feat: add async play_audio_async generator with pygame mixer polling loop

Introduce an asynchronous generator function `play_audio_async` in `src/rspeech/play.py` that initializes the pygame mixer, loads and plays a given audio file, then yields control every 100ms while the music is still busy, enabling non-blocking audio playback in async contexts.
This commit is contained in:
retoor 2025-01-18 14:38:02 +00:00
parent 66ae51ee86
commit a75a6574ba

View File

@ -33,6 +33,13 @@ import pygame
async def play_audio_async(filename)
pygame.mixer.init()
pygame.mixer.music.load(filename)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
await asyncio.sleep(0.1)
yield
def play_audio(filename):