Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.3k stars 2.39k forks source link

ISSUE: SPEECH RECOGNITION NOT WORKING WITH LIVE RECORDING BUT IS WORKING ON A PRE RECORDED AUDIOFILE #557

Open Emilieve opened 3 years ago

Emilieve commented 3 years ago

SpeechRecognition is not giving a response if I use a live microphone.

I have successfully installed the SpeechRecognition library and PyAudio using python3 -m pip install ... I am working on a Raspberry Pi Zero in a virtual environment with Python 3.7.3 pip 21.0.1

I am using the Adafruit I2S MEMS Microphone Breakout and am able to successfully record using:

arecord -D plughw:1 -c1 -r 48000 -f S32_LE -t wav -V mono -v file.wav When I save this in a file (file.wav) and use the following code, the speech recognizer works:

import speech_recognition as sr

r = sr.Recognizer()
with sr.AudioFile('file.wav') as source:
        audio = r.record(source)

try:
        print("You said: " + r.recognize_google(audio))
except sr.UnknowValueError:
        print("Sorry, could not understand audio")
except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))
But when I want to do live speech recognition with the following code:

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone(1) as source:
        print("Say something!")
        audio = r.listen(source)

try:
        print("You said: " + r.recognize_google(audio))
except sr.UnknowValueError:
        print("Sorry, could not understand audio")
except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))

It gives the following output and keeps saying: 'Say something' without showing any transcript:

ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
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:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib conf.c:5014:(snd_config_expand) Unknown parameters {AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
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
Say something!

When I press ^C after a while because nothing is happening the following bit is added:

^CTraceback (most recent call last):
  File "srwm.py", line 6, in <module>
    audio = r.listen(source)
  File "/home/pi/.virtualenvs/pythonyt/lib/python3.7/site-packages/speech_recognition/__init__.py", line 620, in listen
    buffer = source.stream.read(source.CHUNK)
  File "/home/pi/.virtualenvs/pythonyt/lib/python3.7/site-packages/speech_recognition/__init__.py", line 161, in read
    return self.pyaudio_stream.read(size, exception_on_overflow=False)
  File "/home/pi/.virtualenvs/pythonyt/lib/python3.7/site-packages/pyaudio.py", line 608, in read
    return pa.read_stream(self._stream, num_frames, exception_on_overflow)
KeyboardInterrupt

Please let me know if any more information is needed. I hope there is someone really smart that can help me, thanks in advance!


  1. (How do you make the issue happen? Does it happen every time you try it?) Yes happens everytime I use live audio speech to text. When doing speech to text on a pre-recorded file I have no problems.
  2. (Make sure to go into as much detail as needed to reproduce the issue. Posting your code here can help us resolve the problem much faster!) Done, let me know if I can provide you with any more info
  3. (If there are any files, like audio recordings, don't forget to include them.)

Expected behaviour

Expect to display 'Say something!' and when I stop talking show the transcript of what is said.

Actual behaviour

Only displays 'Say something!' doesn't convert any speech to text.

(If the library threw an exception, paste the full stack trace here)

System information

(Delete all the statements that don't apply.)

My system is . (For example, "Ubuntu 16.04 LTS x64", "Windows 10 x64", or "macOS Sierra".)

My Python version is <3.7.3>. (You can check this by running python -V.)

My Pip version is <21.0.1>. (You can check this by running pip -V.)

My SpeechRecognition library version is <3.8.1>. (You can check this by running python -c "import speech_recognition as sr;print(sr.__version__)".)

My PyAudio library version is <0.2.11> / I don't have PyAudio installed. (You can check this by running python -c "import pyaudio as p;print(p.__version__)".)

My microphones are: ['bcm2835 HDMI 1: - (hw:0,0)', 'snd_rpi_i2s_card: simple-card_codec_link snd-soc-dummy-dai-0 (hw:1,0)', 'sysdefault', 'lavrate', 'samplerate', 'speexrate', 'pulse', 'upmix', 'vdownmix', 'dmix', 'default']

My working microphones are: (You can check this by running python -c "import speech_recognition as sr;print(sr.Microphone.list_working_microphones())".): AttributeError: type object 'Microphone' has no attribute 'list_working_microphones'

I installed PocketSphinx from . (For example, from the Debian repositories, from Homebrew, or from the source code.) I have not installed PocketSphinx?

danic85 commented 2 years ago

@Emilieve I can reproduce this as well with the same microphone breakout. Have you found a fix or workaround?

firefly19 commented 2 years ago

这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

Emilieve commented 2 years ago

Hi Dan,

I did find a fix. However, I do not remember it. I will check tomorrow if I wrote it down somewhere and let you know!

Kind regards Emilie

On Tue, 21 Dec 2021, 21:09 Dan Nicholson, @.***> wrote:

@Emilieve https://github.com/Emilieve I can reproduce this as well with the same microphone breakout. Have you found a fix or workaround?

— Reply to this email directly, view it on GitHub https://github.com/Uberi/speech_recognition/issues/557#issuecomment-999062270, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDWTZUKZZLI7TQ4HPO4MGTUSDNGLANCNFSM4ZOLCKYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

danic85 commented 2 years ago

Thanks @Emilieve - I appreciate the help.

marcopyre commented 1 year ago

Hi Dan, I did find a fix. However, I do not remember it. I will check tomorrow if I wrote it down somewhere and let you know! Kind regards Emilie On Tue, 21 Dec 2021, 21:09 Dan Nicholson, @.> wrote: @Emilieve https://github.com/Emilieve I can reproduce this as well with the same microphone breakout. Have you found a fix or workaround? — Reply to this email directly, view it on GitHub <#557 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDWTZUKZZLI7TQ4HPO4MGTUSDNGLANCNFSM4ZOLCKYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.>

Hi, I really need to know how you fixed it if you can tell me i cant find any fix about it its my last hope

danic85 commented 1 year ago

Hi @marcopyre - I can't remember the exact details, but when I tracked through this issue on my side it was a problem with the pi configuration and the MEMS microphones. I added some notes about it to this README:

https://github.com/danic85/companion-robot#mems-microphone-configuration-for-speech-recognition

Emilieve commented 1 year ago

Hi, for me I think it was the microphone that was broken in the end! :(

On Tue, 11 Apr 2023 at 09:10, Dan Nicholson @.***> wrote:

Hi @marcopyre https://github.com/marcopyre - I can't remember the exact details, but when I tracked through this issue on my side it was a problem with the pi configuration and the MEMS microphones. I added some notes about it to this README:

https://github.com/danic85/companion-robot#mems-microphone-configuration-for-speech-recognition

— Reply to this email directly, view it on GitHub https://github.com/Uberi/speech_recognition/issues/557#issuecomment-1502792390, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDWTZQQLBQ6VRNYSTX54ODXAT7WRANCNFSM4ZOLCKYQ . You are receiving this because you were mentioned.Message ID: @.***>

-- Met vriendelijke groet,

Emilie van Eps