Python Forum

Full Version: Am trying to use speech_recognition module but getting error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Guys,
Am using Ubuntu 20.04 OS, Phython 3.8
While am running below basic program am getting error. Could you please some one guide me to fix this issue.
Error:
/home/nagaphani/PycharmProjects/Voice_Project/venv/Voice_Project/bin/python /home/nagaphani/PycharmProjects/Voice_Project/MainVoice.py 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 ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map 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 Say somthing Traceback (most recent call last): File "/home/nagaphani/PycharmProjects/Voice_Project/MainVoice.py", line 11, in <module> audio= r.listen(source) File "/home/nagaphani/PycharmProjects/Voice_Project/venv/Voice_Project/lib/python3.8/site-packages/speech_recognition/__init__.py", line 620, in listen buffer = source.stream.read(source.CHUNK) File "/home/nagaphani/PycharmProjects/Voice_Project/venv/Voice_Project/lib/python3.8/site-packages/speech_recognition/__init__.py", line 161, in read return self.pyaudio_stream.read(size, exception_on_overflow=False) File "/home/nagaphani/PycharmProjects/Voice_Project/venv/Voice_Project/lib/python3.8/site-packages/pyaudio.py", line 608, in read return pa.read_stream(self._stream, num_frames, exception_on_overflow) KeyboardInterrupt Process finished with exit code 130 (interrupted by signal 2: SIGINT)
import speech_recognition as sr
r = sr.Recognizer()
mic = sr.Microphone()
with mic as source:
    r.adjust_for_ambient_noise(source)
    print('Say somthing')
    audio= r.listen(source)

voice_data = r.recognize_google(audio)
print(voice_data)