我在安装了 pyAudio 的 Python 2.7 中运行以下代码。
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source: # use the default microphone as the audio source
audio = r.listen(source) # listen for the first phrase and extract it into audio data
try:
print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition
except LookupError: # speech is unintelligible
print("Could not understand audio")
输出给出了一个闪烁的指针。就是这样。
最佳答案
可能的原因可能是 recognizer_instance.energy_threshold
属性设置的值可能太高而无法开始。您应该降低此阈值,或调用 recognizer_instance.adjust_for_ambient_noise(source, duration = 1)
。您可以在 Speech Recognition 了解更多信息
关于python - 语音识别python代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32005310/