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 AddLocalesToDubbingProjectRequest = {targetLanguages: Array, lipsyncEnabled?: boolean | undefined, videoDuration?: ('adaptive' | 'original') | undefined, visibility?: ('private' | 'public') | undefined}; export type UpdateApiV2DubbingDubbingProjectIdArgs = {dubbing_project_id: string, body: AddLocalesToDubbingProjectRequest}; export type UpdateApiV2DubbingDubbingProjectIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const dubbedVideosApiError = z.object({error: z.string().nullable().optional(), language: z.string().nullable().optional()}); export const dubbingOutputLanguage = z.enum(["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 const dubbedAssetInProgress = z.object({id: z.string(), language: dubbingOutputLanguage, status: z.literal("in_progress").optional()}); export const dubbedAssetThumbnail = z.object({image: z.string().nullable().optional(), gif: z.string().nullable().optional()}); export const dubbedAssetCaptions = z.object({srt: z.string().nullable().optional(), vtt: z.string().nullable().optional()}); export const dubbedAssetComplete = z.object({id: z.string(), title: z.string(), description: z.string(), language: dubbingOutputLanguage, status: z.literal("complete").optional(), createdAt: z.number().int().nullable().optional(), lastUpdatedAt: z.number().int().nullable().optional(), visibility: z.enum(["public", "private"]), download: z.string(), thumbnail: dubbedAssetThumbnail, captions: dubbedAssetCaptions}); export const publicApiImportedAndDubbedVideosErrorCode = z.enum(["moderation", "video_duration_limit_reached", "invalid_target_language", "processing_error"]); export const dubbedAssetError = z.object({id: z.string(), language: dubbingOutputLanguage, status: z.literal("error").optional(), errorCode: publicApiImportedAndDubbedVideosErrorCode}); export const addLocalesToDubbingProjectResponse = z.object({dubbedErrors: z.array(dubbedVideosApiError).optional(), createdDubbedAssets: z.array(z.union([dubbedAssetInProgress, dubbedAssetComplete, dubbedAssetError]))}); 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 }; /** * Add locales to a a dubbing project (original imported video) * * PUT /v2/dubbing/{dubbing_project_id} */ export const updateApiV2DubbingDubbingProjectId = async (args: UpdateApiV2DubbingDubbingProjectIdArgs, options?: UpdateApiV2DubbingDubbingProjectIdOptions) => { 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/${encodeURIComponent(String(args.dubbing_project_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(addLocalesToDubbingProjectResponse, await res.json()) };