PyAudio prints ALSA warnings and does not work

10,505

Solution 1

if someone is still looking for getting rid of

ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map

I just commented out all pcm.surround* lines in "PCM interface" section in

/usr/share/alsa/alsa.conf

file and it works fine for me.

Solution 2

It seems that you have multiple audio input sources, and the first one is not supported by the speech-recognition library. There is another possibility that you have no audio inputs at all.

Try different indexes (e.g. 0, 1, 2, etc) with sr.Microphone(...) as per example below:

with sr.Microphone(device_index=0) as source:

But first, it's a good idea to run cat /proc/asound/card to see what audio devices you've got.

Share:
10,505
Charan Karthikeyan
Author by

Charan Karthikeyan

Updated on September 07, 2022

Comments

  • Charan Karthikeyan
    Charan Karthikeyan almost 2 years

    I am trying to run a basic python speech to text code. This is the code.

    import speech_recognition as sr
    r = sr.Recognizer()
    with sr.Microphone() as source:                
    audio = r.listen(source)                   
    
    try:
       print("You said " + r.recognize(audio))     
    except LookupError:                            
       print("Could not understand audio")
    

    The code works fine until it reaches the print stage, then it throws this error. Is there anything that I have done wrong?

    ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
    ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
    ALSA lib pcm.c:2266:(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
    
  • Charan Karthikeyan
    Charan Karthikeyan over 7 years
    the "cat /proc/asound/card" returns as no such directory found
  • Charan Karthikeyan
    Charan Karthikeyan over 7 years
    "OSError: [Errno -9998] Invalid number of channels" if i give the device index as more than 0, and returns the same statements as above when I give the device_index value as 0
  • zmechanic
    zmechanic over 7 years
    Sorry, that must be cat /proc/asound/cards. Have no Linux at this moment. Have a look at this article: alsa.opensrc.org/Proc_asound_documentation
  • zmechanic
    zmechanic over 7 years
    Just realized that you would like to get rid off error messages. See this post for your problem stackoverflow.com/a/13453192/1786034
  • Charan Karthikeyan
    Charan Karthikeyan over 7 years
    Hmmm it works for the pcm.c errors but i cant remove the other four lines(last 4).
  • zmechanic
    zmechanic over 7 years
    I recommend you to read this: github.com/Uberi/speech_recognition/issues/27