我试图使我的音频接口(interface)连续循环播放相同的音频。有人建议在声音设备库中使用“OutputStream”功能。这是我为此编写的代码:
sounddevice.default.device = "Focusrite USB ASIO, ASIO"
sounddevice.default.samplerate = 48000
stream = sounddevice.OutputStream()
stream.start()
stream.write(data)
最后一行代码给了我错误:
我究竟做错了什么?
最佳答案
我的工作方式是使用:
with sounddevice.OutputStream(device="Focusrite USB ASIO, ASIO", channels=8, callback=callback, samplerate=samplesPerSecond)
这会反复调用回调函数。在回调函数中,我设置输出:
def callback(outdata, frames, time, status):
for i in range(8):
channels[i] = audioData
multiChannel = np.column_stack((channels[0], channels[1], channels[2], channels[3], channels[4], channels[5], channels[6], channels[7]))
outdata[:] = multiChannel
关于python - 如何在python中使用sounddevice打开音频输出流?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61415407/