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()