我正在制作一个使用语音转文本的软件。我在 stackoverflow 上读过一些文章和帖子。我尝试了这段代码-
r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
r.adjust_for_ambient_noise(source)
print("Speak:")
audio = r.listen(source)
try:
print("You said " + r.recognize_google(audio)+';')
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
在我运行代码后,当它到达这部分时,它会进入输入阶段并停止。它不执行任何操作,并且 tkinter window 不响应。看起来像这样。
我尝试了 r.recognize_google
和 r.recognize_sphinx
。我也尝试过不使用麦克风索引。我不明白发生了什么事。当谈到r.listen(source)
时它就停止了。感谢您的建议。
最佳答案
你可以试试这个code在 GitHub 中。
关于使用语音识别将 Python 语音转为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53112910/