From 57928b9deff0442e90622228823ed1cf3c614cdd Mon Sep 17 00:00:00 2001 From: nsrCodes Date: Mon, 4 Aug 2025 01:49:08 +0530 Subject: [PATCH] fix: dynamically add file extension. Required for whipser API --- js/plugins/compat-oai/src/audio.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/plugins/compat-oai/src/audio.ts b/js/plugins/compat-oai/src/audio.ts index 9113856fd0..e89e3943be 100644 --- a/js/plugins/compat-oai/src/audio.ts +++ b/js/plugins/compat-oai/src/audio.ts @@ -231,6 +231,17 @@ export function compatOaiSpeechModelRef< }); } +export const FILE_TYPE_TO_FILE_NAME_EXTENSION = { + 'audio/flac': '.flac', + 'audio/mp4': '.mp4', + 'audio/mpeg': '.mp3', + 'audio/mpga': '.mpga', + 'audio/oga': '.oga', + 'audio/wav': '.wav', + 'audio/webm': '.webm', + 'audio/ogg': '.ogg', +}; + function toSttRequest( modelName: string, request: GenerateRequest, @@ -245,11 +256,9 @@ function toSttRequest( media.url.slice(media.url.indexOf(',') + 1), 'base64' ); - const mediaFile = new File([mediaBuffer], 'input', { - type: - media.contentType ?? - media.url.slice('data:'.length, media.url.indexOf(';')), - }); + const contentType = media.contentType ?? media.url.slice('data:'.length, media.url.indexOf(';')); + const extension = FILE_TYPE_TO_FILE_NAME_EXTENSION[contentType] || ''; + const mediaFile = new File([mediaBuffer], `input${extension}`, {type: contentType}); const { temperature, version: modelVersion,