我想使用语音识别来识别来自麦克风的语音(内置在Mac Book Pro / air pods中)。
因此,我按照说明安装了端口音频。
brew info portaudio
返回:portaudio: stable 19.7.0 (bottled), HEAD
在我的项目(pipenv环境)中,我安装了PyAudio和SpeechRecognition。我的pipenv图如下所示:
cffi==1.14.5
- pycparser [required: Any, installed: 2.20]
pocketsphinx==0.1.15
PyAudio==0.2.11
SpeechRecognition==3.8.1
从音频文件中识别语音是有效的,但是只要我使用麦克风,它就不能。例如,当我在控制台中输入以下命令进行测试时:
python3 -m speech_recognition
这将打印出来:
A moment of silence, please...
Set minimum energy threshold to 45.131829621150224
Say something!
但它对我的声音没有反应。
或者当我运行这段代码时:
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))
没有错误消息,但即使我说了什么,之后也不会发生任何事情。
当我跑的时候
print(sr.Microphone.list_microphone_names())
我回来了
['AirPods of MyName', 'AirPods of MyName', 'Built-in Microphone', 'Built-in Output']
因此,麦克风应该被识别出来。
发布于 2021-06-28 03:12:54
我也有同样的问题。我不知道这个问题是否已经为你解决了。
对我来说,问题是在VS Code...as中使用集成终端,这里提到了Python speech recognition is stuck (Mac)
我尝试了一下外部终端(iTerm),一切工作正常。实际上,我的终端必须获得许可才能访问我的麦克风。VS代码中的集成终端似乎没有获得使用it...will的许可,稍后必须弄清楚这一点。
PS -经过快速搜索,这个问题的一个答案发布在这里,Mac OS Mojave microphone permission for Visual Studio Code它仍然是一个有点简陋的but...works。
https://stackoverflow.com/questions/67200257
复制相似问题