利用百度AI进行语音朗读和识别(python)

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()

 

转载于:https://www.cnblogs.com/liubingzhe/p/11328599.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值