利用百度API行语音合成 python

1. 登录百度AL开发平台

image

2. 在控制台选择语音合成

image

3. 创建应用

image

4. 填写应用信息

image

5. 在应用列表获取(Appid、API Key、Secret Key)

image

6. 安装pythonsdk

安装使用Python SDK有如下方式:

  • 如果已安装pip,执行pip install baidu-aip即可。
  • 如果已安装setuptools,执行python setup.py instal即可。

7. 书写代码

  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('auido.mp3', 'wb') as f:
        f.write(result)  
复制代码

8. 大功告成

原文地址:https://www.cnblogs.com/helloworld3/p/11990779.html