import {z} from 'zod' export type GetApiVoicesV1VoicesArgs = {filter?: string | undefined, orderBy?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined, languages?: Array | undefined}; export type GetApiVoicesV1VoicesOptions = {baseUrl?: string | undefined, inworldBasic?: string | undefined, fetch?: typeof fetch | undefined}; export const inworldttslanguageCodesLanguageCode = z.enum(["EN_US", "ZH_CN", "KO_KR", "JA_JP", "RU_RU", "AUTO", "IT_IT", "ES_ES", "PT_BR", "DE_DE", "FR_FR", "AR_SA", "PL_PL", "NL_NL", "HI_IN", "HE_IL"]); export const inworldvoicev1Voice = z.object({voiceId: z.string().optional(), langCode: inworldttslanguageCodesLanguageCode.optional(), languageCode: z.string().optional(), displayName: z.string().optional(), description: z.string().optional(), tags: z.array(z.string()).optional(), name: z.string().optional(), source: z.enum(["SYSTEM", "IVC", "PVC"]).optional(), gender: z.enum(["male", "female", "neutral", ""]).optional(), ageGroup: z.enum(["young", "middle_aged", "elderly", ""]).optional(), categories: z.array(z.enum(["companions", "enterprise", "education_training", "developer_assistants", "healthcare", "interactive_media"])).optional(), promptLanguages: z.array(z.string()).optional()}); export const inworldvoicev1ListVoicesResponse = z.object({voices: z.array(inworldvoicev1Voice).optional(), totalSize: z.number().int().optional(), nextPageToken: z.string().optional()}); 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 }; /** * Lists voices in a workspace * * GET /voices/v1/voices */ export const getApiVoicesV1Voices = async (args: GetApiVoicesV1VoicesArgs, options?: GetApiVoicesV1VoicesOptions) => { const {baseUrl = "https://api.inworld.ai", fetch: fetchFn = fetch, inworldBasic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) for (const item of args.languages ?? []) query.append("languages", String(item)) if (inworldBasic !== undefined) headers.set("Authorization", inworldBasic) const url = `${baseUrl.replace(/\/+$/, '')}/voices/v1/voices${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(inworldvoicev1ListVoicesResponse, await res.json()) };