首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用OSError模块修复“PortAudio:[Errno -9986]内部PortAudio错误”?

如何用OSError模块修复“PortAudio:[Errno -9986]内部PortAudio错误”?
EN

Stack Overflow用户
提问于 2021-02-27 22:39:03
回答 1查看 531关注 0票数 3

我试图在macOS上用python构建一个语音到文本的识别(请不要在这里发布关于Windows设备的建议)。

我试图使用SpeechRecognition示例代码并开发我的应用程序,但是每次我试图运行该代码时,我都会得到以下错误:

OSError: Errno -9986内部PortAudio错误

我已经在brew install portaudio和PyAudio以及pip3 install pyaudio中安装了PyAudio。

下面是示例代码:

代码语言:javascript
复制
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))

这是错误消息的追溯:

代码语言:javascript
复制
||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
EN

回答 1

Stack Overflow用户

发布于 2021-03-23 11:22:57

尝试以下几点:

  1. brew卸载端口音频
  2. brew安装端口音频-HEAD

这对我有用。我是从这个杂志上得到的:https://github.com/spatialaudio/python-sounddevice/issues/299

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66404109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档