The SeaPlayer library for async/sync playback audio.
The module is still under DEVELOPMENT, so I do not recommend using it in your projects.
It is based on the sounddevice and soundfile module.
soundfile, in turn, is a wrapper of the C library libsndfile, which has limitations in file reading formats. More info...
import time
from seaplayer_audio import CallbackSoundDeviceStreamer, FileAudioSource
def main():
with FileAudioSource('example.mp3') as source:
with CallbackSoundDeviceStreamer() as streamer:
while len(data := source.readline(1)) > 0:
streamer.send( data )
time.sleep(0.01) # Optional
if __name__ == '__main__':
main()
import time
from seaplayer_audio import CallbackSoundDeviceStreamer, FileAudioSource
def main():
file = FileAudioSource('example.mp3')
streamer = CallbackSoundDeviceStreamer()
streamer.start()
while len(data := source.readline(1)) > 0:
streamer.send( data )
time.sleep(0.01) # Optional
streamer.stop()
file.close()
if __name__ == '__main__':
main()
import asyncio
from seaplayer_audio import AsyncCallbackSoundDeviceStreamer, AsyncFileAudioSource
async def main():
async with AsyncFileAudioSource('example.mp3') as source:
async with AsyncCallbackSoundDeviceStreamer() as streamer:
while len(data := await source.readline(1)) > 0:
await streamer.send( data )
await asyncio.sleep(0.01) # Optional
if __name__ == '__main__':
asyncio.run(main())
import asyncio
from seaplayer_audio import AsyncCallbackSoundDeviceStreamer, AsyncFileAudioSource
async def main():
file = FileAudioSource('example.mp3')
streamer = CallbackSoundDeviceStreamer()
await streamer.start()
while len(data := await source.readline(1)) > 0:
await streamer.send( data )
await asyncio.sleep(0.01) # Optional
await streamer.stop()
await file.close()
if __name__ == '__main__':
asyncio.run(main())