在控制台选择语音合成
创建应用
填写应用信息
在应用列表获取(Appid、API Key、Secret Key)
6. 安装pythonsdk
安装使用Python SDK有如下方式:
-
如果已安装pip,执行pip install baidu-aip即可。
-
如果已安装setuptools,执行python setup.py instal即可。
7. 书写代码
1 from aip import AipSpeech 2 3 """ 你的 APPID AK SK """ 4 APP_ID = '你的 App ID' 5 API_KEY = '你的 Api Key' 6 SECRET_KEY = '你的 Secret Key' 7 8 client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) 9 10 11 result = client.synthesis('你好百度', 'zh', 1, { 12 'vol': 5, 13 }) 14 15 # 识别正确返回语音二进制 错误则返回dict 参照下面错误码 16 if not isinstance(result, dict): 17 with open('auido.mp3', 'wb') as f: 18 f.write(result)