[英]speech recognition stopped if i did not say something, how to keep it listening
想要創建 2 個按鈕來啟動語音識別並繼續,直到我點擊按鈕完成。 問題是當我單擊開始並且沒有說它停止時:
import tkinter as tk
import speech_recognition as sr
window = tk.Tk()
window.title("Voice to Text")
window.geometry("300x350")
def startvoice():
r = sr.Recognizer()
with sr.Microphone() as source:
print("speak now")
audio = r.listen(source)
try:
startvoice.voice2text = r.recognize_google(audio)
print("you said:{}".format(startvoice.voice2text))
except:
print("Your voice not clear")
def finished():
text_field.focus()
text_field.delete('1.0', tk.END)
text_field.insert('1.0', startvoice.voice2text)
text_field = tk.Text(master=window, height=20, width=40)
text_field.grid(column=0, row=2)
button1 = tk.Button(text="Start", width=16, command=startvoice)
button1.grid(column=0, row=0)
button1 = tk.Button(text="finish", width=16, command=finished)
button1.grid(column=0, row=1)
window.mainloop()
根據文檔, listen
方法有一個超時參數,這可能是您正在尋找的,例如
audio = r.listen(source, timeout=60)
會讓你在放棄前一分鍾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.