在控制台選擇語音合成
創建應用
填寫應用信息
在應用列表獲取(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)