using ossaudiodev for playback
I'm trying to write a streaming audio client and I'd like to use ossaudiodev functions to help me play back the audio on my local machine. Unfortunately, I'm getting an exception every time I try to run my code:
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'
Here's my code. Pretty simple methinks, but not sure how to free up the /dev/audio resource.
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
Any tricks to this?
Edit: The answer is obvious and stupid. I was playing pandora while running the code, thus the speakers were "busy" doing that. Can anyone clarify why this is so? How can other applications all run multiple audio streams at the same time, yet I seemingly can't?
Even on systems where it's available, the OSS interface is usually just a facade over ALSA. Consider using a library that supports multiple interfaces, such as pyao.
your desktop manager is already using your soundcard, you may have more luck with dmix plugin for alsa, but it's often difficult
soundblaster live has hw mixing so you can open it multiple times
and yes definitively you can find a working backend of pyao
精彩评论