我是Python和PysimpleGUI的新手。我想创建一个简单的GUI,用于语音到文本。 Pysimple GUI可以做到吗?还是除了PysimpleGUI之外还有其他可以工作的GUI框架?现在,我已经完成了GUI的创建,但是遇到了一些问题,我想创建一个语音按钮代码,以便在我想停止获取声音时总是获取语音并停止按钮,但是我不知道如何停止。当我测试程序时,程序将冻结并出现错误:
>Traceback (most recent call last):
File "C:/Users/sumet3412/PycharmProjects/Speech2Txt/testPysimpleGUI.py", line 123, in <module>
value = r.recognize_google(audio, language="en-US")
File "C:\Users\sumet3412\PycharmProjects\Speech2Txt\venv\lib\site-packages\speech_recognition\__init__.py", line 672, in recognize_google
if "alternative" not in actual_result: raise UnknownValueError()
speech_recognition.UnknownValueError
import speech_recognition as sr
import PySimpleGUI as sg
r = sr.Recognizer()
m = sr.Microphone()
layout = [[sg.Text('Converter', font='Helvetica 15')],
[sg.ReadButton('Speak'), sg.ReadButton('Stop')],
[sg.Output(size=(80, 10))],
[sg.Exit()]]
window = sg.Window('Speech Recognition').Layout(layout)
while True:
event,values = window.Read()
if event is None or event == 'Exit':
break
elif event == 'Speak':
with m as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
value = r.recognize_google(audio, language="en-US")
print(value)
window.Close()
答案 0 :(得分:0)
反应较晚,但是我创建了类似的内容,您可以在此行上设置持续时间:
audio= r.listen(source,5)
这将起作用,因为这意味着音频将被捕获5秒钟然后被转录。希望这可以帮助。