diff --git a/src/pipecat/services/aws.py b/src/pipecat/services/aws.py index cb0af1e30..4a2eceab6 100644 --- a/src/pipecat/services/aws.py +++ b/src/pipecat/services/aws.py @@ -190,7 +190,7 @@ class AWSTTSService(TTSService): await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() if "AudioStream" in response: with response["AudioStream"] as stream: @@ -203,7 +203,7 @@ class AWSTTSService(TTSService): frame = TTSAudioRawFrame(chunk, self._settings["sample_rate"], 1) yield frame - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() except (BotoCoreError, ClientError) as error: logger.exception(f"{self} error generating TTS: {error}") @@ -211,4 +211,4 @@ class AWSTTSService(TTSService): yield ErrorFrame(error=error_message) finally: - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() diff --git a/src/pipecat/services/azure.py b/src/pipecat/services/azure.py index 32af1b3f4..eff5d333f 100644 --- a/src/pipecat/services/azure.py +++ b/src/pipecat/services/azure.py @@ -261,14 +261,14 @@ class AzureTTSService(TTSService): if result.reason == ResultReason.SynthesizingAudioCompleted: await self.start_tts_usage_metrics(text) await self.stop_ttfb_metrics() - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() # Azure always sends a 44-byte header. Strip it off. yield TTSAudioRawFrame( audio=result.audio_data[44:], sample_rate=self._settings["sample_rate"], num_channels=1, ) - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() elif result.reason == ResultReason.Canceled: cancellation_details = result.cancellation_details logger.warning(f"Speech synthesis canceled: {cancellation_details.reason}") diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index 22e09cb2b..c23e96df9 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -255,8 +255,8 @@ class CartesiaTTSService(WordTTSService): await self._connect() if not self._context_id: - await self.push_frame(TTSStartedFrame()) await self.start_ttfb_metrics() + yield TTSStartedFrame() self._context_id = str(uuid.uuid4()) msg = self._build_msg(text=text) @@ -266,7 +266,7 @@ class CartesiaTTSService(WordTTSService): await self.start_tts_usage_metrics(text) except Exception as e: logger.error(f"{self} error sending message: {e}") - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() await self._disconnect() await self._connect() return @@ -331,8 +331,8 @@ class CartesiaHttpTTSService(TTSService): async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: logger.debug(f"Generating TTS: [{text}]") - await self.push_frame(TTSStartedFrame()) await self.start_ttfb_metrics() + yield TTSStartedFrame() try: voice_controls = None @@ -365,4 +365,4 @@ class CartesiaHttpTTSService(TTSService): logger.error(f"{self} exception: {e}") await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() diff --git a/src/pipecat/services/deepgram.py b/src/pipecat/services/deepgram.py index 433e08172..248efe3fc 100644 --- a/src/pipecat/services/deepgram.py +++ b/src/pipecat/services/deepgram.py @@ -84,7 +84,7 @@ class DeepgramTTSService(TTSService): ) await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() # The response.stream_memory is already a BytesIO object audio_buffer = response.stream_memory @@ -105,7 +105,7 @@ class DeepgramTTSService(TTSService): ) yield frame - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() except Exception as e: logger.exception(f"{self} exception: {e}") diff --git a/src/pipecat/services/elevenlabs.py b/src/pipecat/services/elevenlabs.py index a2e25cf8a..723e2f854 100644 --- a/src/pipecat/services/elevenlabs.py +++ b/src/pipecat/services/elevenlabs.py @@ -387,8 +387,8 @@ class ElevenLabsTTSService(WordTTSService): try: if not self._started: - await self.push_frame(TTSStartedFrame()) await self.start_ttfb_metrics() + yield TTSStartedFrame() self._started = True self._cumulative_time = 0 @@ -396,7 +396,7 @@ class ElevenLabsTTSService(WordTTSService): await self.start_tts_usage_metrics(text) except Exception as e: logger.error(f"{self} error sending message: {e}") - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() await self._disconnect() await self._connect() return diff --git a/src/pipecat/services/google.py b/src/pipecat/services/google.py index a02471040..a8187366a 100644 --- a/src/pipecat/services/google.py +++ b/src/pipecat/services/google.py @@ -361,7 +361,7 @@ class GoogleTTSService(TTSService): await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() # Skip the first 44 bytes to remove the WAV header audio_content = response.audio_content[44:] @@ -377,11 +377,11 @@ class GoogleTTSService(TTSService): yield frame await asyncio.sleep(0) # Allow other tasks to run - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() except Exception as e: logger.exception(f"{self} error generating TTS: {e}") error_message = f"TTS generation error: {str(e)}" yield ErrorFrame(error=error_message) finally: - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() diff --git a/src/pipecat/services/lmnt.py b/src/pipecat/services/lmnt.py index 1ea3f1e62..eea4fd9db 100644 --- a/src/pipecat/services/lmnt.py +++ b/src/pipecat/services/lmnt.py @@ -176,8 +176,8 @@ class LmntTTSService(TTSService): await self._connect() if not self._started: - await self.push_frame(TTSStartedFrame()) await self.start_ttfb_metrics() + yield TTSStartedFrame() self._started = True try: @@ -186,7 +186,7 @@ class LmntTTSService(TTSService): await self.start_tts_usage_metrics(text) except Exception as e: logger.error(f"{self} error sending message: {e}") - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() await self._disconnect() await self._connect() return diff --git a/src/pipecat/services/openai.py b/src/pipecat/services/openai.py index 24d673234..2f98a7e10 100644 --- a/src/pipecat/services/openai.py +++ b/src/pipecat/services/openai.py @@ -426,13 +426,13 @@ class OpenAITTSService(TTSService): await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() async for chunk in r.iter_bytes(8192): if len(chunk) > 0: await self.stop_ttfb_metrics() frame = TTSAudioRawFrame(chunk, self._settings["sample_rate"], 1) yield frame - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() except BadRequestError as e: logger.exception(f"{self} error generating TTS: {e}") diff --git a/src/pipecat/services/playht.py b/src/pipecat/services/playht.py index fe5feba3a..26c666d61 100644 --- a/src/pipecat/services/playht.py +++ b/src/pipecat/services/playht.py @@ -75,7 +75,7 @@ class PlayHTTTSService(TTSService): await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() async for chunk in playht_gen: # skip the RIFF header. if in_header: @@ -95,6 +95,6 @@ class PlayHTTTSService(TTSService): await self.stop_ttfb_metrics() frame = TTSAudioRawFrame(chunk, self._settings["sample_rate"], 1) yield frame - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame() except Exception as e: logger.exception(f"{self} error generating TTS: {e}") diff --git a/src/pipecat/services/xtts.py b/src/pipecat/services/xtts.py index eb20d5f3c..d3cea254a 100644 --- a/src/pipecat/services/xtts.py +++ b/src/pipecat/services/xtts.py @@ -151,7 +151,7 @@ class XTTSService(TTSService): await self.start_tts_usage_metrics(text) - await self.push_frame(TTSStartedFrame()) + yield TTSStartedFrame() buffer = bytearray() async for chunk in r.content.iter_chunked(1024): @@ -187,4 +187,4 @@ class XTTSService(TTSService): frame = TTSAudioRawFrame(resampled_audio_bytes, 16000, 1) yield frame - await self.push_frame(TTSStoppedFrame()) + yield TTSStoppedFrame()