Skip to content

fix: dynamically add file extension for transcription workflow. #3367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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