Skip to content

romanin-rf/seaplayer-audio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

seaplayer-audio

Description

The SeaPlayer library for async/sync playback audio.

The module is still under DEVELOPMENT, so I do not recommend using it in your projects.

Supported formats

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...

Usage (synchronously)

Through context manager

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()

Through cycle

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()

Usage (asynchronously)

Through context manager

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())

Through cycle

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())