from aip import AipSpeech import os from tkinter import * #TK可视化 import threading app=Tk() app.title('语音播报V1.0') app.geometry('600x700') v1 = StringVar() text1 = Text(app,width=50,height=50) """ 你的 APPID AK SK """ APP_ID = '***************' API_KEY = '***************' SECRET_KEY = '***************' client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) def run(): text=text1.get('0.0', 'end') ''' tex String 合成的文本,使用UTF-8编码,请注意文本长度必须小于1024字节 cuid String 用户唯一标识,用来区分用户,填写机器 MAC 地址或 IMEI 码,长度为60以内 spd String 语速,取值0-9,默认为5中语速 pit String 音调,取值0-9,默认为5中语调 vol String 音量,取值0-15,默认为5中音量 per String 发音人选择, 0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女 ''' result = client.synthesis(text, 'zh', 1, {'vol': 15,'per':3,'spd':3}) if not isinstance(result, dict): with open('auido.mp3', 'wb') as f: f.write(result) '''调用系统自带播放器进行播放 利用pygame也可以''' os.system('auido.mp3') def thread():#启用线程,解决tk与语音合成 t=threading.Thread(target=run) t.start() text1.pack() button_run=Button(app,text='播放',command=thread).pack() app.mainloop()
利用百度AI进行语音朗读和识别(python)
猜你喜欢
转载自www.cnblogs.com/liubingzhe/p/11328599.html
今日推荐
周排行