Voice access Baidu ai
Speech synthesis
https://ai.baidu.com/tech/speech/tts
View Instructions
Interface name | A brief description of interface capabilities |
---|---|
Speech Synthesis | The text messages generated by their own computer, or external input into can understand the technical Fluent in spoken output. |
https://ai.baidu.com/ai-doc/SPEECH/Ik4nlz8l6
"What is the sdk
SDK full name in English is: software development kit, translated into Chinese means "Software Development Kit"
Operating procedures
Finishing official described the content of the document
Installation Kit
pip install baidu-aip
Create an object
from aip import AipSpeech
""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
Generation voice
The method of using the object, generating a speech
For example, take a piece of text to speech synthesis file:
result = client.synthesis('你好百度', 'zh', 1, {
'vol': 5,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
with open('auido.mp3', 'wb') as f:
f.write(result)
parameter | Types of | description | Do you have to |
---|---|---|---|
tex | String | Synthetic text, using UTF-8 encoding, please note that the text must be less than 1024 bytes | Yes |
some | String | Unique user identifier used to distinguish the user, the machine fill IMEI code or MAC address, length of 60 or less | no |
spd | String | Speed, values 0-9, default is 5 Speed | no |
pit | String | Tone, values 0-9, default is 5 tone | no |
vol | String | Volume, value 0-15, the default is 5 volume | no |
per | String | Pronunciation people choose 0 for female, 1 male, 3 for the synthesis of emotion - of Happy, 4 for the synthesis of emotion - of the Ya-Ya, the default is ordinary woman | no |
Production code
from aip import AipSpeech
""" 你的 APPID AK SK """
# APP_ID = '18403692'
APP_ID = '18527788'
# API_KEY = 'kP8jrCoYMxAuyI9XesWPcln5'
API_KEY = 'aP6s30SFn8HFI4ybXg86X7Lz'
# SECRET_KEY = 'oZQCcWeamKwRwvh6cC2WxGYOWBHSmtks'
SECRET_KEY = 'QPMU9j1DHG1li2NcGA1mZsDzs2rIbDcC'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
s = """
我要我家彩虹散
"""
result = client.synthesis(s, 'zh', 1, {
'vol': 5, 'per': 4
})
# 发音人选择, 0为女声,1为男声,
# 3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
with open('./auido.mp3', 'wb') as f:
f.write(result)