需要到 百度智能云 申请测试账号,获得相关的 

APP_ID, API_KEY, SECRET_KEY

相关的使用说明可查看文档

pip install baidu_aip

from aip import AipSpeech


client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

def text_to_speech(text):
    file = "audio2.wav"
    synthesis = client.synthesis(
        text, "zh", 1, 
        {"vol": 5, "spd": 6, "per": 3}
        )
    f = open(file, "wb")
    f.write(synthesis)
    return file

text = "测试语音"
text_to_speech(text)

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐