fix: replace blocking play_audio with async generator yielding playback duration in gcloud tts
This commit is contained in:
+5
-3
@@ -30,16 +30,18 @@ import os
|
||||
import subprocess
|
||||
import sys
|
||||
import pygame
|
||||
|
||||
import time
|
||||
|
||||
|
||||
async def play_audio_async(filename)
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load(filename)
|
||||
time_start = time.time()
|
||||
pygame.mixer.music.play()
|
||||
|
||||
while pygame.mixer.music.get_busy():
|
||||
await asyncio.sleep(0.1)
|
||||
yield
|
||||
duration = time.time() - time_start
|
||||
yield duration
|
||||
|
||||
|
||||
def play_audio(filename):
|
||||
|
||||
Reference in New Issue
Block a user