All files / web/src/lib/audio voices.ts

0% Statements 0/59
0% Branches 0/1
0% Functions 0/1
0% Lines 0/59

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                                                                                       
export interface VoiceProviderConfig {
  id: string
  name: string
  models: VoiceModelConfig[]
}

export interface VoiceModelConfig {
  id: string
  name: string
  /** File format clips are persisted as, e.g. "mp3". Omit for non-persisted sources. */
  format: string
  voices: readonly string[]
}

export const VOICE_PROVIDERS: readonly VoiceProviderConfig[] = [
  {
    id: 'openai',
    name: 'OpenAI',
    models: [
      {
        id: 'tts-1',
        name: 'tts-1',
        format: 'mp3',
        voices: [
          'alloy',
          'ash',
          'ballad',
          'coral',
          'echo',
          'fable',
          'nova',
          'onyx',
          'sage',
          'shimmer',
        ],
      },
    ],
  },
] as const

/** Flat list of all voice names across all providers/models */
export const ALL_VOICES = VOICE_PROVIDERS.flatMap((p) => p.models.flatMap((m) => m.voices))

export type VoiceName = (typeof ALL_VOICES)[number]

/** Look up provider + model metadata for a voice name */
export function getVoiceMeta(voiceName: string): {
  provider: VoiceProviderConfig
  model: VoiceModelConfig
} | null {
  for (const provider of VOICE_PROVIDERS) {
    for (const model of provider.models) {
      if (model.voices.includes(voiceName)) {
        return { provider, model }
      }
    }
  }
  return null
}