Python 语音识别,Pyaudio 不听但给这个

Python Speech Recognition,Pyaudio not listening but giving this

我正在尝试使用语音识别将语音转换为文本,python.It 中的 pyaudio 在转换预先录制的音频文件时工作正常,但是当我使用麦克风(外部)录制时,它没有收听而是显示这个:

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map

这是我的代码:

import speech_recognition as sr
r = sr.Recognizer()
mic = sr.Microphone()
with mic as source:
  print('say somthing')
  audio = r.listen(source)
 
print(r.recognize_google(audio))

试试这个代码块。即使在实时输入中,这在我的系统中也能完美运行。

import speech_recognition as sr
def myCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source, phrase_time_limit = 5)  
    try:
        command = r.recognize_google(audio).lower()
        print("you said: " + command)
        
    except sr.UnknownValueError:
        print("Sorry, Cant understand, Please say again")
        command = myCommand()
    return command