@@ -93,8 +93,12 @@ export class TTS extends tts.TTS {
9393 } ) ) ;
9494 }
9595
96- synthesize ( text : string , connOptions ?: APIConnectOptions ) : ChunkedStream {
97- return new ChunkedStream ( this , text , this . #client, this . #opts, connOptions ) ;
96+ synthesize (
97+ text : string ,
98+ connOptions ?: APIConnectOptions ,
99+ abortSignal ?: AbortSignal ,
100+ ) : ChunkedStream {
101+ return new ChunkedStream ( this , text , this . #client, this . #opts, connOptions , abortSignal ) ;
98102 }
99103
100104 stream ( ) : tts . SynthesizeStream {
@@ -118,8 +122,9 @@ export class ChunkedStream extends tts.ChunkedStream {
118122 client : Mistral ,
119123 opts : TTSOptions ,
120124 connOptions ?: APIConnectOptions ,
125+ abortSignal ?: AbortSignal ,
121126 ) {
122- super ( text , ttsInstance , connOptions ) ;
127+ super ( text , ttsInstance , connOptions , abortSignal ) ;
123128 this . #client = client ;
124129 this . #opts = opts ;
125130 this . #text = text ;
@@ -128,13 +133,18 @@ export class ChunkedStream extends tts.ChunkedStream {
128133 protected async run ( ) : Promise < void > {
129134 const logger = log ( ) ;
130135 try {
131- const eventStream = await this . #client. audio . speech . complete ( {
132- input : this . #text,
133- model : this . #opts. model ?? 'voxtral-mini-tts-2603' ,
134- voiceId : this . #opts. voiceId ,
135- responseFormat : 'pcm' ,
136- stream : true ,
137- } ) ;
136+ const eventStream = await this . #client. audio . speech . complete (
137+ {
138+ input : this . #text,
139+ model : this . #opts. model ?? 'voxtral-mini-tts-2603' ,
140+ voiceId : this . #opts. voiceId ,
141+ responseFormat : 'pcm' ,
142+ stream : true ,
143+ } ,
144+ {
145+ fetchOptions : { signal : this . abortController ?. signal } ,
146+ } ,
147+ ) ;
138148
139149 const requestId = crypto . randomUUID ( ) ;
140150 const segmentId = crypto . randomUUID ( ) ;
@@ -206,8 +216,6 @@ export class ChunkedStream extends tts.ChunkedStream {
206216 message : `Mistral TTS: ${ err . message ?? 'unknown error' } ` ,
207217 options : { retryable : true } ,
208218 } ) ;
209- } finally {
210- this . queue . close ( ) ;
211219 }
212220 }
213221}
0 commit comments