export type TimeRange = {start_ms: number, end_ms: number}; export type SectionSource = {song_id: string, range: TimeRange, negative_ranges?: Array | undefined}; export type SongSection = {section_name: string, positive_local_styles: Array, negative_local_styles: Array, duration_ms: number, lines: Array, source_from?: (SectionSource | null) | undefined}; export type MusicPrompt = {positive_global_styles: Array, negative_global_styles: Array, sections: Array}; export type AudioRefChunk = {song_id: string, range: TimeRange}; export type ConditionStrength = 'low' | 'medium' | 'high' | 'xhigh'; export type GenerationChunkInput = {text: string, duration_ms: number, positive_styles: Array, negative_styles?: Array | undefined, context_adherence?: ('low' | 'medium' | 'high') | undefined, conditioning_ref?: (AudioRefChunk | null) | undefined, condition_strength?: (ConditionStrength | null) | undefined}; export type CompositionPlan = {chunks: Array}; export type MusicModelID = 'music_v1' | 'music_v2' | 'music_v2_5'; export type BodyStreamComposedMusicWithADetailedResponseV1MusicDetailedStreamPost = {prompt?: (string | null) | undefined, generation_mode?: ('track' | 'loop' | 'ambience' | 'video_to_music' | null) | undefined, music_prompt?: ({positive_global_styles: Array, negative_global_styles: Array, sections: Array} | null) | undefined, lyrics_text?: (string | null) | undefined, composition_plan?: (MusicPrompt | CompositionPlan | null) | undefined, music_length_ms?: (number | null) | undefined, model_id?: MusicModelID | undefined, seed?: (number | null) | undefined, force_instrumental?: boolean | undefined, finetune_id?: (string | null) | undefined, finetune_strength?: number | undefined, use_phonetic_names?: boolean | undefined, store_for_inpainting?: boolean | undefined, with_timestamps?: boolean | undefined, with_waveform_visual?: boolean | undefined}; export type CreateApiV1MusicDetailedStreamArgs = {output_format?: ('auto' | 'mp3_48000_128' | 'mp3_48000_192' | 'mp3_48000_240' | 'mp3_48000_320' | '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, enable_logging?: boolean | undefined, 'xi-api-key'?: (string | null) | undefined, body: BodyStreamComposedMusicWithADetailedResponseV1MusicDetailedStreamPost}; export type CreateApiV1MusicDetailedStreamOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Stream Composed Music With A Detailed Response * * POST /v1/music/detailed/stream */ export const createApiV1MusicDetailedStream = async (args: CreateApiV1MusicDetailedStreamArgs, options: CreateApiV1MusicDetailedStreamOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (args.output_format != null) query.append("output_format", String(args.output_format)) if (args.enable_logging != null) query.append("enable_logging", String(args.enable_logging)) if (args['xi-api-key'] != null) headers.set("xi-api-key", String(args['xi-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/music/detailed/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.text() };