Skip to content

Commit 5292105

Browse files
committed
feat(openai): implement close() cleanup for STT
1 parent 97d066f commit 5292105

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

plugins/openai/src/stt.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class STT extends stt.STT {
2727
#opts: STTOptions;
2828
#client: OpenAI;
2929
label = 'openai.STT';
30+
private abortController = new AbortController();
3031

3132
/**
3233
* Create a new instance of OpenAI STT.
@@ -145,13 +146,19 @@ export class STT extends stt.STT {
145146
const config = this.#sanitizeOptions(language);
146147
buffer = mergeFrames(buffer);
147148
const file = new File([this.#createWav(buffer)], 'audio.wav', { type: 'audio/wav' });
148-
const resp = await this.#client.audio.transcriptions.create({
149-
file,
150-
model: this.#opts.model,
151-
language: config.language,
152-
prompt: config.prompt,
153-
response_format: 'json',
154-
});
149+
150+
const resp = await this.#client.audio.transcriptions.create(
151+
{
152+
file,
153+
model: this.#opts.model,
154+
language: config.language,
155+
prompt: config.prompt,
156+
response_format: 'json',
157+
},
158+
{
159+
signal: this.abortController.signal,
160+
},
161+
);
155162

156163
return {
157164
type: stt.SpeechEventType.FINAL_TRANSCRIPT,
@@ -171,4 +178,8 @@ export class STT extends stt.STT {
171178
stream(): stt.SpeechStream {
172179
throw new Error('Streaming is not supported on OpenAI STT');
173180
}
181+
182+
async close(): Promise<void> {
183+
this.abortController.abort();
184+
}
174185
}

0 commit comments

Comments
 (0)