Errors while running speech_recognition module - python-3.x

I'm working on a project which uses the speech_recognition module.
# Importing all the installed packages
import speech_recognition as sr
audio = sr.Recognizer
try:
with sr.Microphone() as source:
voice = audio.listen(source)
command = audio.recognize_google(voice)
print(command)
finally:
pass
I'm getting this error
I tried all the possible solutions and yet I get the same error again and again
I'm using the PyCharm editor.
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWitePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Traceback (most recent call last):
File "/home/rohan/Rocland_Python/Rocland/Rocland2.py", line 9, in <module>
command = audio.recognize_google(sound)
File "/home/rohan/Rocland_Python/Rocland/venv/lib/python3.9/site-
packages/speech_recognition/__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0:
raise UnknownValueError()
speech_recognition.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/rohan/Rocland_Python/Rocland/Rocland2.py", line 10, in <module>
except: command = command.lower()
NameError: name 'command' is not defined
Please help me. Thanks!

Here i have the speech recognition code snippet which i have used in one of my code , i hope it will work for yours also:
import speech_recognition as sr
rObject = sr.Recognizer()
audio = ''
with sr.Microphone() as source:
print("Speak...")
audio = rObject.listen(source, phrase_time_limit = 0)
print("Stop.")
try:
text = rObject.recognize_google(audio, language ='en-US')
print("You : "+ text)
except:
speak("Could not understand your audio...PLease try again !")
Try and checkout !
There is socket as well as command = command.lower()

Related

ALSA lib pcm.c:8568:(snd_pcm_recover) underrun occurred

i have this code:
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
newVoiceRate = 200
engine.setProperty('rate', newVoiceRate)
def speak(audio):
engine.say(audio)
engine.runAndWait()
speak("hello this is a program")
and these errors:
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_a52.c:1001:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No existe el fichero o el directorio
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm.c:8568:(snd_pcm_recover) underrun occurred
Process finished with exit code 0
My SO is Manjaro :)

No output in speech recognition module of python

When i run below python script it shows some error.
import speech_recognition as s
sr=s.Recognizer()
print("Please, speak now....")
with s.Microphone() as m:
audio=sr.listen(m)
query=sr.recognize_google(audio,language='eng-in')
print(query)
I tried almost all solution available online but still my problem is not solved.
The error massage in command line is:
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_route.c:869:(find_matching_chmap) Found no matching channel map
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
But when i run this python script on jupyter-notebook or Pycharm it does't show any error but still not taking any input from microphone(but microphone start) and also not showing any output.

How do i make the Microphone() function work in SpeechRecognition in Linux

I am trying SpeechRecognition module but i can get it to work.
Can anyone pleas help me.
I am using Linux Mint
Thias is my python code:
import speech_recognition as sr
r = sr.Recognizer()
try:
with sr.Microphone() as source:
audio = r.listen(source)
text = r.recognize_google(audio)
print(text)
except:
print("not working")
and I get this error:
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open
slave
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
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_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1,
skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1,
skipping unlock
Expression 'parameters->channelCount <= maxChans' failed in
'src/hostapi/alsa/pa_linux_alsa.c', line: 1514
Expression 'ValidateParameters( inputParameters, hostApi,
StreamDirection_In )' failed in
'src/hostapi/alsa/pa_linux_alsa.c',
line: 2818
not working

Play sound in octave with pulseaudio

I would like to play sound in octave with pulseaudio. I saw this post but the octave audio management is changed in the new releases and it is not longer possible to use paplay like say that post, I have the version 4.2.1-4
Now when I try to use sound or audiolayer functions I get these errors:
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
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_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
And no sound is played, next, if I retry to use sound I don't get error and it waits for the sound duration, however it keep to not play sound.
It seems it would like to use ALSA, but I'm using pulseaudio what can i do?
EDIT:
I notice that sometimes the error message change and it say:
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1735
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1902
Expression 'PaAlsaStreamComponent_Initialize( &self->playback, alsaApi, outParams, StreamDirection_Out, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2170
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2835
error: audioplayer: unable to open audio playback stream
error: called from
playblocking at line 36 column 3
sound at line 59 column 3

speechRecognition: jack server is not running

I'm setting up a sound recognizer with the speechRecognition python library.
This is my code so far:
#!/usr/bin/env python3
import speech_recognition as sr
r = sr.Recognizer('es-MX')
with sr.Microphone() as mic:
audio = r.listen(mic)
print(r.recognize(audio))
On running I get
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_l$
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
I'm using SpeechRecognition version 1.3.1 running on Linux LXLE 14.04 x64 with python 3.4
It tells you it can not record audio on your device. It is not related to a jack server, it also tries to open alsa device and bluetooth audio device. Make sure that audio is properly set on your device. See also
PyAudio does not work and bricks sound on ubuntu
PyAudio working, but spits out error messages each time
I am having this same error. If you would like a work around you can use my code I wrote. I used the sounddevice library to record audio while there is audio it saves into one file, then convert it to text using the speech recognition library. The error comes when microphone is called in as it is using PyAudio.
https://shepai.github.io/code/PetSHEP/soundLib.py
The following lines should replace your "with microphone" bit
with sr.AudioFile(filename) as source:
Audio=r.record(source)
This is how I got round the problem, hope it helps :)

Resources