speech_recognition icon indicating copy to clipboard operation
speech_recognition copied to clipboard

"ALSA lib unable to open slave" When calling Microphone()

Open IanMCharles opened this issue 4 years ago • 8 comments

Steps to reproduce

Any time I make a call to sr.Microphone() (after importing speech_recognition as sr), I get a list of error messages I'm specifically trying to use it in the following context:

import speech_recognition as sr

def get_input():
    r = sr.Recognizer()
    print(r)
    with sr.Microphone() as source:
        print(source)
        audio = r.listen(source)
        said = ""
        try:
            said = r.recognize_google(audio)
            print(said)
        except Exception as e:
            print("Exception: + " + str(e))
        return said

The program does not get input when it reaches the r.listen(source)

Expected behaviour

I'm expecting sr.Microphone() to not give me a full page of errors when I call it. I want it to get input from the user at audio = r.listen(source)

Actual behaviour

the line "with sr.Microphone() as source:" gives me the error message

ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave

(What happened instead? How is it different from what you expected?)

System information

My system is CentOS 7

My Python version is 3.6.8

My Pip version is 20.2.4

My SpeechRecognition library version is 3.8.1

My PyAudio library version is 0.2.11

My microphones are: ['HDA Intel HDMI: 0 (hw:0,3)', 'HDA Intel HDMI: 1 (hw:0,7)', 'HDA Intel HDMI: 2 (hw:0,8)', 'HDA Intel HDMI: 3 (hw:0,9)', 'HDA Intel HDMI: 4 (hw:0,10)', 'HDA Intel PCH: 92HD91BXX Analog (hw:1,0)', 'hdmi', 'pulse', 'default']

IanMCharles avatar Oct 19 '20 19:10 IanMCharles

This can get rid of the Unknown Device messages:

( sudo nano /usr/share/alsa/alsa.conf ) and comment out cards.pcm.{device} where {device} is the unknown devices listed

this will get rid of the jack server error, not sure about the others :

(sudo apt install multimedia-jack pulseaudio --kill jack_control start)

If you get memory errors logout/login AFTER running:

( sudo usermod -a -G audio MYUSERNAME ) Make sure you log out / in, otherwise permissions won't be updated.

You may need to run:

(jack_control start)

**commands are inside circular bracket **

amannegi117 avatar Oct 25 '20 16:10 amannegi117

`import speech_recognition as sr

def get_input(): r = sr.Recognizer() print(r) with sr.Microphone() as source: print(source) audio = r.listen(source)

    try:
        said = r.recognize_google(audio)
        print(said)
    except Exception as e:
        print("Exception:  " + str(e))
    return said

get_input()`

amannegi117 avatar Oct 25 '20 16:10 amannegi117

i am also getting same error

learncodingforweb avatar May 30 '23 10:05 learncodingforweb

The problem is related to the alsa.conf. Go to /usr/share/alsa/alsa.conf then comment lines with unknown PCM cards e.g. cards.pcm.rear:

image

And to fix "ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave" error: type aplay -l command:

image

read card id and then change alsa.conf again:

image

replacing 0's with your card id (in my case it's 1 (because i use card 1))

TheYoungBeast avatar Aug 09 '23 08:08 TheYoungBeast

use .recognize() in place of .recognize_google()

abhie16 avatar Dec 08 '23 14:12 abhie16

The problem is related to the alsa.conf. Go to /usr/share/alsa/alsa.conf then comment lines with unknown PCM cards e.g. cards.pcm.rear:

image

And to fix "ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave" error: type aplay -l command:

image

read card id and then change alsa.conf again:

image

replacing 0's with your card id (in my case it's 1 (because i use card 1))

How do you edit the file? as for me it says permission denied.

Vaish1795 avatar Mar 31 '24 11:03 Vaish1795