음성 인식에서 텍스트 상자까지의 텍스트를 텍스트로 표시하는 코드가 있습니다.Tkinter의 파이썬 음성 인식
문제점 : 그냥 을 수신 한 다음을 실행 한 다음 실행을 멈 춥니 다. listen it till,i close the Tkinter
이 필요합니다.
내가 이라면 분명히라고 말하면 텍스트 상자의 내용을 지워야합니다. 내 문제는, 나는 내용을 Tkinter에 직접 말할 수 없다는 것입니다. 이것은 쉘 출력 후에 청취합니다.
제발 내 문제를 해결하는 데 도움이됩니다.
코딩 :
당신은 적절한 동시 음성 인식을 실행하는 스레드를 사용하여 텍스트 위젯의 내용을 업데이트해야from Tkinter import *
import pyaudio
import tkMessageBox
import Tkinter as tki
import tkFileDialog as th1
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
a=(r.recognize(audio))
print a
except LookupError:
a=("Could not understand audio")
print a
class App(object):
def __init__(self,root):
self.root = root
# create a Frame for the Text and Scrollbar
txt_frm = tki.Frame(self.root, width=900, height=900)
txt_frm.pack(fill="both", expand=True)
# ensure a consistent GUI size
txt_frm.grid_propagate(False)
# create first Text label, widget and scrollbar
self.lbl1 = tki.Label(txt_frm, text="Type")
self.lbl1.grid(row=0,column=0,padx=2,pady=2)
self.txt1 = tki.Text(txt_frm, borderwidth=3, relief="sunken", height=4,width=55)
self.txt1.config(font=("consolas", 12), undo=True, wrap='word')
self.txt1.grid(row=25, column=7, sticky="nsew", padx=2, pady=2)
self.txt1.insert(0.0,a)
def clearBox(self):
if a == "clear":
self.txt1.delete('1.0', 'end')
root = tki.Tk()
app = App(root)
root.mainloop()
이 문제를 해결하려면 스레드가 필요하며, Tkinter는 스레딩에 대해 알지 못하므로 메인 루프에서 변경/인식을 폴링하기 위해 애프터 기능이 필요합니다. – deets
@deets 내 쿼리와 관련된 작은 예제를 도와 줄 수 있습니까? –
@sarkite : PyAudio가 speech_recognition에 대한 작업을 수행했다면, 여기에서했던 것처럼, 다른 질문을 닫거나 더 잘 대답 할 수 있습니까? http://stackoverflow.com/questions/26666216/pyaudio-build-and-install-python-portaudio-bindings-first – tom10