Google Translate, support APIKEY
Project description
pygtrans
谷歌翻译, 支持 APIKEY
安装
pip install -U pygtrans
基本功能
- 获取语言支持列表
- 自动检测语言, 支持批量
- 文本/HTML 翻译, 支持批量
- 支持 TTS
快速入门
from pygtrans import Translate
client = Translate(proxies={'https': 'http://localhost:10809'})
# 检测语言
text = client.detect('Answer the question.')
assert text.language == 'en'
# 翻译句子
text = client.translate('Look at these pictures and answer the questions.')
assert text.translatedText == '看这些图片,回答问题。'
# 批量翻译
texts = client.translate([
'Good morning. What can I do for you?',
'Read aloud and underline the sentences about booking a flight.',
'May I have your name and telephone number?'
])
assert [text.translatedText for text in texts] == [
'早上好。我能为你做什么?',
'大声朗读并在有关预订航班的句子下划线。',
'可以给我你的名字和电话号码吗?'
]
# 翻译到日语
text = client.translate('请多多指教', target='ja')
assert text.translatedText == 'お知らせ下さい'
# 翻译到韩语
text = client.translate('请多多指教', target='ko')
assert text.translatedText == '조언 부탁드립니다'
# 文本到语音
tts = client.tts('やめて', target='ja')
open('やめて.mp3', 'wb').write(tts)
最佳实践
pygtrans
中包含两个翻译模块Translate
的最佳实践:http
代理:Translate(proxies={"https": "http://localhost:10809"})
socks5
代理:Translate(proxies={"https": "socks5://localhost:10808"})
- 重要:尽量一次性多翻译,减少请求次数,参考 #13,比如一次性翻译 2000 / 5000 / 10000
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pygtrans-1.4.0.tar.gz
(22.1 kB
view details)
Built Distribution
pygtrans-1.4.0-py3-none-any.whl
(23.2 kB
view details)
File details
Details for the file pygtrans-1.4.0.tar.gz
.
File metadata
- Download URL: pygtrans-1.4.0.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
2fdbcabbbe90e7ec3c8af696ba3955da8d51aa90c3094b6ec895424ffe493c8b
|
|
MD5 |
c27bcbfe8cca96265d7270fc8a2c2bb7
|
|
BLAKE2b-256 |
d19c2ccce985a6e70e736360f7dc25165c6dae8cd5fab26988e3dfe1abf13a95
|
File details
Details for the file pygtrans-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: pygtrans-1.4.0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
2635fadc00711f6b0c47b4a403cd0a07026b4606debea3f1d0fdf6881a9840e8
|
|
MD5 |
f0c3bb4c88065259e50d6d6e8bccd84b
|
|
BLAKE2b-256 |
26a8933683e0a48301bb29a5d2a124bf57db914e4caf679daf27c942d4ebba67
|