Skip to content

Commit 15067c6

Browse files
author
Ashot
committed
adapt Async TTS to updated AudioContextTTSService
1 parent 5ae592f commit 15067c6

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

  • src/pipecat/services/asyncai

src/pipecat/services/asyncai/tts.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
TTSStoppedFrame,
2929
)
3030
from pipecat.processors.frame_processor import FrameDirection
31-
from pipecat.services.tts_service import AudioContextTTSService, WebsocketTTSService, TTSService
31+
from pipecat.services.tts_service import AudioContextTTSService, TTSService
3232
from pipecat.transcriptions.language import Language, resolve_language
3333
from pipecat.utils.tracing.service_decorators import traced_tts
3434

@@ -73,7 +73,7 @@ def language_to_async_language(language: Language) -> Optional[str]:
7373
return resolve_language(language, LANGUAGE_MAP, use_base_code=True)
7474

7575

76-
class AsyncAITTSService(AudioContextTTSService, WebsocketTTSService):
76+
class AsyncAITTSService(AudioContextTTSService):
7777
"""Async TTS service with WebSocket streaming.
7878
7979
Provides text-to-speech using Async's streaming WebSocket API.
@@ -153,7 +153,7 @@ def __init__(
153153
self._receive_task = None
154154
self._keepalive_task = None
155155
self._started = False
156-
156+
157157
async def start(self, frame: StartFrame):
158158
"""Start the Async TTS service.
159159
@@ -337,7 +337,10 @@ async def _keepalive_task_handler(self):
337337
try:
338338
if self._websocket and self._websocket.state is State.OPEN:
339339
if self._context_id:
340-
keepalive_message = {"transcript": " ", "context_id": self._context_id,}
340+
keepalive_message = {
341+
"transcript": " ",
342+
"context_id": self._context_id,
343+
}
341344
logger.trace("Sending keepalive message")
342345
else:
343346
# It's possible to have a user interruption which clears the context
@@ -358,7 +361,9 @@ async def _handle_interruption(self, frame: InterruptionFrame, direction: FrameD
358361
if self._context_id and self._websocket:
359362
try:
360363
await self._websocket.send(
361-
json.dumps({"context_id": self._context_id, "close_context": True, "transcript": ""})
364+
json.dumps(
365+
{"context_id": self._context_id, "close_context": True, "transcript": ""}
366+
)
362367
)
363368
except Exception as e:
364369
logger.error(f"Error closing context on interruption: {e}")
@@ -381,7 +386,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
381386
if not self._websocket or self._websocket.state is State.CLOSED:
382387
await self._connect()
383388

384-
try:
389+
try:
385390
if not self._started:
386391
await self.start_ttfb_metrics()
387392
yield TTSStartedFrame()
@@ -401,15 +406,16 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
401406
if self._websocket and self._context_id:
402407
msg = self._build_msg(text=text, force=True, context_id=self._context_id)
403408
await self._get_websocket().send(msg)
404-
409+
405410
except Exception as e:
406411
logger.error(f"{self} error sending message: {e}")
407412
yield TTSStoppedFrame()
408413
self._started = False
409414
return
410415
yield None
411416
except Exception as e:
412-
logger.error(f"{self} exception: {e}")
417+
logger.error(f"{self} exception: {e}")
418+
413419

414420
class AsyncAIHttpTTSService(TTSService):
415421
"""HTTP-based Async TTS service.

0 commit comments

Comments
 (0)