export type FramePhoneme = {phoneme: string, frame_length: number, note_id?: (string | null) | undefined}; export type FrameAudioQuery = {f0: Array, volume: Array, phonemes: Array, volumeScale: number, outputSamplingRate: number, outputStereo: boolean}; export type CreateApiFrameSynthesisArgs = {speaker: number, core_version?: string | undefined, body: FrameAudioQuery}; export type CreateApiFrameSynthesisOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Frame Synthesis * * POST /frame_synthesis */ export const createApiFrameSynthesis = async (args: CreateApiFrameSynthesisArgs, options: CreateApiFrameSynthesisOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "audio/wav") if (args.speaker != null) query.append("speaker", String(args.speaker)) if (args.core_version != null) query.append("core_version", String(args.core_version)) const url = `${baseUrl.replace(/\/+$/, '')}/frame_synthesis${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() };