Comments (2)
Currently this package has no support for that but I'll look into it.
from google-translate-api.
@AidanWelch , I found this code , good starter idea to develop it :
Everything looks right , but i don't know why not working.
import json
import requests
import base64
import os
def guess_type(image_path):
# Get the file extension from the image path
ext = os.path.splitext(image_path)[1].lower()
# Map the extensions to the mimetypes
mimetypes = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png"
}
# Return the mimetype if it exists, otherwise return None
return mimetypes.get(ext, None)
def load_image_as_base64(image_path):
with open(image_path, 'rb') as f:
image_bytes = f.read()
# Convert image bytes to base64 string
base64_string = base64.b64encode(image_bytes).decode('utf-8')
mimetype = guess_type(image_path)
# Return image data in the specified format
return [base64_string, mimetype]
_imageObj = load_image_as_base64('124+958.png')
_RPCIDS = "WqWDPb"
params = {
'rpcids': _RPCIDS,
'bl': 'boq_translate-webserver_20240115.08_p0',
'soc-app': 1,
'soc-platform': 1,
'soc-device': 1,
'rt': 'c'
}
data = {'f.req': json.dumps([[
[_RPCIDS,
json.dumps([_imageObj,"auto","fr"], separators=(',', ':')),
None,
"generic"]
]], separators=(',', ':')),
}
TRANSLATEURL = 'https://translate.google.com/_/TranslateWebserverUi/data/batchexecute'
response = requests.request("POST", TRANSLATEURL,
data=data,
params=params,
)
then i use bellow code to get translated image :
import base64
def convert_base64_to_image(base64_string, image_path):
# Convert base64 string to image bytes
image_bytes = base64.b64decode(base64_string)
# Write the image bytes to a file
with open(image_path, 'wb') as image_file:
image_file.write(image_bytes)
b = response.text.split('\n')
li_filter = []
flag = False
for _b in b:
if _b.isnumeric():
flag = not flag
_b = '==='
if flag:
li_filter.append(_b)
li_data = json.loads(li_filter[1])
resp_img_data =json.loads(li_data[0][2])
res_img_data=resp_img_data[0]
f_mimetypes = {
"image/jpg": ".jpg" ,
"image/jpeg" :".jpeg",
"image/png" : ".png"
}
convert_base64_to_image(res_img_data[0], 'out'+f_mimetypes[res_img_data[1]])
from google-translate-api.
Related Issues (20)
- Real-time translation HOT 2
- ReferenceError: fetch is not defined HOT 2
- TypeScript Error HOT 2
- requestOptions documentation outdated HOT 3
- It throws error "fetch is not defined" HOT 2
- Tests fail only because rate limited on single translate HOT 1
- TypeError: (0 , _googleTranslateApiX.translate) is not a function HOT 17
- google-translate-api-x gives below error HOT 3
- Improve `speak` testing
- Caught an error from batch translate HOT 8
- ERROR [TypeError: Cannot convert null value to object] HOT 2
- Issue with the speak functionality HOT 2
- Batch translation error HOT 4
- Can't run on React.js HOT 2
- Big translation slowed down HOT 11
- change speak speed HOT 2
- fetch is not defined after deployment HOT 2
- CORS policy error HOT 4
- Obtain translation synonyms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-translate-api.