export type OpenAISpeechRequest = {model: string, input: string, voice?: ('alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer') | undefined, response_format?: ('mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm') | undefined, speed?: number | undefined, stream_format?: 'sse' | undefined, fallbacks?: Array | undefined}; export type CreateApiOpenaiV1AudioSpeechArgs = {body: OpenAISpeechRequest}; export type CreateApiOpenaiV1AudioSpeechOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create speech (OpenAI TTS) * * POST /openai/v1/audio/speech * * Also accepts auth: BasicAuth, VirtualKeyAuth, ApiKeyAuth */ export const createApiOpenaiV1AudioSpeech = async (args: CreateApiOpenaiV1AudioSpeechArgs, options?: CreateApiOpenaiV1AudioSpeechOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "audio/mpeg") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/openai/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() };