This commit is contained in:
James Hush
2024-11-27 19:38:37 +08:00
parent f34e6bce94
commit 1884ff3f09
3 changed files with 9 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
import asyncio import asyncio
import base64 import base64
import json import json
import random
import uuid import uuid
from typing import AsyncGenerator, List, Optional, Union from typing import AsyncGenerator, List, Optional, Union
@@ -222,6 +223,10 @@ class CartesiaTTSService(WordTTSService):
async def _receive_task_handler(self): async def _receive_task_handler(self):
try: try:
async for message in self._get_websocket(): async for message in self._get_websocket():
# Randomly cancel the asyncio task 1% of the time
if random.random() < 0.01:
logger.info(f"Cancelling task for {self} due to random chance")
asyncio.current_task().cancel()
msg = json.loads(message) msg = json.loads(message)
if not msg or msg["context_id"] != self._context_id: if not msg or msg["context_id"] != self._context_id:
continue continue
@@ -256,6 +261,7 @@ class CartesiaTTSService(WordTTSService):
logger.error(f"Cartesia error, unknown message type: {msg}") logger.error(f"Cartesia error, unknown message type: {msg}")
except asyncio.CancelledError: except asyncio.CancelledError:
pass pass
# await self.push_error(ErrorFrame(f"{self} cancelled", True))
except Exception as e: except Exception as e:
logger.error(f"{self} exception: {e}") logger.error(f"{self} exception: {e}")

View File

@@ -71,6 +71,7 @@ class BaseInputTransport(FrameProcessor):
return self._params.vad_analyzer return self._params.vad_analyzer
async def push_audio_frame(self, frame: InputAudioRawFrame): async def push_audio_frame(self, frame: InputAudioRawFrame):
logger.info(f"Pushing audio qsize: {self._audio_in_queue.qsize()}")
if self._params.audio_in_enabled or self._params.vad_enabled: if self._params.audio_in_enabled or self._params.vad_enabled:
await self._audio_in_queue.put(frame) await self._audio_in_queue.put(frame)
@@ -167,6 +168,7 @@ class BaseInputTransport(FrameProcessor):
return vad_state return vad_state
async def _audio_task_handler(self): async def _audio_task_handler(self):
logger.info("_audio_task_handler started")
vad_state: VADState = VADState.QUIET vad_state: VADState = VADState.QUIET
while True: while True:
try: try:

View File

@@ -106,6 +106,7 @@ class WebsocketServerInputTransport(BaseInputTransport):
continue continue
if isinstance(frame, AudioRawFrame): if isinstance(frame, AudioRawFrame):
logger.info("websocket_server")
await self.push_audio_frame( await self.push_audio_frame(
InputAudioRawFrame( InputAudioRawFrame(
audio=frame.audio, audio=frame.audio,