Py学习  »  Python

利用百度API行语音合成 python

乔柯 • 4 年前 • 369 次点击  
阅读 116

利用百度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. 大功告成

搜索887934385交流群,进入后下载资料工具安装包等。最后,感谢观看!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50824
 
369 次点击