comments re fixes
This commit is contained in:
@@ -156,7 +156,7 @@ class TTSService(AIService):
|
|||||||
async def say(self, text: str):
|
async def say(self, text: str):
|
||||||
await self.process_frame(TextFrame(text=text), FrameDirection.DOWNSTREAM)
|
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 = ""
|
self._current_sentence = ""
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ class TTSService(AIService):
|
|||||||
if isinstance(frame, TextFrame):
|
if isinstance(frame, TextFrame):
|
||||||
await self._process_text_frame(frame)
|
await self._process_text_frame(frame)
|
||||||
elif isinstance(frame, StartInterruptionFrame):
|
elif isinstance(frame, StartInterruptionFrame):
|
||||||
await self.handle_interruption(frame, direction)
|
await self._handle_interruption(frame, direction)
|
||||||
elif isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame):
|
elif isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame):
|
||||||
self._current_sentence = ""
|
self._current_sentence = ""
|
||||||
await self._push_tts_frames(self._current_sentence)
|
await self._push_tts_frames(self._current_sentence)
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ class CartesiaTTSService(TTSService):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
api_key: str,
|
api_key: str,
|
||||||
|
voice_id: str,
|
||||||
cartesia_version: str = "2024-06-10",
|
cartesia_version: str = "2024-06-10",
|
||||||
url: str = "wss://api.cartesia.ai/tts/websocket",
|
url: str = "wss://api.cartesia.ai/tts/websocket",
|
||||||
voice_id: str,
|
|
||||||
model_id: str = "sonic-english",
|
model_id: str = "sonic-english",
|
||||||
encoding: str = "pcm_s16le",
|
encoding: str = "pcm_s16le",
|
||||||
sample_rate: int = 16000,
|
sample_rate: int = 16000,
|
||||||
@@ -89,14 +89,13 @@ class CartesiaTTSService(TTSService):
|
|||||||
|
|
||||||
async def start(self, frame: StartFrame):
|
async def start(self, frame: StartFrame):
|
||||||
await super().start(frame)
|
await super().start(frame)
|
||||||
await self.connect()
|
await self._connect()
|
||||||
|
|
||||||
async def stop(self, frame: EndFrame):
|
async def stop(self, frame: EndFrame):
|
||||||
await super().stop(frame)
|
await super().stop(frame)
|
||||||
await self.disconnect()
|
await self._disconnect()
|
||||||
pass
|
|
||||||
|
|
||||||
async def connect(self):
|
async def _connect(self):
|
||||||
try:
|
try:
|
||||||
self._websocket = await websockets.connect(
|
self._websocket = await websockets.connect(
|
||||||
f"{self._url}?api_key={self._api_key}&cartesia_version={self._cartesia_version}"
|
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
|
# 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
|
# playing out audio and need the timestamp to set send context frames
|
||||||
self._context_id = None
|
self._context_id = None
|
||||||
self._timestamped_words_buffer.append(["LLMFullResponseEndFrame", 0])
|
self._timestamped_words_buffer.append(("LLMFullResponseEndFrame", 0))
|
||||||
if msg["type"] == "timestamps":
|
elif msg["type"] == "timestamps":
|
||||||
# logger.debug(f"TIMESTAMPS: {msg}")
|
# logger.debug(f"TIMESTAMPS: {msg}")
|
||||||
self._timestamped_words_buffer.extend(
|
self._timestamped_words_buffer.extend(
|
||||||
list(zip(msg["word_timestamps"]["words"], msg["word_timestamps"]["end"]))
|
list(zip(msg["word_timestamps"]["words"], msg["word_timestamps"]["end"]))
|
||||||
)
|
)
|
||||||
continue
|
elif msg["type"] == "chunk":
|
||||||
if msg["type"] == "chunk":
|
|
||||||
if not self._context_id_start_timestamp:
|
if not self._context_id_start_timestamp:
|
||||||
self._context_id_start_timestamp = time.time()
|
self._context_id_start_timestamp = time.time()
|
||||||
if self._waiting_for_ttfb:
|
if self._waiting_for_ttfb:
|
||||||
@@ -192,7 +190,7 @@ class CartesiaTTSService(TTSService):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if not self._websocket:
|
if not self._websocket:
|
||||||
await self.connect()
|
await self._connect()
|
||||||
|
|
||||||
if not self._waiting_for_ttfb:
|
if not self._waiting_for_ttfb:
|
||||||
await self.start_ttfb_metrics()
|
await self.start_ttfb_metrics()
|
||||||
@@ -219,8 +217,8 @@ class CartesiaTTSService(TTSService):
|
|||||||
await self._websocket.send(json.dumps(msg))
|
await self._websocket.send(json.dumps(msg))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"{self} error sending message: {e}")
|
logger.exception(f"{self} error sending message: {e}")
|
||||||
await self.disconnect()
|
await self._disconnect()
|
||||||
await self.connect()
|
await self._connect()
|
||||||
return
|
return
|
||||||
yield None
|
yield None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user