python-youdao-ai
有道智云API的Python SDK。
安装
pip install youdaoai
使用方法
同步客户端
from youdaoai import YoudaoAI
# 创建有道智云客户端
client = YoudaoAI('你的APP_KEY', '你的APP_SECRET')
result = client.translate('今天天气真不错', 'zh-CHS', 'en')
print(result)
异步客户端
import asyncio
from youdaoai import AsyncYoudaoAI
# 创建有道智云客户端
client = AsyncYoudaoAI('你的APP_KEY', '你的APP_SECRET')
async def main():
result = await client.translate('今天天气真不错', 'zh-CHS', 'en')
print(result)
if __name__ == '__main__':
asyncio.run(main())
文本翻译服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| q | 无,必填 | 待翻译文本 |
| from_ | 无,必填 | 源语言 |
| to_ | 无,必填 | 目标语言 |
| ext | None | 翻译结果音频格式,支持mp3 |
| audio_path | None | 音频储存路径 |
| voice | None | 翻译结果发音选择,0为女声,1为男声 |
| strict | None | 是否严格按照指定from和to进行翻译:true/false |
| vocabId | None | 用户上传的词典 |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
# 中文翻译为英文
result = await client.translate(
text='今天天气真不错',
from_='zh-CHS',
to_='en'
)
print(result)
图片翻译服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| q | 无,必填 | 待翻译文本 |
| from_ | 无,必填 | 源语言 |
| to_ | 无,必填 | 目标语言 |
| ext | None | 翻译结果音频格式,支持mp3 |
| audio_path | None | 音频储存路径 |
| docType | None | 服务器响应类型,目前只支持json |
| render | None | 是否需要服务端返回渲染的图片,0:否;1:是,默认是0 |
| nullIsError | None | 如果ocr没有检测到文字,是否返回错误,false:否;true:是,默认是false |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
result = client.ocr_translate(img=Path(__file__).parent / Path("test-img.jpeg"), from_="en", to_="zh-CHS")
print(result)
result = client.ocr_translate(
img=Path(__file__).parent / Path("test-img.jpeg"), from_="en", to_="zh-CHS", render=True
)
if result.render_image:
with open("ocr_translated_image.png", "wb") as f:
f.write(base64.b64decode(result.render_image))
else:
print("No render image")
语音翻译服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| q | 无,必填 | 待翻译文本 |
| from_ | 无,必填 | 源语言 |
| to_ | 无,必填 | 目标语言 |
| rate | 'auto' | 采样率,默认会自动分析 |
| format_ | 'wav' | 语音文件的格式, 目前只支持wav |
| channel | '1' | 声道数, 仅支持单声道,请填写固定值1 |
| type_ | '1' | 上传类型, 仅支持Base64上传,请填写固定值1 |
| ext | 'mp3' | 翻译结果音频格式,支持mp3,默认mp3 |
| voice | '0' | 翻译结果发音选择,0为女声,1为男声 |
| signType | 'v1' | 签名版本 |
| version | 'v1' | 接口版本 |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
# 语音文件翻译
result = await client.speech_translate(
q='speech.wav',
from_='zh-CHS',
to_='en',
rate='16000', # 采样率
voice='0' # 0为女声,1为男声
)
print(result)
通用文字识别服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| img | 无,必填 | 待识别图像路径 |
| langType | 'auto' | 要识别的语言类型 |
| angle | None | 是否进行360角度识别,0:不识别,1:识别。默认不识别(0) |
| column | None | 是否按多列识别,onecolumn:按单列识别;columns:按多列识别。默认按单列识别 |
| rotate | None | 是否需要获得文字旋转角度,donot_rotate:不需要得到倾斜角度,rotate:得到倾斜角度。默认不需要 |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
# OCR通用文字识别
result = await client.ocr_general(
img='test_image.png',
langType='zh-CHS',
angle=1, # 启用360度识别
column='columns' # 按多列识别
)
print(result)
表格OCR服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| img | 无,必填 | 待识别图像路径 |
| docType | 无,必填 | 服务器响应类型,目前支持json和Excel |
| excel_filepath | None | 若docType为excel可通过该参数指定生成的xlsx文件路径,若不填该参数则不会生成xlsx文件 |
| angle | None | 是否进行360角度识别,0:不识别,1:识别。默认不识别(0) |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
# 表格OCR识别
result = await client.ocr_table(
img='表格图片.jpg',
docType='excel',
excel_filepath='test.xlsx'
)
print(result)
语音合成服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| q | 无,必填 | 待合成音频文件的文本字符串 |
| langType | 无,必填 | 合成文本的语言类型 |
| filepath | 无,必填 | 指定生成的mp3文件路径 |
| voice | 0 | 翻译结果发音选择,0为女声,1为男声,默认为女声 |
| speed | 1 | 合成音频的语速,1为正常速度,最大为2,最小为0.1 |
| volumn | 1 | 合成音频的音量,正常为1.00,最大为5.00,最小为0.50 |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
# 基础语音合成
result = await client.tts(
q='你好,世界',
langType='zh-CHS',
filepath='output.mp3'
)
print(result)
短语音识别服务
| 参数 | 默认值 | 描述 |
|---|---|---|
| q | 无,必填 | 待合成音频文件的文本字符串 |
| langType | 无,必填 | 合成文本的语言类型,详情见官方文档 |
| rate | 'auto' | 采样率,默认会自动分析(仅支持分析wav格式),非wav格式请手动指定采样率 |
| format_ | 'wav' | 语音文件的格式, 目前支持wav、aac、mp3 |
| channel | '1' | 声道数, 仅支持单声道,请填写固定值1 |
from youdaoai import Youdao
# 创建有道智云客户端
client = Youdao('你的APP_KEY', '你的APP_SECRET')
# WAV文件识别
result = await client.asr(
q='speech.wav',
langType='zh-CHS'
)
print(result)
Metadata
Release files for youdaoai 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| youdaoai-0.2.3.tar.gz | 2.5 MB | Without provenance | Details for youdaoai-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| youdaoai-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for youdaoai-0.2.3-py3-none-any.whl |
Total release size: 2.5 MB
Release files / youdaoai-0.2.3.tar.gz
| Download URL | youdaoai-0.2.3.tar.gz |
|---|---|
| Size | 2.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc4c29183da1ca344eb0d09e1858cc248a6cd26ddb708555720fa777fd7d830b
|
|
BLAKE2b-256 checksum How to use checksums |
c8f892631ff9fa410ff435b59050db756b14c869058f95cbda0bab6d52c67afd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.0 CPython/3.11.6 Windows/10
|
Release files / youdaoai-0.2.3-py3-none-any.whl
| Download URL | youdaoai-0.2.3-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb15a597f2afd4f7a087d0062de0eb94dc3dd23d39d248659954e4fb6812296e
|
|
BLAKE2b-256 checksum How to use checksums |
a79a650843450ccb9ca6e98d3e4a968ca1458acf3aa2c8efdeef27c012efe54b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.0 CPython/3.11.6 Windows/10
|
Security for youdaoai 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.