export type VoiceIdsOrCustomVoice = string | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse' | 'marin' | 'cedar' | {id: string}; export type CreateSpeechRequest = {model: string | 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | 'gpt-4o-mini-tts-2025-12-15', input: string, instructions?: string | undefined, voice: VoiceIdsOrCustomVoice, response_format?: ('mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm') | undefined, speed?: number | undefined, stream_format?: ('sse' | 'audio') | undefined}; export type CreateApiV1AudioSpeechArgs = {body: CreateSpeechRequest}; export type CreateApiV1AudioSpeechOptions = {baseUrl?: string | undefined, gatewayBearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * /v1/audio/speech * * POST /v1/audio/speech */ export const createApiV1AudioSpeech = async (args: CreateApiV1AudioSpeechArgs, options?: CreateApiV1AudioSpeechOptions) => { const {baseUrl = "https://aihubmix.com", fetch: fetchFn = fetch, gatewayBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/octet-stream") if (gatewayBearer !== undefined) headers.set('authorization', `Bearer ${gatewayBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/audio/speech${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };