baiduAI实现文字转语音功能

1. 模块安装

pip install baidu_aip

2. 注册 百度智能云
3. 创建应用

管理控制台--产品服务--人工智能--语音技术--应用列表--创建应用
在这里插入图片描述
baiduAI实现文字转语音功能_第1张图片
baiduAI实现文字转语音功能_第2张图片

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)

在这里插入图片描述

你可能感兴趣的:(Special,Python)