语音识别python代码无法正常工作

all*_*niv 7 python speech-recognition

我在安装了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")
Run Code Online (Sandbox Code Playgroud)

输出指示闪烁.而已.请帮助,因为我是新手.

小智 8

尝试添加

r.adjust_for_ambient_noise(source,duration=1)
Run Code Online (Sandbox Code Playgroud)

其中 r 是识别器实例,如下所示

import speech_recognition as sr

r=sr.Recognizer()
print(sr.Microphone.list_microphone_names())
with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source,duration=1)
    # r.energy_threshold()
    print("say anything : ")
    audio= r.listen(source)
    try:
        text = r.recognize_google(audio)
        print(text)
    except:
        print("sorry, could not recognise")
Run Code Online (Sandbox Code Playgroud)


小智 6

我已经通过以下(噪声抑制)为我解决了同样的问题,“监听”功能存在环境噪声问题。所以正在运行的代码只是闪烁等待。

使用此环境噪声抑制/调整; r.adjust_for_ambient_noise(source, duration=5)

全球化志愿服务青年 周二,2017年3月28日易语音识别在用Python PyAudio和Pocketsphinx


Tus*_*tam 5

可能的原因可能是该recognizer_instance.energy_threshold属性可能设置为一个过高而无法使用的值。您应该降低此阈值,或致电recognizer_instance.adjust_for_ambient_noise(source, duration = 1)。您可以在语音识别中了解更多信息