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.2.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

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

youdaoai-0.2.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: youdaoai-0.2.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • 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.2.0.tar.gz
Algorithm Hash digest
SHA256 c6c00acc83951c53333ef8bb81543d87eeb7005f160464694f36ca2b2a1d94c5
MD5 de8c26622a9ffa525a46336dfb9b4499
BLAKE2b-256 87de251ceeb67a3a556289b3a69fc1cc0237d2c74fd21951233ee9cf19fe5fb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: youdaoai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bfb2dca42fe968f2aba3ac584a813bef70ec16b5aa5ccdfa3ef963ebbde34bb
MD5 7d6f01eb865820600143d01b415d6ce8
BLAKE2b-256 32f722ec5f18d8d6db969e10bb091360e601d2b0130aabc87d57330fc37994fc

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