Skip to main content

Python SDK for Youdao AI.

Project description

python-youdao-ai

有道智云API的Python SDK。

安装

pip install youdaoai

使用方法

文本翻译服务

参数 默认值 描述
q 无,必填 待翻译文本
from_ 无,必填 源语言
to_ 无,必填 目标语言
ext None 翻译结果音频格式,支持mp3
audio_path None 音频储存路径
voice None 翻译结果发音选择,0为女声,1为男声
strict None 是否严格按照指定from和to进行翻译:true/false
vocabId None 用户上传的词典
from youdaoai import Translation


ts = Translation('你的APP_KEY', '你的APP_SECRET')
result = ts.translate('大家好我是毕老师', 'zh-CHS', '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 OCRTranslation


ts = OCRTranslation('你的APP_KEY', '你的APP_SECRET')
result = ts.translate('ocr_translation.png', 'zh-CHS', 'en')
print(result)

语音翻译服务

参数 默认值 描述
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 SpeechTranslation


ts = SpeechTranslation('你的APP_KEY', '你的APP_SECRET')
result = ts.translate('speech.wav', 'zh-CHS', 'en')
print(result)

通用文字识别服务

参数 默认值 描述
img 无,必填 待识别图像路径
langType 'auto' 要识别的语言类型
angle None 是否进行360角度识别,0:不识别,1:识别。默认不识别(0)
column None 是否按多列识别,onecolumn:按单列识别;columns:按多列识别。默认按单列识别
rotate None 是否需要获得文字旋转角度,donot_rotate:不需要得到倾斜角度,rotate:得到倾斜角度。默认不需要
from youdaoai import OCRGeneral


ocr = OCRGeneral('你的APP_KEY', '你的APP_SECRET')
result = ocr.recognize('ocr_general.png')
print(result)

身份证识别服务

参数 默认值 描述
img 无,必填 待识别图像路径
from youdaoai import OCRIDCard


ocr = OCRIDCard('你的APP_KEY', '你的APP_SECRET')
result = ocr.recognize('身份证.jpg')
print(result)

购物小票识别服务

参数 默认值 描述
img 无,必填 待识别图像路径
from youdaoai import OCRReceipt


ocr = OCRReceipt('你的APP_KEY', '你的APP_SECRET')
result = ocr.recognize('购物小票.jpg')
print(result)

表格OCR服务

参数 默认值 描述
img 无,必填 待识别图像路径
docType 无,必填 服务器响应类型,目前支持json和Excel
excel_filepath None 若docType为excel可通过该参数指定生成的xlsx文件路径,若不填该参数则不会生成xlsx文件
angle None 是否进行360角度识别,0:不识别,1:识别。默认不识别(0)
from youdaoai import OCRTable


ocr = OCRTable('你的APP_KEY', '你的APP_SECRET')
result = ocr.recognize('表格图片.jpg', 'excel', 'test.xlsx')
print(result)

名片识别服务

参数 默认值 描述
img 无,必填 待识别图像路径
from youdaoai import OCRNamecard


ocr = OCRNamecard('你的APP_KEY', '你的APP_SECRET')
result = ocr.recognize('名片照片.jpg')
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 TTS


tts = TTS('你的APP_KEY', '你的APP_SECRET')
result = tts.build('大家好我是毕老师', 'zh-CHS', '语音合成.mp3')
print(result)
from youdaoai import TTS

tts = TTS('你的APP_KEY', '你的APP_SECRET')
result = tts.build('Embedded finance will help fill the life insurance coverage gap', 'en-USA', '英语语音合成.mp3', 1, 1.5, 3)
print(result)

短语音识别服务

参数 默认值 描述
q 无,必填 待合成音频文件的文本字符串
langType 无,必填 合成文本的语言类型,详情见官方文档
rate 'auto' 采样率,默认会自动分析(仅支持分析wav格式),非wav格式请手动指定采样率
format_ 'wav' 语音文件的格式, 目前支持wav、aac、mp3
channel '1' 声道数, 仅支持单声道,请填写固定值1
from youdaoai import ASR


asr = ASR('你的APP_KEY', '你的APP_SECRET')
result = asr.recognize('speech.wav', 'zh-CHS')
print(result)
from youdaoai import ASR

asr = ASR('你的APP_KEY', '你的APP_SECRET')
result = asr.recognize('speech.mp3', 'zh-CHS', 16000, 'mp3')
print(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

youdaoai-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

youdaoai-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file youdaoai-0.1.0.tar.gz.

File metadata

  • Download URL: youdaoai-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.0 CPython/3.11.6 Windows/10

File hashes

Hashes for youdaoai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4718b8fdb79f3bf9026d4575030ed2cae4096c545f890ba817235dc3f6ff5ed8
MD5 0b495d207bfb799e8dc41e9504765174
BLAKE2b-256 30c514fe8d37f54e3041588ccaeefad44d0acd65349dcdc479a726a5829dd72d

See more details on using hashes here.

File details

Details for the file youdaoai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: youdaoai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.0 CPython/3.11.6 Windows/10

File hashes

Hashes for youdaoai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb115864dd1d2496eeed5f02973f0978b23b8743f654dd6e27a8852d12cc87eb
MD5 14eeb7c1f1e554d05d42e3a7da17d169
BLAKE2b-256 802a4487388cb3c9ef3baedac3e37688324dc1263fc218af6f40b0b76ddf351d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page