|
发表于 2020-2-17 09:12:52
|
显示全部楼层
本帖最后由 一个账号 于 2020-2-17 09:18 编辑
- from tkinter import *
- from aip import AipSpeech
- from _thread import start_new_thread as s
- from tkinter.messagebox import showerror, showinfo
- from os.path import abspath, isfile
- from os import system
- from aip import AipSpeech
- APP_ID = ''
- API_KEY = ''
- SECRET_KEY = ''
- def creat():
- text = t.get(1., END)
- client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
- result = client.synthesis(text, 'zh', 1, {'vol': 5, })
- # 识别正确返回语音二进制,错误则返回 dict 类型
- if not isinstance(result, dict):
- with open('audio.mp3', 'wb') as f:
- f.write(result)
- showinfo("信息", f"音频已保存至 {abspath('voice.mp3')}")
- else:
- showerror("错误", "发生错误!")
-
- def play():
- from win32com import client
-
- text = t.get(1., END)
- engine = client.Dispatch("SAPI.SpVoice")
- engine.Speak(text)
- root = Tk()
- root.title("文本复述机")
- Label(root, text="请输入要复述的内容:").pack(pady=5)
- t = Text(root, width=50, height=30)
- t.pack(padx=10)
- Button(root, text="复述文本", width=12, command=lambda: s(play, ())).pack(pady=5)
- Button(root, text="生成音频", width=12, command=lambda: s(creat, ())).pack(pady=5)
- mainloop()
复制代码 |
|