语音识别蟒蛇代码不起作用

2022-04-01 00:00:00 python speech-recognition

问题描述

我在安装了pyAudio的Python2.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

了解更多信息

相关文章