export type VoiceSettingsResponseModel = {stability?: (number | null) | undefined, use_speaker_boost?: (boolean | null) | undefined, similarity_boost?: (number | null) | undefined, style?: (number | null) | undefined, speed?: (number | null) | undefined, clone_strength?: (number | null) | undefined}; export type PronunciationDictionaryVersionLocatorRequestModel = {pronunciation_dictionary_id: string, version_id?: (string | null) | undefined}; export type EffectsSpecInput = {filter_preset_id?: (string | null) | undefined, distance?: number | undefined, environment_id?: (string | null) | undefined, background_noise_id?: (string | null) | undefined, send_level?: number | undefined, pan?: number | undefined}; export type BodyTextToSpeechStream = {text: string, model_id?: string | undefined, language_code?: (string | null) | undefined, voice_settings?: (VoiceSettingsResponseModel | null) | undefined, pronunciation_dictionary_locators?: (Array | null) | undefined, seed?: (number | null) | undefined, previous_text?: (string | null) | undefined, next_text?: (string | null) | undefined, previous_request_ids?: (Array | null) | undefined, next_request_ids?: (Array | null) | undefined, use_pvc_as_ivc?: (boolean | null) | undefined, apply_text_normalization?: ('auto' | 'on' | 'off') | undefined, apply_language_text_normalization?: boolean | undefined, audio_effects?: (EffectsSpecInput | null) | undefined}; export type CreateApiV1TextToSpeechVoiceIdStreamArgs = {voice_id: string, enable_logging?: boolean | undefined, optimize_streaming_latency?: (number | null) | undefined, output_format?: ('mp3_22050_32' | 'mp3_24000_48' | 'mp3_44100_32' | 'mp3_44100_64' | 'mp3_44100_96' | 'mp3_44100_128' | 'mp3_44100_192' | 'pcm_8000' | 'pcm_16000' | 'pcm_22050' | 'pcm_24000' | 'pcm_32000' | 'pcm_44100' | 'pcm_48000' | 'ulaw_8000' | 'alaw_8000' | 'opus_48000_32' | 'opus_48000_64' | 'opus_48000_96' | 'opus_48000_128' | 'opus_48000_192') | undefined, 'xi-api-key'?: (string | null) | undefined, body: BodyTextToSpeechStream}; export type CreateApiV1TextToSpeechVoiceIdStreamOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Text To Speech Streaming * * POST /v1/text-to-speech/{voice_id}/stream */ export const createApiV1TextToSpeechVoiceIdStream = async (args: CreateApiV1TextToSpeechVoiceIdStreamArgs, options: CreateApiV1TextToSpeechVoiceIdStreamOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "audio/mpeg") if (args.enable_logging != null) query.append("enable_logging", String(args.enable_logging)) if (args.optimize_streaming_latency != null) query.append("optimize_streaming_latency", String(args.optimize_streaming_latency)) if (args.output_format != null) query.append("output_format", String(args.output_format)) if (args['xi-api-key'] != null) headers.set("xi-api-key", String(args['xi-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/text-to-speech/${encodeURIComponent(String(args.voice_id))}/stream${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() };