1. 模块安装
pip install baidu_aip
2. 注册 百度智能云
3. 创建应用
管理控制台--产品服务--人工智能--语音技术--应用列表--创建应用
4. 接口实现
from aip import AipSpeech
""" 你的 APPID AK SK """
APP_ID = 'app_id'
API_KEY = 'app_key'
SECRET_KEY = 'secret_key'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis('百度智能云服务', 'zh', 1, {
'vol': 15, # 音量
'spd': 3, # 语速
'pit': 9, # 语调
'per': 4, # 0:女 1:男 3:逍遥 4:小萝莉
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
with open('auido.mp3', 'wb') as f:
f.write(result)