@@ -10,6 +10,7 @@ import {
1010 tts ,
1111} from '@livekit/agents' ;
1212import { Mistral } from '@mistralai/mistralai' ;
13+ import * as crypto from 'node:crypto' ;
1314import type { MistralTTSModels } from './models.js' ;
1415
1516// Confirmed from WAV header: Mistral TTS PCM output is 24000 Hz, mono, 16-bit signed
@@ -135,7 +136,8 @@ export class ChunkedStream extends tts.ChunkedStream {
135136 stream : true ,
136137 } ) ;
137138
138- const requestId = this . #text. slice ( 0 , 8 ) ;
139+ const requestId = crypto . randomUUID ( ) ;
140+ const segmentId = crypto . randomUUID ( ) ;
139141 const audioByteStream = new AudioByteStream ( MISTRAL_TTS_SAMPLE_RATE , MISTRAL_TTS_CHANNELS ) ;
140142
141143 let lastFrame : import ( '@livekit/rtc-node' ) . AudioFrame | undefined ;
@@ -152,7 +154,7 @@ export class ChunkedStream extends tts.ChunkedStream {
152154 const pcmBytes = Buffer . from ( event . data . audioData , 'base64' ) ;
153155 const frames = audioByteStream . write ( pcmBytes ) ;
154156 for ( const frame of frames ) {
155- sendLastFrame ( requestId , false ) ;
157+ sendLastFrame ( segmentId , false ) ;
156158 lastFrame = frame ;
157159 }
158160 } else if ( event . data . type === 'speech.audio.done' ) {
@@ -163,11 +165,11 @@ export class ChunkedStream extends tts.ChunkedStream {
163165 // Flush any remaining buffered audio
164166 const flushFrames = audioByteStream . flush ( ) ;
165167 for ( const frame of flushFrames ) {
166- sendLastFrame ( requestId , false ) ;
168+ sendLastFrame ( segmentId , false ) ;
167169 lastFrame = frame ;
168170 }
169171
170- sendLastFrame ( requestId , true ) ;
172+ sendLastFrame ( segmentId , true ) ;
171173 this . queue . close ( ) ;
172174 } catch ( error : unknown ) {
173175 if ( this . abortController ?. signal . aborted ) return ;
0 commit comments