From 8866ab1585e257d8f880b71bd46b0ad4091e98ab Mon Sep 17 00:00:00 2001 From: filipi87 Date: Thu, 12 Feb 2026 15:53:38 -0300 Subject: [PATCH] Fixing RimeTTSService to reuse the same context when needed. --- src/pipecat/services/rime/tts.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pipecat/services/rime/tts.py b/src/pipecat/services/rime/tts.py index e38e840e6..22f1cf4e1 100644 --- a/src/pipecat/services/rime/tts.py +++ b/src/pipecat/services/rime/tts.py @@ -12,6 +12,7 @@ using Rime's API for streaming and batch audio synthesis. import base64 import json +import uuid from typing import Any, AsyncGenerator, Mapping, Optional import aiohttp @@ -369,6 +370,20 @@ class RimeTTSService(AudioContextWordTTSService): return word_pairs + def create_context_id(self) -> str: + """Generate a unique context ID for a TTS request in case we don't have one already in progress. + + Returns: + A unique string identifier for the TTS context. + """ + # If a context ID does not exist, create a new one. + # If an ID exists, continue using the current ID. + # When interruptions happen, user speech results in + # an interruption, which resets the context ID. + if not self._context_id: + return str(uuid.uuid4()) + return self._context_id + async def flush_audio(self): """Flush any pending audio synthesis.""" if not self._context_id or not self._websocket: