From 63146d6f85517f15dc699d6562fe6b1f62db49ab Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Thu, 3 Apr 2025 16:15:58 -0400 Subject: [PATCH] TTS: Skip generation when there is no text --- src/pipecat/services/cartesia/tts.py | 4 ++-- src/pipecat/services/openai/tts.py | 2 +- src/pipecat/services/tts_service.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pipecat/services/cartesia/tts.py b/src/pipecat/services/cartesia/tts.py index aaa8560fe..a4d0c3fa4 100644 --- a/src/pipecat/services/cartesia/tts.py +++ b/src/pipecat/services/cartesia/tts.py @@ -158,7 +158,7 @@ class CartesiaTTSService(AudioContextWordTTSService): voice_config["__experimental_controls"]["emotion"] = self._settings["emotion"] msg = { - "transcript": text or " ", # Text must contain at least one character + "transcript": text, "continue": continue_transcript, "context_id": self._context_id, "model_id": self.model_name, @@ -287,7 +287,7 @@ class CartesiaTTSService(AudioContextWordTTSService): self._context_id = str(uuid.uuid4()) await self.create_audio_context(self._context_id) - msg = self._build_msg(text=text or " ") # Text must contain at least one character + msg = self._build_msg(text=text) try: await self._get_websocket().send(msg) diff --git a/src/pipecat/services/openai/tts.py b/src/pipecat/services/openai/tts.py index af2bdfdfa..01a8fb7d8 100644 --- a/src/pipecat/services/openai/tts.py +++ b/src/pipecat/services/openai/tts.py @@ -105,7 +105,7 @@ class OpenAITTSService(TTSService): extra_body["instructions"] = self._instructions async with self._client.audio.speech.with_streaming_response.create( - input=text or " ", # Text must contain at least one character + input=text, model=self.model_name, voice=VALID_VOICES[self._voice_id], response_format="pcm", diff --git a/src/pipecat/services/tts_service.py b/src/pipecat/services/tts_service.py index 344ba9704..1da3c6814 100644 --- a/src/pipecat/services/tts_service.py +++ b/src/pipecat/services/tts_service.py @@ -269,7 +269,8 @@ class TTSService(AIService): filter.reset_interruption() text = filter.filter(text) - await self.process_generator(self.run_tts(text)) + if text: + await self.process_generator(self.run_tts(text)) await self.stop_processing_metrics()