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
4

3 回答 3

1

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

于 2020-08-19T19:34:35.213 回答
0

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

首先,您是否尝试过wire.py示例?这对我来说是开箱即用的。

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

  • 我没有尝试指定块大小。我只使用了默认值 0。我很可能相信这可能会导致您出现问题。
  • 您已指定“低”延迟流。至少在 OSX10.13 上,这会产生非常不稳定的音频(大量输入下溢)。如果稳定的音频对您很重要,我建议您考虑高于“高”的延迟选项。作为参考,Audacity 使用 100ms 并获得稳定的音频。此外,输入下溢通常意味着 indata 用零填充。

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

于 2020-07-30T23:00:24.047 回答
0

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

切换到从终端运行脚本,一切都发生了变化,我收到了许可请求,一切顺利。

于 2021-03-05T19:21:07.793 回答