Python Sounddevice回调返回一个包含0的数组



我正在尝试Python Sounddevice lib从麦克风流式传输音频

self.audio_streamer = sd.Stream(device=self.input_device, channels=self.channels,
samplerate=self.sampling_rate, dtype='int16',
callback=self.update_audio_feed, blocksize=self.audio_block_size,
latency='low')```

def update_audio_feed(self, indata, outdata, frames, time, status):
print("update_audio_feed")
if status:
print(status, file=sys.stderr)
print(indata)
outdata.fill(0)

Output :
The indata is an array with 0's always from the callback.
update_audio_feed
[[0]
[0]
[0]
...
[0]
[0]
[0]]
Sounddevice is detectingt the mic fine but not getting the signal :
Device Info: {'name': 'MacBook Pro Microphone', 'hostapi': 0, 'max_input_channels': 1, 'max_output_channels': 0, 'default_low_input_latency': 0.04852607709750567, 'default_low_output_latency': 0.01, 'default_high_input_latency': 0.05868480725623583, 'default_high_output_latency': 0.1, 'default_samplerate': 44100.0}
Sampling rate: 44100.0

我的mac上的问题是安全/权限问题。当我尝试通过Visual Studio控制台运行python脚本时,它不起作用。。。但当我尝试mac终端时,它提示我要麦克风,一切都开始工作了。。

更多详细信息请点击此处:https://www.reddit.com/r/MacOS/comments/9lwyz0/mojave_not_privacy_settings_blocking_all_mic/

https://github.com/spatialaudio/python-sounddevice/issues/267

几个月来,我一直在许多Mac电脑上使用sounddevice,但没有出现重大问题。

首先,你试过wire.py的例子吗?这对我来说是开箱即用的。

我在你的代码中注意到两件事:

  • 我还没有尝试指定块大小。我只使用了默认值0。我完全可以相信这可能会给你带来问题
  • 您指定了一个";"低";latency流。至少在OSX10.13上,这会产生非常不稳定的音频(大量输入下溢(。如果稳定的音频对你来说很重要,我建议你考虑比"延迟"更高的延迟选项;高";。作为参考,Audacity使用100ms并获得稳定的音频。此外,输入下溢通常意味着indata填充了零

对于那些未来对这个问题感兴趣的人,你可能希望看看GitHub上sounddevice上发布的问题。

我在MacOS上遇到了同样的问题,但我是从vscode运行脚本的。事实上,vscode不会要求麦克风权限,所以它会假设它有这个权限(但它没有(,你会得到一个空数组。

切换到从终端运行脚本,一切都变了,我得到了许可请求,一切都很顺利。

相关内容

最新更新