博客
关于我
python谷歌翻译,2021年9月10日亲测可用,一次可以翻译十万,强烈star
阅读量:801 次
发布时间:2023-03-06

本文共 1136 字,大约阅读时间需要 3 分钟。

pygtransTranslate API 开源库 Documentation

安装

使用 pip 安装 pygtransTranslate:

pip install pygtrans

基本使用

导入库

from pygtrans import Translate

检测语言

client = Translate()
text = client.detect('Answer the question.')
# text.language 将返回检测到的语言

翻译句子

text = client.translate('Look at these pictures and answer the questions.')
# text.translatedText 将返回翻译后的文本

批量翻译

texts = [
'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?'
]
translated_texts = client.translate(texts)
# translated_texts 是一个包含所有翻译结果的列表

支持多语言

# 翻译到中文
text = client.translate('请多多指教')
# text.translatedText -> '请多多指教'
# 翻译到日语
text = client.translate('请多多指教', target='ja')
# text.translatedText -> 'お知らせ下さい'
# 翻译到韩语
text = client.translate('请多多指教', target='ko')
# text.translatedText -> '조언 부탁드립니다'

文本到语音

tts = client.tts('やめて', target='ja')
# 生成语音文件,保存为 'やめて.mp3'
with open('やめて.mp3', 'wb') as f:
f.write(tts)

高级功能

支持大规模请求

pygtransTranslate 可以处理长列表的翻译任务,支持超过 10 万个请求,适合大规模自动化任务。

API 键

请参考 pygtrans API 文档 获取详细信息。


开源项目

此外,pygtransTranslate 是一个开源项目,旨在为开发者提供简单易用的翻译 API 接口。

转载地址:http://krafk.baihongyu.com/

你可能感兴趣的文章
Python GC 也会关闭文件吗?
查看>>
python gen_key.py 报错 提示找不到OpenSSL lib
查看>>
python getattrribute_Python学习——面向对象高级之反射
查看>>
Python进阶语法:字典推导式
查看>>
python gil_Python中GIL的使用详解
查看>>
python glob.glob使用
查看>>
python glob的安装和使用
查看>>
Python google drive API 下载,文件在哪里?
查看>>
Python GPS 模块:读取最新的 GPS 数据
查看>>
python grpc入门
查看>>
python gRPC测试helloworld
查看>>
python gRPC简单示例
查看>>
Python GUI 开发:全面指南
查看>>
Python GUI编程
查看>>
Python hashlib模块
查看>>
python hashlib模块
查看>>
python if,循环的练习
查看>>
Python in open course (week3)
查看>>
Python IO编程
查看>>
Python IO编程详解
查看>>