From a75a6574baae1bd4e83f5f706d636a67e4104f3e Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 18 Jan 2025 14:38:02 +0000 Subject: [PATCH] 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. --- src/rspeech/play.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rspeech/play.py b/src/rspeech/play.py index 1fc1096..8d75518 100644 --- a/src/rspeech/play.py +++ b/src/rspeech/play.py @@ -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):