Skip to content

Commit 456cd59

Browse files
committed
feat(mistral): implement Mistral TTS plugin and STT configs
1 parent 1dd25ee commit 456cd59

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

plugins/mistral/src/models.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export type MistralChatModels =
1616

1717
export type MistralSTTModels =
1818
| 'voxtral-mini-transcribe-realtime-2602' //realtime streaming
19-
| 'voxtral-small-latest' //chat completions
20-
| 'voxtral-mini-latest' //chat completions
21-
| 'voxtral-mini-transcribe'; //chat completions
19+
| 'voxtral-mini-2602' //batch transcription
20+
| 'voxtral-mini-transcribe-2507'; //batch transcription (deprecated)
2221

2322
export type MistralTTSModels = 'voxtral-mini-tts-2603';

plugins/mistral/src/stt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export class SpeechStream extends stt.SpeechStream {
386386
stopRequested = true;
387387
resolveAbortTask();
388388
if (connection) {
389-
await connection.close();
389+
await connection.close().catch(() => {});
390390
}
391391
if (sendAudioTask) {
392392
await sendAudioTask;

plugins/mistral/src/tts.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)