Python 使用ossaudiodev进行播放

Python 使用ossaudiodev进行播放,python,audio,audio-streaming,Python,Audio,Audio Streaming,我正在尝试编写一个流式音频客户端,我想使用ossaudiodev函数来帮助我在本地机器上播放音频。不幸的是,每次尝试运行代码时都会出现异常: Unhandled exception in thread started by <function audioplayer at 0x88e96f4> Traceback (most recent call last): File "client.py", line 56, in audioplayer audio = ossau

我正在尝试编写一个流式音频客户端,我想使用ossaudiodev函数来帮助我在本地机器上播放音频。不幸的是,每次尝试运行代码时都会出现异常:

Unhandled exception in thread started by <function audioplayer at 0x88e96f4>
Traceback (most recent call last):
  File "client.py", line 56, in audioplayer
    audio = ossaudiodev.open("/dev/audio", 'w')
IOError: [Errno 16] Device or resource busy: '/dev/audio'
有什么窍门吗


编辑:答案是显而易见的和愚蠢的。我在运行代码时玩潘多拉,因此演讲者“忙”着这么做。有人能澄清为什么会这样吗?其他应用程序怎么能同时运行多个音频流,而我似乎不能?

即使在可用的系统上,OSS接口通常只是ALSA的一个门面。考虑使用一个支持多个接口的库,例如PYAO。

< P>你的桌面管理器已经使用了你的声卡,你可能会对DALY插件有更大的运气,但是它通常很难

。 soundblaster live具有硬件混音功能,因此您可以多次打开它

是的,你肯定可以找到pyao的工作后端

def audioplayer():

    audio = ossaudiodev.open("/dev/audio", 'w')
    audio.setfmt(ossaudiodev.AFMT_MU_LAW)
    audio.channels(2)
    audio.speed(8000)

    packet = 0

    sleep(.20) # give it a little bit of time to fill ze buffers

    while (packets[packet] != "\0"):
        audio.write(packets[packet])
        packet += 1