简体   繁体   English

pyaudio-OSError: [Errno -9999] 意外的主机错误

[英]pyaudio-OSError: [Errno -9999] Unanticipated host error

I just want to run a simple python audio code:我只想运行一个简单的python音频代码:

import pyaudio
import wave
import sys

CHUNK = 1024
wf = wave.open("4.wav", 'rb')
# instantiate PyAudio (1)
p = pyaudio.PyAudio()
# open stream (2)
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                channels=wf.getnchannels(),
                rate=wf.getframerate(),
                output=True)

but I got the following error:但我收到以下错误:

Traceback (most recent call last):
  File "rec2.py", line 17, in <module>
    output=True)
  File "C:\Users\Surena\Anaconda3\lib\site-packages\pyaudio.py", line 750,  in open
    stream = Stream(self, *args, **kwargs)
  File "C:\Users\Surena\Anaconda3\lib\site-packages\pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error

I tried another pyaudio record too, the same error came up.我也尝试了另一个 pyaudio 记录,出现了同样的错误。 I also tried uninstall pyaudio and install it again using pip install pyaudio, but it did not help.我也尝试卸载 pyaudio 并使用 pip install pyaudio 再次安装它,但它没有帮助。 I even uninstalled anaconda3 and reinstall it.nothing changed.我什至卸载了 anaconda3 并重新安装了它。没有任何改变。

what is the problem?问题是什么?

我遇到了同样的问题,我只是通过在“设置”>“机密性”>“麦克风”(在 Windows 10 上)中启用/禁用对麦克风的访问来解决它

You need to collect additional information to understand the problem.您需要收集其他信息以了解问题。 From Portaudio docs :来自Portaudio 文档

PortAudio usually tries to translate error conditions into portable PaError error codes. PortAudio 通常会尝试将错误条件转换为可移植的 PaError 错误代码。 However if an unexpected error is encountered the paUnanticipatedHostError code may be returned.但是,如果遇到意外错误,可能会返回 paUnanticipatedHostError 代码。 In this case a further mechanism is provided to query for Host API-specific error information.在这种情况下,提供了进一步的机制来查询主机 API 特定的错误信息。 If PortAudio returns paUnanticipatedHostError you can call Pa_GetLastHostErrorInfo() to retrieve a pointer to a PaHostErrorInfo structure that provides more information, including the Host API that encountered the error, a native API error code and error text.如果 PortAudio 返回 paUnanticipatedHostError,您可以调用 Pa_GetLastHostErrorInfo() 来检索指向 PaHostErrorInfo 结构的指针,该结构提供更多信息,包括遇到错误的主机 API、本机 API 错误代码和错误文本。

If you have this error on Linux, most likely it is caused by incompatible sample rate you are trying to request from the driver.如果您在 Linux 上遇到此错误,很可能是由于您尝试从驱动程序请求的采样率不兼容造成的。 This value这个值

            rate=wf.getframerate()

can be changed to 16000, 44100 and 48000 to test which rate is actually supported.可以改为16000、44100、48000来测试实际支持哪个速率。

我遇到了同样的问题,所以我只是从设置中授予麦克风权限,其工作只需转到设置 --> 隐私 --> 麦克风,然后在麦克风上授予麦克风权限

如果您使用的是 Windows 10 搜索麦克风隐私设置

Okay so if you using jupyter-notebook and you face this challenge.好吧,如果您使用 jupyter-notebook 并且面临这个挑战。 install pyaudio with homebrew(brew install pyaudio) and then restart your kernel.使用自制软件安装 pyaudio(brew install pyaudio),然后重新启动内核。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM