Merge pull request #465 from kunal-cai/ks--fix-ws

[Cartesia] Fix streaming truncation bug with Twilio Fast API WS
This commit is contained in:
Aleix Conchillo Flaqué
2024-09-16 17:17:13 -07:00
committed by GitHub
2 changed files with 20 additions and 1 deletions

View File

@@ -161,6 +161,25 @@ class CartesiaTTSService(AsyncWordTTSService):
await self.push_frame(LLMFullResponseEndFrame())
self._context_id = None
async def flush_audio(self):
if not self._context_id or not self._websocket:
return
logger.debug("Flushing audio")
msg = {
"transcript": "",
"continue": False,
"context_id": self._context_id,
"model_id": self._model_id,
"voice": {
"mode": "id",
"id": self._voice_id
},
"output_format": self._output_format,
"language": self._language,
"add_timestamps": True,
}
await self._websocket.send(json.dumps(msg))
async def _receive_task_handler(self):
try:
async for message in self._websocket:

View File

@@ -101,7 +101,7 @@ class FastAPIWebsocketOutputTransport(BaseOutputTransport):
async def write_raw_audio_frames(self, frames: bytes):
self._websocket_audio_buffer += frames
while len(self._websocket_audio_buffer) >= self._params.audio_frame_size:
while len(self._websocket_audio_buffer):
frame = AudioRawFrame(
audio=self._websocket_audio_buffer[:
self._params.audio_frame_size],