https://github.com/Baidu-AIP/python-sdk
pip install git+https://github.com/Baidu-AIP/python-sdk.git@master安装音频播放库
pip install playsound
from aip import AipSpeech
""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis('你好百度', 'zh', 1, {
'vol': 5,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
with open('audio.mp3', 'wb') as f:
f.write(result)
- 语音生成参数:API说明
执行成功后会生成一个audio.mp3的音频文件:
from playsound import playsound
playsound('audio.mp3')
参考:
- Python播放MP3音频文件



