![](/img/trans.png)
[英]PyAudio OSError: [Errno -9986] Internal PortAudio error
[英]How to fix “OSError: [Errno -9986] Internal PortAudio error” with speech_recognition module on macOS?
我試圖在 macOS 上使用 python 構建語音到文本識別(請不要在此處發布有關 Windows 設備的建議)。
我正在嘗試使用 SpeechRecognition 示例代碼並開發我的應用程序,但每次嘗試運行代碼時都會出現以下錯誤:
OSError: [Errno -9986] 內部端口音頻錯誤
我已經使用brew install portaudio
和 PyAudio 以及pip3 install pyaudio
。
這是示例代碼:
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
這是錯誤消息的回溯:
||PaMacCore (AUHAL)|| Error on line 1277: err='-66748', msg=Unknown Error
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-1-a97bf104167b> in <module>
3 # obtain audio from the microphone
4 r = sr.Recognizer()
----> 5 with sr.Microphone() as source:
6 print("Say something!")
7 audio = r.listen(source)
/usr/local/lib/python3.9/site-packages/speech_recognition/__init__.py in __enter__(self)
136 try:
137 self.stream = Microphone.MicrophoneStream(
--> 138 self.audio.open(
139 input_device_index=self.device_index, channels=1,
140 format=self.format, rate=self.SAMPLE_RATE, frames_per_buffer=self.CHUNK,
/usr/local/lib/python3.9/site-packages/pyaudio.py in open(self, *args, **kwargs)
748 """
749
--> 750 stream = Stream(self, *args, **kwargs)
751 self._streams.add(stream)
752 return stream
/usr/local/lib/python3.9/site-packages/pyaudio.py in __init__(self, PA_manager, rate, channels, format, input, output, input_device_index, output_device_index, frames_per_buffer, start, input_host_api_specific_stream_info, output_host_api_specific_stream_info, stream_callback)
439
440 # calling pa.open returns a stream object
--> 441 self._stream = pa.open(**arguments)
442
443 self._input_latency = self._stream.inputLatency
OSError: [Errno -9986] Internal PortAudio error
嘗試以下操作:
這對我有用。 我從這個 Github 問題中得到它: https://github.com/spatialaudio/python-sounddevice/issues/299
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.