import {z} from 'zod' export type DubbingOutputLanguage = 'af' | 'sq' | 'am' | 'ar' | 'ar-DZ' | 'ar-BH' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LY' | 'ar-MA' | 'ar-QA' | 'ar-SA' | 'ar-SY' | 'ar-TN' | 'ar-AE' | 'ar-YE' | 'hy' | 'as' | 'az' | 'eu' | 'bn' | 'bs' | 'bg' | 'ca' | 'zh' | 'zh-CN' | 'zh-HK' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'nl-BE' | 'nl-NL' | 'en' | 'en-AU' | 'en-CA' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-IE' | 'en-KE' | 'en-MX' | 'en-NZ' | 'en-NG' | 'en-PH' | 'en-SG' | 'en-ZA' | 'en-TZ' | 'en-US' | 'et' | 'fil' | 'fi' | 'fr' | 'fr-BE' | 'fr-CA' | 'fr-FR' | 'fr-CH' | 'gl' | 'ka' | 'de' | 'de-AT' | 'de-DE' | 'de-CH' | 'el' | 'gu' | 'he' | 'hi' | 'hu' | 'is' | 'id' | 'ga' | 'it' | 'ja' | 'jw' | 'kn' | 'kk' | 'km' | 'ko' | 'lo' | 'lv' | 'lt' | 'mk' | 'ms' | 'ml' | 'mt' | 'mr' | 'mn' | 'ne' | 'no' | 'nb' | 'nn' | 'or' | 'pa' | 'ps' | 'fa' | 'pl' | 'pt' | 'pt-BR' | 'pt-PT' | 'ro' | 'ru' | 'sr' | 'si' | 'sk' | 'sl' | 'so' | 'es' | 'es-AR' | 'es-BO' | 'es-CL' | 'es-CO' | 'es-CR' | 'es-CU' | 'es-DO' | 'es-EC' | 'es-SV' | 'es-GQ' | 'es-GT' | 'es-HN' | 'es-LA' | 'es-MX' | 'es-NI' | 'es-PA' | 'es-PY' | 'es-PE' | 'es-PR' | 'es-ES' | 'es-US' | 'es-UY' | 'es-VE' | 'su' | 'sw' | 'sv' | 'ta' | 'ta-IN' | 'ta-SG' | 'ta-LK' | 'te' | 'th' | 'tr' | 'uk' | 'ur' | 'uz' | 'vi' | 'cy' | 'zu'; export type DubbingInputLanguage = 'af' | 'sq' | 'am' | 'ar' | 'ar-DZ' | 'ar-BH' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LY' | 'ar-MA' | 'ar-QA' | 'ar-SA' | 'ar-SY' | 'ar-TN' | 'ar-AE' | 'ar-YE' | 'hy' | 'as' | 'az' | 'ba' | 'eu' | 'be' | 'bn' | 'bs' | 'br' | 'bg' | 'my' | 'ca' | 'zh' | 'zh-CN' | 'zh-HK' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'nl-BE' | 'nl-NL' | 'en' | 'en-AU' | 'en-CA' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-IE' | 'en-KE' | 'en-MX' | 'en-NZ' | 'en-NG' | 'en-PH' | 'en-SG' | 'en-ZA' | 'en-TZ' | 'en-US' | 'et' | 'fo' | 'fi' | 'fr' | 'fr-BE' | 'fr-CA' | 'fr-FR' | 'fr-CH' | 'gl' | 'ka' | 'de' | 'de-AT' | 'de-DE' | 'de-CH' | 'el' | 'gu' | 'ht' | 'ha' | 'haw' | 'he' | 'hi' | 'hu' | 'is' | 'id' | 'it' | 'ja' | 'jw' | 'kn' | 'kk' | 'km' | 'ko' | 'lo' | 'la' | 'lv' | 'ln' | 'lt' | 'lb' | 'mk' | 'mg' | 'ms' | 'ml' | 'mt' | 'mi' | 'mr' | 'mn' | 'ne' | 'no' | 'nb' | 'nn' | 'oc' | 'pa' | 'ps' | 'fa' | 'pl' | 'pt' | 'pt-BR' | 'pt-PT' | 'ro' | 'ru' | 'sa' | 'sr' | 'sn' | 'sd' | 'si' | 'sk' | 'sl' | 'so' | 'es' | 'es-AR' | 'es-BO' | 'es-CL' | 'es-CO' | 'es-CR' | 'es-CU' | 'es-DO' | 'es-EC' | 'es-SV' | 'es-GQ' | 'es-GT' | 'es-HN' | 'es-LA' | 'es-MX' | 'es-NI' | 'es-PA' | 'es-PY' | 'es-PE' | 'es-PR' | 'es-ES' | 'es-US' | 'es-UY' | 'es-VE' | 'su' | 'sw' | 'sv' | 'tl' | 'tg' | 'ta' | 'ta-IN' | 'ta-SG' | 'ta-LK' | 'tt' | 'te' | 'th' | 'bo' | 'tr' | 'tk' | 'uk' | 'ur' | 'uz' | 'vi' | 'cy' | 'yi' | 'yo'; export type CreateDubbingProjectApiRequestFromSourceAssetId = {title: string, targetLanguages: Array, lipsyncEnabled?: boolean | undefined, videoDuration?: ('adaptive' | 'original') | undefined, visibility?: ('private' | 'public') | undefined, sourceAssetId: string, sourceLanguage: DubbingInputLanguage}; export type CreateApiV2DubbingArgs = {body: CreateDubbingProjectApiRequestFromSourceAssetId | {title: string, targetLanguages: Array, lipsyncEnabled?: boolean | undefined, videoDuration?: ('adaptive' | 'original') | undefined, visibility?: ('private' | 'public') | undefined, sourceVideoUrl: string, sourceLanguage?: (DubbingInputLanguage | null) | undefined}}; export type CreateApiV2DubbingOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const importedAssetId = z.object({id: z.string()}); export const createDubbingProjectApiResponseSuccess = z.object({createdImportedAsset: importedAssetId}); 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 }; /** * Create a dubbing project from an uploaded video asset * * POST /v2/dubbing */ export const createApiV2Dubbing = async (args: CreateApiV2DubbingArgs, options?: CreateApiV2DubbingOptions) => { const {baseUrl = "https://api.synthesia.io", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/dubbing${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(createDubbingProjectApiResponseSuccess, await res.json()) };