gpt4 book ai didi

python - 如果我不说话,语音识别就会停止,如何让它继续听

转载 作者:太空宇宙 更新时间:2023-11-03 20:10:53 24 4
gpt4 key购买 nike

想要创建 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)

在放弃之前给你一分钟的时间。

关于python - 如果我不说话,语音识别就会停止,如何让它继续听,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58724960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com