From d9c900f872a44e9f7e4583f1131d353bfdf127a7 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Sat, 12 Oct 2024 21:27:37 -0400 Subject: [PATCH] Satisfy minimal text requirements for Cartesia and OpenAI --- src/pipecat/services/cartesia.py | 4 ++-- src/pipecat/services/openai.py | 2 +- src/pipecat/utils/text/markdown_text_filter.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index 5166a3df8..c0e4a89a2 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -152,7 +152,7 @@ class CartesiaTTSService(WordTTSService): voice_config["__experimental_controls"]["emotion"] = self._settings["emotion"] msg = { - "transcript": text, + "transcript": text or " ", # Text must contain at least one character "continue": continue_transcript, "context_id": self._context_id, "model_id": self.model_name, @@ -271,7 +271,7 @@ class CartesiaTTSService(WordTTSService): yield TTSStartedFrame() self._context_id = str(uuid.uuid4()) - msg = self._build_msg(text=text) + msg = self._build_msg(text=text or " ") # Text must contain at least one character try: await self._get_websocket().send(msg) diff --git a/src/pipecat/services/openai.py b/src/pipecat/services/openai.py index 2f98a7e10..f530d924b 100644 --- a/src/pipecat/services/openai.py +++ b/src/pipecat/services/openai.py @@ -409,7 +409,7 @@ class OpenAITTSService(TTSService): await self.start_ttfb_metrics() async with self._client.audio.speech.with_streaming_response.create( - input=text, + input=text or " ", # Text must contain at least one character model=self.model_name, voice=VALID_VOICES[self._voice_id], response_format="pcm", diff --git a/src/pipecat/utils/text/markdown_text_filter.py b/src/pipecat/utils/text/markdown_text_filter.py index d7203e6e7..d91922e32 100644 --- a/src/pipecat/utils/text/markdown_text_filter.py +++ b/src/pipecat/utils/text/markdown_text_filter.py @@ -96,7 +96,7 @@ class MarkdownTextFilter(BaseTextFilter): # Restore leading and trailing spaces filtered_text = re.sub("ยง", " ", filtered_text) - return filtered_text or " " # Return a space to satisfy TTS services + return filtered_text else: return text