I am attempting to write a speech recognition program for the raspberry pi, however I am facing some issues using python's speech_recognition library.From the error messages (posted below) I think the issue may be with the wrong sound card being accessed, however I am able to record with PyAudio (which I think the microphone class uses) as well as 'arecord'Below is the code I am trying to run:import speech_recognition as srr = sr.Recognizer()with sr.Microphone() as source:    while True:        audio = r.listen(source)        try:            printf(You said  + r.recognize(audio))        except LookupError:            printf(Could not understand audio)I have made some adjustments to which soundcard is used as default.My /etc/modprobe.d/alsa-base.conf file is untouched and standard.I have created a file in /home/pi under the name .asoundrc which contains:pcm.!default {     type asym     playback.pcm hw:0,0     capture.pcm hw:1,0    }This allows for recording from the USB microphone and playback through the on-board headphone jack port.Below is the error message I received when trying to run the python script:pi@raspberrypi ~/Desktop $ python speechtester.pyALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.front.0:CARD=0'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM frontALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rearALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfeALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.sideALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround40.0:CARD=0'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround40ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround41ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround50ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround51ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround71.0:CARD=0'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround71ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM iec958ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM spdifALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directoryALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM spdifALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmiALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmiALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modemALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modemALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phonelineALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phonelineALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback streamCannot connect to server socket err = No such file or directoryCannot connect to server request channeljack server is not running or cannot be startedApologies for the relatively long post I just wanted to provide as much information as possible.
Unable to use python speech_recognition lib Microphone class due to ALSA
audio;python;alsa