export type GetApiV1TextToVoiceGeneratedVoiceIdStreamArgs = {generated_voice_id: string, 'xi-api-key'?: (string | null) | undefined}; export type GetApiV1TextToVoiceGeneratedVoiceIdStreamOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Text To Voice Preview Streaming * * GET /v1/text-to-voice/{generated_voice_id}/stream */ export const getApiV1TextToVoiceGeneratedVoiceIdStream = async (args: GetApiV1TextToVoiceGeneratedVoiceIdStreamArgs, options: GetApiV1TextToVoiceGeneratedVoiceIdStreamOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "audio/mpeg") if (args['xi-api-key'] != null) headers.set("xi-api-key", String(args['xi-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/text-to-voice/${encodeURIComponent(String(args.generated_voice_id))}/stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };