人工智能 - 语音合成,语音识别,语音聊天机器人
语音合成
根据百度大佬提供的文档,作出以下小栗子:
1.下载
pip install baidu-aip
2.代码
from aip import AipSpeech
""" 你的 APPID AK SK
控制台 -> 百度语音-> 创建或管理应用
"""
APP_ID = '15837844'
API_KEY = '411VNGbuZVbDNZU78LqTzfsV'
SECRET_KEY = '84AnwR2NARGMqnC6WFnzqQL9WWdWh5bW'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) # 实例化
def text2audio(text):
"""一些参数的配置,详见文档"""
result = client.synthesis(text, 'zh', 1, {
'vol': 5,
'per': 4,
'spd': 4,
'pit': 7,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
print(result)
with open('audio.mp3', 'wb') as f:
f.write(result)