export type SynthesizeSpeechDto = {engine: string, text: string, languageCode: string, voiceId: string}; export type CreateApiAutogamePollyVoiceArgs = {body: SynthesizeSpeechDto}; export type CreateApiAutogamePollyVoiceOptions = {baseUrl: string, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /autogame/polly/voice */ export const createApiAutogamePollyVoice = async (args: CreateApiAutogamePollyVoiceArgs, options: CreateApiAutogamePollyVoiceOptions) => { const {baseUrl, fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "audio/mp3") if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/autogame/polly/voice${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() };