feat: Add WAV MIME type variants and improve audio format detection (#23396)
This commit is contained in:
@@ -183,6 +183,10 @@ export enum MimeTypeAudio {
|
|||||||
MP3 = 'audio/mp3',
|
MP3 = 'audio/mp3',
|
||||||
MP4 = 'audio/mp4',
|
MP4 = 'audio/mp4',
|
||||||
WAV = 'audio/wav',
|
WAV = 'audio/wav',
|
||||||
|
WAVE = 'audio/wave',
|
||||||
|
X_WAV = 'audio/x-wav',
|
||||||
|
X_WAVE = 'audio/x-wave',
|
||||||
|
X_PN_WAV = 'audio/x-pn-wav',
|
||||||
WEBM = 'audio/webm',
|
WEBM = 'audio/webm',
|
||||||
WEBM_OPUS = 'audio/webm;codecs=opus'
|
WEBM_OPUS = 'audio/webm;codecs=opus'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
AttachmentType,
|
AttachmentType,
|
||||||
ContentPartType,
|
ContentPartType,
|
||||||
|
FileTypeAudio,
|
||||||
MessageRole,
|
MessageRole,
|
||||||
|
MimeTypeAudio,
|
||||||
ReasoningFormat,
|
ReasoningFormat,
|
||||||
UrlProtocol
|
UrlProtocol
|
||||||
} from '$lib/enums';
|
} from '$lib/enums';
|
||||||
@@ -19,9 +21,29 @@ import type {
|
|||||||
ApiChatMessageData,
|
ApiChatMessageData,
|
||||||
ApiChatCompletionToolCall
|
ApiChatCompletionToolCall
|
||||||
} from '$lib/types/api';
|
} from '$lib/types/api';
|
||||||
import type { DatabaseMessageExtraMcpPrompt, DatabaseMessageExtraMcpResource } from '$lib/types';
|
import type {
|
||||||
|
AudioInputFormat,
|
||||||
|
DatabaseMessageExtraMcpPrompt,
|
||||||
|
DatabaseMessageExtraMcpResource
|
||||||
|
} from '$lib/types';
|
||||||
import { modelsStore } from '$lib/stores/models.svelte';
|
import { modelsStore } from '$lib/stores/models.svelte';
|
||||||
|
|
||||||
|
function getAudioInputFormat(mimeType: string): AudioInputFormat {
|
||||||
|
const normalizedMimeType = mimeType.trim().toLowerCase();
|
||||||
|
|
||||||
|
if (
|
||||||
|
normalizedMimeType === MimeTypeAudio.WAV ||
|
||||||
|
normalizedMimeType === MimeTypeAudio.WAVE ||
|
||||||
|
normalizedMimeType === MimeTypeAudio.X_WAV ||
|
||||||
|
normalizedMimeType === MimeTypeAudio.X_WAVE ||
|
||||||
|
normalizedMimeType === MimeTypeAudio.X_PN_WAV
|
||||||
|
) {
|
||||||
|
return FileTypeAudio.WAV;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FileTypeAudio.MP3;
|
||||||
|
}
|
||||||
|
|
||||||
export class ChatService {
|
export class ChatService {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -879,7 +901,7 @@ export class ChatService {
|
|||||||
type: ContentPartType.INPUT_AUDIO,
|
type: ContentPartType.INPUT_AUDIO,
|
||||||
input_audio: {
|
input_audio: {
|
||||||
data: audio.base64Data,
|
data: audio.base64Data,
|
||||||
format: audio.mimeType.includes('wav') ? 'wav' : 'mp3'
|
format: getAudioInputFormat(audio.mimeType)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-2
@@ -1,6 +1,8 @@
|
|||||||
import type { ContentPartType, ServerModelStatus, ServerRole } from '$lib/enums';
|
import type { ContentPartType, FileTypeAudio, ServerModelStatus, ServerRole } from '$lib/enums';
|
||||||
import type { ChatMessagePromptProgress, ChatRole } from './chat';
|
import type { ChatMessagePromptProgress, ChatRole } from './chat';
|
||||||
|
|
||||||
|
export type AudioInputFormat = FileTypeAudio.WAV | FileTypeAudio.MP3;
|
||||||
|
|
||||||
export interface ApiChatCompletionToolFunction {
|
export interface ApiChatCompletionToolFunction {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
@@ -20,7 +22,7 @@ export interface ApiChatMessageContentPart {
|
|||||||
};
|
};
|
||||||
input_audio?: {
|
input_audio?: {
|
||||||
data: string;
|
data: string;
|
||||||
format: 'wav' | 'mp3';
|
format: AudioInputFormat;
|
||||||
};
|
};
|
||||||
input_video?: {
|
input_video?: {
|
||||||
data: string;
|
data: string;
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ export type {
|
|||||||
ApiRouterModelsStatusResponse,
|
ApiRouterModelsStatusResponse,
|
||||||
ApiRouterModelsListResponse,
|
ApiRouterModelsListResponse,
|
||||||
ApiRouterModelsUnloadRequest,
|
ApiRouterModelsUnloadRequest,
|
||||||
ApiRouterModelsUnloadResponse
|
ApiRouterModelsUnloadResponse,
|
||||||
|
AudioInputFormat
|
||||||
} from './api';
|
} from './api';
|
||||||
|
|
||||||
// Chat types
|
// Chat types
|
||||||
|
|||||||
@@ -18,8 +18,12 @@ import {
|
|||||||
MimeTypeText
|
MimeTypeText
|
||||||
} from '$lib/enums';
|
} from '$lib/enums';
|
||||||
|
|
||||||
|
function normalizeMimeType(mimeType: string): string {
|
||||||
|
return mimeType.trim().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
export function getFileTypeCategory(mimeType: string): FileTypeCategory | null {
|
export function getFileTypeCategory(mimeType: string): FileTypeCategory | null {
|
||||||
switch (mimeType) {
|
switch (normalizeMimeType(mimeType)) {
|
||||||
// Images
|
// Images
|
||||||
case MimeTypeImage.JPEG:
|
case MimeTypeImage.JPEG:
|
||||||
case MimeTypeImage.PNG:
|
case MimeTypeImage.PNG:
|
||||||
@@ -33,6 +37,10 @@ export function getFileTypeCategory(mimeType: string): FileTypeCategory | null {
|
|||||||
case MimeTypeAudio.MP3:
|
case MimeTypeAudio.MP3:
|
||||||
case MimeTypeAudio.MP4:
|
case MimeTypeAudio.MP4:
|
||||||
case MimeTypeAudio.WAV:
|
case MimeTypeAudio.WAV:
|
||||||
|
case MimeTypeAudio.WAVE:
|
||||||
|
case MimeTypeAudio.X_WAV:
|
||||||
|
case MimeTypeAudio.X_WAVE:
|
||||||
|
case MimeTypeAudio.X_PN_WAV:
|
||||||
case MimeTypeAudio.WEBM:
|
case MimeTypeAudio.WEBM:
|
||||||
case MimeTypeAudio.WEBM_OPUS:
|
case MimeTypeAudio.WEBM_OPUS:
|
||||||
return FileTypeCategory.AUDIO;
|
return FileTypeCategory.AUDIO;
|
||||||
|
|||||||
Reference in New Issue
Block a user