【问题标题】:Python Sounddevice Callback returning an array with zerosPython Sounddevice 回调返回一个带零的数组
【发布时间】:2020-11-16 10:25:02
【问题描述】:

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

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

【问题讨论】:

    标签: python-3.x macos portaudio python-sounddevice


    【解决方案1】:

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

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

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

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

    以后对这个问题感兴趣的朋友,不妨看看sounddevice at GitHub发的issue。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        切换到从终端运行脚本,一切都变了,我收到了权限请求,一切顺利。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-04-12
          • 1970-01-01
          • 1970-01-01
          • 2019-08-11
          • 2018-07-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多