Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions js/plugins/compat-oai/src/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down