export type CreateApiVoiceSayArgs = {voiceid?: string | undefined, sinkid?: string | undefined, volume?: string | undefined, body: BodyInit}; export type CreateApiVoiceSayOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Speaks a given text with a given voice through the given audio sink. * * POST /voice/say */ export const createApiVoiceSay = async (args: CreateApiVoiceSayArgs, options: CreateApiVoiceSayOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") if (args.voiceid != null) query.append("voiceid", String(args.voiceid)) if (args.sinkid != null) query.append("sinkid", String(args.sinkid)) if (args.volume != null) query.append("volume", String(args.volume)) const url = `${baseUrl.replace(/\/+$/, '')}/voice/say${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };