sounddevice.play() 不起作用并且不发送错误

问题描述

我正在尝试录制一些合成器并使用 sounddevice 模块播放它们,它似乎可以正确录制,因为 print(my_recording) 返回一个填充了典型疯狂音频数字的数组,但函数 sd.play() 似乎导致没有效果,但没有弹出错误

我正在使用 focusrite Scarlett 18i8 gen 1 音频接口,它似乎已正确连接,因为我为 sd.default.device 提供了正确的 ID,并且我收到了有关与其同步的通知,尽管我已经注意到sd.default.channels 变量有些奇怪 - 它不接受 sd.query_devices() 明确说明的可用输出数量(对于我来说,它是“14 Focusrite USB ASIO,ASIO(18 进,8 出)”设备)。程序运行良好,直到它到达 sd.play() (我可以通过打印的字符串来判断)。这是当我尝试使用 sd.default.channels = (18,8) 运行程序时弹出的错误

sounddevice.PortAudioError: Error opening OutputStream: Invalid number
of channels [PaErrorCode -9998]

例如,当我将其调整为 (2,2) 时,它不会运行任何错误,但仍然没有真正播放音频。老实说,我不明白为什么该函数接受“输入/输出通道数”。正如文档所述,而不是与乐器/扬声器连接的确切通道。所以我试图以对我来说更自然的方式对待它,通过提供确切的频道 ID(根据我的音频接口手册)作为 Ins 是元组中的第一个值,而 Outs 是第二个值,但不出所料,它没有工作。

这是我的代码

''' capturing the sound from the synth '''
sd.default.samplerate = 44100
sd.default.device = 14
sd.default.channels = (18,8)
duration = 10

print('records')
my_recording = sd.rec(int(44100 * duration))
sd.wait()
print('done recording')
time.sleep(3)
print('playing back')
sd.play(my_recording)
sd.wait()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)