export type SpeechRequest = {model: string, input: string, voice: 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer', response_format?: ('mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm') | undefined, instructions?: string | undefined, stream_format?: 'sse' | undefined}; export type CreateApiV1AudioSpeechArgs = {body: SpeechRequest}; export type CreateApiV1AudioSpeechOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create Speech (Text-to-Speech) * * POST /v1/audio/speech */ export const createApiV1AudioSpeech = async (args: CreateApiV1AudioSpeechArgs, options?: CreateApiV1AudioSpeechOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "audio/mpeg") 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() };