【问题标题】:How do I open an audio output stream using sounddevice in python?如何在 python 中使用 sounddevice 打开音频输出流?
【发布时间】:2020-05-15 00:03:04
【问题描述】:

我正在尝试让我的音频界面连续循环播放相同的音频。有人推荐使用 sounddevice 库中的“OutputStream”函数。这是我为此编写的代码:

sounddevice.default.device = "Focusrite USB ASIO, ASIO"
sounddevice.default.samplerate = 48000
stream = sounddevice.OutputStream()
stream.start()
stream.write(data)

最后一行代码给了我错误:

sounddevice.PortAudioError: 等待超时 [PaErrorCode -9987]

我做错了什么?

【问题讨论】:

  • sounddevice.play(data, blocking=True) 工作吗?

标签: python audio python-sounddevice


【解决方案1】:

我让它工作的方式是使用:

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

【讨论】:

  • 这里的channelsaudioData 是什么?
猜你喜欢
  • 1970-01-01
  • 2021-04-29
  • 1970-01-01
  • 1970-01-01
  • 2011-12-21
  • 2012-07-13
  • 1970-01-01
  • 2013-01-07
  • 2022-07-31
相关资源
最近更新 更多