diff --git a/src/rspeech/play.py b/src/rspeech/play.py index 848b19c..32a5728 100644 --- a/src/rspeech/play.py +++ b/src/rspeech/play.py @@ -32,17 +32,32 @@ import sys import pygame import time +PLAY_SOUND = True + +def stop_audio(): + global PLAY_SOUND + PLAY_SOUND = False + +async def stop_audio_async(): + global PLAY_SOUND + PLAY_SOUND = False + async def play_audio_async(filename): + global PLAY_SOUND + PLAY_SOUND = True pygame.mixer.init() pygame.mixer.music.load(filename) time_start = time.time() pygame.mixer.music.play() while pygame.mixer.music.get_busy(): + if not PLAY_SOUND: + pygame.mixer.music.stop() + break duration = time.time() - time_start yield duration - + def play_audio(filename): pygame.mixer.init()