![](/img/trans.png)
[英]PyAudio OSError: [Errno -9986] Internal PortAudio error
[英]Python: Portaudio Errno -9986 Internal PortAudio error
我正在嘗試運行一個簡單的 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 運行程序解決了這個問題。
`brew卸載portaudio
brew install portaudio --HEAD`
消除 Mac Big sur 上的這個錯誤
您能否確認您的麥克風工作正常,並且在安裝Mojave
后不受音頻問題的影響,請參考此處。
你的代碼看起來不錯。 看起來錯誤是由microphone
系統中的一些故障引起的。 確保您已正確遵循 package 索引頁中的說明。 尤其,
PyAudio(用於麥克風用戶)當且僅當您想要使用麥克風輸入(麥克風)時才需要 PyAudio。 PyAudio 版本 0.2.11+ 是必需的,因為早期版本在某些情況下從麥克風錄制時已知 memory 管理錯誤。
您還應該在此處看到此線程上發布的一些解決方案 - 回復:錯誤代碼 -9986 內部 PortAudio 錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.