【发布时间】:2020-10-26 06:16:18
【问题描述】:
我正在尝试运行一个简单的 python 语音识别程序。代码如下:
import speech_recognition as sr
import pyttsx3
r = sr.Recognizer()
engine = pyttsx3.init("nsss",True)
engine.say("hello")
engine.runAndWait()
while True:
try:
print("starting process")
with sr.Microphone() as source2:
r.adjust_for_ambient_noise(source2, duration=0.2)
print("completed adjustment")
audio2 = r.listen(source2)
MyText = r.recognize_google(audio2)
MyText = MyText.lower()
print("Did you say "+MyText)
SpeakText(MyText)
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
except sr.UnknownValueError:
print("an unknown error occured")
运行时,语音测试成功说“你好”,但随后抛出
||PaMacCore (AUHAL)|| Failed to open AUHAL component.||PaMacCore (AUHAL)|| Error on line 1263: err='-50', msg=Unknown Error
Traceback (most recent call last):
File "test1.py", line 16, in <module>
with sr.Microphone() as source2:
File "/Users/markus/Library/Python/3.6/lib/python/site-packages/speech_recognition/__init__.py", line 141, in __enter__
input=True, # stream is an input stream
File "/Users/markus/Library/Python/3.6/lib/python/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/Users/markus/Library/Python/3.6/lib/python/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9986] Internal PortAudio error
我已尝试使用 brew 卸载并重新安装 portaudio。
-- 编辑--
我在 musescore 中遇到了与 portaudio 类似的问题,使用 sudo 运行程序解决了这个问题。
【问题讨论】:
标签: python python-3.x macos portaudio pyttsx