I want to use speech recognition to recognize speech from the microphone (built in on Mac Book Pro / air pods).
So I followed the instructions and installed port audio.
brew info portaudio
returns:
portaudio: stable 19.7.0 (bottled), HEAD
And in my project (pipenv environment), I installed PyAudio and SpeechRecognition. My pipenv graph looks like this:
cffi==1.14.5
- pycparser [required: Any, installed: 2.20]
pocketsphinx==0.1.15
PyAudio==0.2.11
SpeechRecognition==3.8.1
Recognizing speech from audio files works, but whenever I use the Microphone, it doesn't. For example, when I enter this command into the console for testing:
python3 -m speech_recognition
This gets printed:
A moment of silence, please...
Set minimum energy threshold to 45.131829621150224
Say something!
But it does not react to my voice.
Or when I run this code:
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("Say something!")
audio = r.listen(source)
# recognize speech using Sphinx
try:
print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
There is no error message, but nothing happens afterwards even if I say something.
When I run
print(sr.Microphone.list_microphone_names())
I get back
['AirPods of MyName', 'AirPods of MyName', 'Built-in Microphone', 'Built-in Output']
So the microphones should be recognized.
I had the same exact problem. I don't know if this has been resolved for you.
The problem for me was with using an integrated terminal in VS Code...as noted here Python speech recognition is stuck (Mac)
I tried the external terminal (iTerm) and everything works well. My terminal actually had to get permission to access my microphone. It seems the integrated terminal in VS Code isn't receiving permission to use it...will have to figure that one out later.
PS - After a quick search the one answer to this is posted here Mac OS Mojave microphone permission for Visual Studio Code It's still a little janky but...works.