audioMimeFromFormat (tts/audio-format.ts)

airi · server/apps/api/src/services/adapters/tts/audio-format.ts · typescript · MIT
voice, tag:knn-classified

Maps TTS audio format keys to MIME types for HTTP responses.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
const AUDIO_MIME_TYPES: Record<string, string> = {
  flac: 'audio/flac',
  mp3: 'audio/mpeg',
  ogg_opus: 'audio/ogg',
  opus: 'audio/opus',
  pcm: 'audio/L16',
  wav: 'audio/wav',
}

/**
 * Maps provider audio format keys to response MIME types.
 *
 * Use when:
 * - A TTS adapter forwards OpenAI-shaped `response_format` / provider
 *   encoding keys through unspeech and needs a gateway fallback MIME type.
 *
 * Expects:
 * - `format` is the exact provider/OpenAI format key.
 *
 * Returns:
 * - A known audio MIME type, or `application/octet-stream` for unknown custom
 *   formats so operators can still experiment through config.
 */

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key