diff --git a/src/pipecat/services/ai_services.py b/src/pipecat/services/ai_services.py index 27c8edbe5..8647d3f77 100644 --- a/src/pipecat/services/ai_services.py +++ b/src/pipecat/services/ai_services.py @@ -156,7 +156,7 @@ class TTSService(AIService): async def say(self, text: str): await self.process_frame(TextFrame(text=text), FrameDirection.DOWNSTREAM) - async def handle_interruption(self, frame: StartInterruptionFrame, direction: FrameDirection): + async def _handle_interruption(self, frame: StartInterruptionFrame, direction: FrameDirection): self._current_sentence = "" await self.push_frame(frame, direction) @@ -194,7 +194,7 @@ class TTSService(AIService): if isinstance(frame, TextFrame): await self._process_text_frame(frame) elif isinstance(frame, StartInterruptionFrame): - await self.handle_interruption(frame, direction) + await self._handle_interruption(frame, direction) elif isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame): self._current_sentence = "" await self._push_tts_frames(self._current_sentence) diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index b8a7145f3..ade1e8ab4 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -42,9 +42,9 @@ class CartesiaTTSService(TTSService): self, *, api_key: str, + voice_id: str, cartesia_version: str = "2024-06-10", url: str = "wss://api.cartesia.ai/tts/websocket", - voice_id: str, model_id: str = "sonic-english", encoding: str = "pcm_s16le", sample_rate: int = 16000, @@ -89,14 +89,13 @@ class CartesiaTTSService(TTSService): async def start(self, frame: StartFrame): await super().start(frame) - await self.connect() + await self._connect() async def stop(self, frame: EndFrame): await super().stop(frame) - await self.disconnect() - pass + await self._disconnect() - async def connect(self): + async def _connect(self): try: self._websocket = await websockets.connect( f"{self._url}?api_key={self._api_key}&cartesia_version={self._cartesia_version}" @@ -146,14 +145,13 @@ class CartesiaTTSService(TTSService): # unset _context_id but not the _context_id_start_timestamp because we are likely still # playing out audio and need the timestamp to set send context frames self._context_id = None - self._timestamped_words_buffer.append(["LLMFullResponseEndFrame", 0]) - if msg["type"] == "timestamps": + self._timestamped_words_buffer.append(("LLMFullResponseEndFrame", 0)) + elif msg["type"] == "timestamps": # logger.debug(f"TIMESTAMPS: {msg}") self._timestamped_words_buffer.extend( list(zip(msg["word_timestamps"]["words"], msg["word_timestamps"]["end"])) ) - continue - if msg["type"] == "chunk": + elif msg["type"] == "chunk": if not self._context_id_start_timestamp: self._context_id_start_timestamp = time.time() if self._waiting_for_ttfb: @@ -192,7 +190,7 @@ class CartesiaTTSService(TTSService): try: if not self._websocket: - await self.connect() + await self._connect() if not self._waiting_for_ttfb: await self.start_ttfb_metrics() @@ -219,8 +217,8 @@ class CartesiaTTSService(TTSService): await self._websocket.send(json.dumps(msg)) except Exception as e: logger.exception(f"{self} error sending message: {e}") - await self.disconnect() - await self.connect() + await self._disconnect() + await self._connect() return yield None except Exception as e: