调用百度云短语音合成简单程序

今天编写一个简洁的语音合成程序,是直接调用百度云短语音合成接口 client.synthesis()。短语音合成接口链接说明
参数说明
常见错误码

直接放程序

from aip import AipSpeech
from playsound import playsound
import os
#一定要注意有免费的短语音识别额度,不然会报错你没有生成audio.mp3
APP_ID = '你申请的ID'
API_KEY = '你申请的API_KEY'
SECRET_KEY = '你申请的SECRET_KEY'
#path = 'C:/Users/Administrator/Desktop/1/'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
 #vol:音量;spd:语速;pit:音调;per:精品音库5为度小娇,103为度米朵,106为度博文,110为度小童,111为度小萌,默认为度小美 
result  = client.synthesis("好好学习天天向上",'zh',1,{
    
    'vol':9,'spd':5,'pit':5,'per':4})
if not isinstance(result,dict):
    with open('audio.mp3','wb+') as f:
        f.write(result)
#print(result) #识别不了的话,打开这个查看返回码,如果502,说明接口额度过了
playsound('audio.mp3') #这个playsound报错的话,需要单独检查playsound库有没有问题,重新卸载安装看看
#os.remove('audio.mp3')

猜你喜欢

转载自blog.csdn.net/lyx4949/article/details/126956646