export type SpeechModel = {model: string, input: string, voice: string, speed?: (number | null) | undefined, instructions?: (string | null) | undefined, response_format?: ('mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm' | null) | undefined}; export type CreateApiV1AudioSpeechArgs = {body: SpeechModel}; export type CreateApiV1AudioSpeechOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create speech * * POST /v1/audio/speech * * Also accepts auth: xApiKeyAuth */ export const createApiV1AudioSpeech = async (args: CreateApiV1AudioSpeechArgs, options?: CreateApiV1AudioSpeechOptions) => { const {baseUrl = "https://api.naga.ac", 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(/\/+$/, '')}/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() };