import {z} from 'zod' export type CreateApiV1AiVoiceClonerArgs = {body: {name?: string | undefined, assets: {audio_file_path: string}, style: {language?: ('auto' | 'chinese' | 'english' | 'japanese' | 'korean' | 'german' | 'french' | 'spanish' | 'italian' | 'russian' | 'portuguese' | 'hindi' | 'polish' | 'arabic' | 'dutch' | 'hebrew' | 'tagalog' | 'thai' | 'urdu' | 'turkish' | 'vietnamese' | 'tamil' | 'persian' | 'ukrainian' | 'bengali' | 'indonesian' | 'marathi' | 'romanian' | 'swahili' | 'nepali' | 'telugu' | 'punjabi' | 'gujarati' | 'javanese' | 'burmese' | 'kannada' | 'cantonese' | 'uzbek' | 'afrikaans' | 'albanian' | 'amharic' | 'armenian' | 'assamese' | 'azerbaijani' | 'basque' | 'belarusian' | 'bulgarian' | 'catalan' | 'cebuano' | 'croatian' | 'czech' | 'danish' | 'estonian' | 'finnish' | 'galician' | 'georgian' | 'greek' | 'haitian creole' | 'hungarian' | 'icelandic' | 'kazakh' | 'konkani' | 'lao' | 'latvian' | 'lithuanian' | 'luxembourgish' | 'macedonian' | 'maithili' | 'malagasy' | 'malay' | 'malayalam' | 'mongolian' | 'norwegian' | 'odia' | 'pashto' | 'serbian' | 'sindhi' | 'sinhala' | 'slovak' | 'slovenian' | 'swedish' | 'welsh') | undefined, speed?: number | undefined, prompt: string}}}; export type CreateApiV1AiVoiceClonerOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AiVoiceClonerResponse = z.object({id: z.string(), credits_charged: z.number().int()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * AI Voice Cloner * * POST /v1/ai-voice-cloner */ export const createApiV1AiVoiceCloner = async (args: CreateApiV1AiVoiceClonerArgs, options?: CreateApiV1AiVoiceClonerOptions) => { const {baseUrl = "https://api.magichour.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ai-voice-cloner${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 validateResponse(createApiV1AiVoiceClonerResponse, await res.json()) };