speech_recognition
speech_recognition copied to clipboard
"ALSA lib unable to open slave" When calling Microphone()
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']
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 **
`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()`
i am also getting same error
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:
And to fix "ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave" error:
type aplay -l
command:
read card id and then change alsa.conf again:
replacing 0's with your card id (in my case it's 1 (because i use card 1))
use .recognize() in place of .recognize_google()
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:
And to fix "ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave" error: type
aplay -l
command:
read card id and then change alsa.conf again:
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.