简体   繁体   English

如何使用 macOS 上的 Speech_recognition 模块修复“OSError: [Errno -9986] Internal PortAudio 错误”?

[英]How to fix “OSError: [Errno -9986] Internal PortAudio error” with speech_recognition module on macOS?

I was trying to build a speech-to-text recognition with python on macOS (please do not post suggestions for Windows devices here).我试图在 macOS 上使用 python 构建语音到文本识别(请不要在此处发布有关 Windows 设备的建议)。

I'm trying to use the SpeechRecognition example code and developing my application, but every time I try to run the code I get the following error:我正在尝试使用 SpeechRecognition 示例代码并开发我的应用程序,但每次尝试运行代码时都会出现以下错误:

OSError: [Errno -9986] Internal PortAudio error OSError: [Errno -9986] 内部端口音频错误

I already have installed PortAudio with brew install portaudio and PyAudio as well with pip3 install pyaudio .我已经使用brew install portaudio和 PyAudio 以及pip3 install pyaudio

Here is the example code:这是示例代码:

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))

This is the traceback of the error message:这是错误消息的回溯:

||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

Try the following:尝试以下操作:

  1. brew uninstall portaudio brew卸载portaudio
  2. brew install portaudio --HEAD酿造安装 portaudio --HEAD

This worked for me.这对我有用。 I got it from this Github issue: https://github.com/spatialaudio/python-sounddevice/issues/299我从这个 Github 问题中得到它: https://github.com/spatialaudio/python-sounddevice/issues/299

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PyAudio OSError:[Errno -9986] 内部 PortAudio 错误 - PyAudio OSError: [Errno -9986] Internal PortAudio error Python:Portaudio Errno -9986 内部 PortAudio 错误 - Python: Portaudio Errno -9986 Internal PortAudio error 如何使用 Speech_recognition 修复模块导入错误? - How to fix Module Import Error with speech_recognition? 计算机扬声器上带有 python 的 Speech_Recognition - OSError: [Errno -9998] 通道数无效 - Speech_Recognition with python on computer speakers - OSError: [Errno -9998] Invalid number of channels 属性错误:模块“ speech_recognition”没有属性“ Recognizer” - Attribute error:module 'speech_recognition' has no attribute 'Recognizer' 使用语音识别模块 PYTHON 中的麦克风()时出错 - Error using Microphone() from speech_recognition module PYTHON ModuleNotFoundError:没有名为“ speech_recognition”的模块 - ModuleNotFoundError: No module named 'speech_recognition' python speech_recognition模块占用麦克风 - python speech_recognition module occupies microphone 语音识别:AttributeError:模块“ speech_recognition”没有属性“ Recognizer” - Speech Recognition: AttributeError: module 'speech_recognition' has no attribute 'Recognizer' Python 中没有名为“speech_recognition”的模块 - No module named 'speech_recognition' in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM