From 3eff1e559b81ee394dad6b3cec1d9a475ae40586 Mon Sep 17 00:00:00 2001 From: Kwindla Hultman Kramer Date: Thu, 6 Jun 2024 11:11:06 -0400 Subject: [PATCH] pipecat async working, but maybe needs a threaded implementation --- src/pipecat/services/playht.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pipecat/services/playht.py b/src/pipecat/services/playht.py index 0c68512e4..b0f0ce5de 100644 --- a/src/pipecat/services/playht.py +++ b/src/pipecat/services/playht.py @@ -7,6 +7,7 @@ import io import struct import time +import asyncio from typing import AsyncGenerator @@ -52,6 +53,11 @@ class PlayHTTTSService(TTSService): ttfb = None logger.debug(f"Generating TTS: [{text}]") + async def async_generator(sync_gen): + for item in sync_gen: + await asyncio.sleep(0) # Yield control back to the event loop + yield item + try: b = bytearray() in_header = True @@ -62,7 +68,9 @@ class PlayHTTTSService(TTSService): # need to ask Aleix about this. frames are getting pushed. # but playback is blocked - for chunk in sync_gen: + + # for chunk in sync_gen: + async for chunk in async_generator(sync_gen): # skip the RIFF header. if in_header: b.extend(chunk)