来源:CSDN
发布时间:Nov 17, 2020, 3:08:18 PM
原地址:https://blog.csdn.net/hlx20080808/article/details/109746952
一、百度语音合成文档: https://cloud.baidu.com/doc/SPEECH/s/Gk4nlz8tc
二、安装baidu-aip
(1) 执行pip install baidu-aip
即可
(2) 工具PyCharm 单击菜单File|setting|Project|Available Packages
三、百度语音合成后台获取秘钥:
登录地址:https://console.bce.baidu.com/ai/?fromai=1#/ai/speech/app/detail~appId=2040639
产品服务 => 人工智能 => 百度语音 => 创建引用
四、代码:
# 1.导入库 pip install baidu-aip
from aip import AipSpeech
# 2.初始化AipSpeech对象
App_ID = '22996943'
API_Key = 'ziVzDCBPX2xo4rY6nZeNSqmz'
Secret_Key = 'XXXX'
# 相当于3把钥匙
client = AipSpeech(App_ID, API_Key, Secret_Key)
# 3.调用语音合成的方法
str = '1、思维导图 2、home作业 3、60道笔试题 4、预习《JDBC》5、查看解析'
# 音频文件流
result = client.synthesis(str, "zh", 1, {"per": 4})
# print(result)
# 识别正确返回语音二进制 错误则返回dict 参照错误码
#4.保存音频文件
if not isinstance(result, dict):
with open('./audio.mp3', 'wb') as f:
f.write(result)
五、 执行效果: