将带语音识别的文本插入到textpad中

时间:2016-09-06 05:58:31

标签: python tkinter

我正在创建一个程序,以语音的形式从用户那里获取输入,并在语音识别模块的帮助下将其转换为文本,该模块工作正常,但此后当我尝试将其插入到创建的文本板中时tkinter,textpad不会出现?请检查并告诉我哪里弄错了。

import speech_recognition as sr
from Tkinter import *

root=Tk()
text=Text(root)

r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something:")
    audio = r.listen(source)
try:
    t=r.recognize_google(audio)
    text.insert(INSERT, t)
    text.pack()
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))

root.mainloop()

0 个答案:

没有答案