百度2108,6月份就發佈百度語音識別無限量,可真是個好消息。本篇教你們運用百度api把文字轉化爲語音!!!
安裝使用Python SDK有以下方式:python
若是已安裝pip,執行pip install baidu-aip便可。
若是已安裝setuptools,執行python setup.py install便可。web
from aip import AipSpeech """ 你的 APPID AK SK """ APP_ID = '你的APPID' API_KEY = '你的api_key' SECRET_KEY = '你的secrt_key' client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) #這些是參數能夠去http://ai.baidu.com/docs#/TTS-Online-Python-SDK/top有詳細解釋 lan="歡迎使用這個東東,呃盒,你,是否是,傻" result = client.synthesis(lan, 'zh', 1, { 'vol': 5,'per':4,'spd':5 }) #識別正確返回語音二進制 錯誤則返回dict 參照下面錯誤碼 if not isinstance(result, dict): with open('C:/Users/Administrator/Desktop/baidu_vioce/auido.mp3', 'wb') as f: f.write(result)
這樣咱們就能夠在C:/Users/Administrator/Desktop/baidu_vioce/文件夾下獲得auido.mp3文件。播放語音內容就是’歡迎使用這個東東,呃盒,你,是否是,傻’api