All files / src/schemas Character.ts

0% Statements 0/7
100% Branches 0/0
100% Functions 0/0
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                                                                                                                                                                       
import z from "zod";
 
const ZeroToOneSchema = z.number().min(0).max(1);
const AutoOnOffSchema = z.enum(["auto", "on", "off"]);
 
export const ElevenLabsTextToSpeechVoiceSettingsSchema = z.object({
    stability: ZeroToOneSchema.default(0.5),
    speakerBoost: z.boolean().default(true),
    similarityBoost: ZeroToOneSchema.default(0.75),
    style: z.number().default(1),
    speed: z.number().default(1),
    applyTextNormalization: AutoOnOffSchema.default("auto"),
    applyLanguageTextNormalization: z.boolean().default(false),
});
 
export const ElevenLabsTextToSpeechVoiceSettingsDefaultValue = ElevenLabsTextToSpeechVoiceSettingsSchema.parse({});
 
export type ElevenLabsTextToSpeechVoiceSettings = z.infer<typeof ElevenLabsTextToSpeechVoiceSettingsSchema>;
 
const ElevenLabsVoiceProviderSchema = z.object({
    provider: z.literal("ELEVENLABS").describe("Voice provider identifier for ElevenLabs"),
    voiceID: z.string().describe("Unique voice identifier from ElevenLabs voice library"),
    name: z.string(),
    gender: z.enum(["MALE", "FEMALE", "NEUTRAL", "NOT_AVAILABLE"]),
    category: z.enum(["GENERATED", "CLONED", "PREMADE", "PROFESSIONAL", "FAMOUS", "HIGH_QUALITY"]),
    description: z.string().optional(),
    /* verifiedLanguages: z
        .array(
            z.object({
                language: z.string(),
                modelID: z.string(),
                accent: z.string().nullable(),
                locale: z.string().nullable(),
            }),
        )
        .nullable(), */
    voiceSettings: z
        .object({
            textToSpeech: ElevenLabsTextToSpeechVoiceSettingsSchema.optional().nullable(),
            textToDialogue: z
                .object({
                    stability: ZeroToOneSchema.optional().nullable(),
                    seed: z.number().min(0).max(4294967295).optional(),
                    textNormalization: AutoOnOffSchema.optional(),
                })
                .optional(),
        })
        .optional(),
});
/*
const HeyGenVoiceProviderSchema = z.object({
    provider: z.literal("HEYGEN").describe("Voice provider identifier for HeyGen"),
    voiceID: z.string().describe("Unique voice identifier from HeyGen voice library"),
});
*/
 
export const CharacterSchema = z.object({
    name: z.string().max(64).describe("Character's name (maximum 64 characters)"),
    gender: z.enum(["MALE", "FEMALE"]),
    ageGroup: z
        .tuple([z.number().min(6), z.number().max(96)])
        .describe("Character's age range as [minimum age, maximum age], where min is at least 6 and max is at most 96"),
    description: z
        .string()
        .describe("Detailed description of the character's appearance, personality, and role in the story"),
    voiceDescription: z
        .string()
        .describe("Description of the character's voice characteristics (tone, accent, pitch, speaking style, etc.)"),
    voice: z
        .discriminatedUnion("provider", [ElevenLabsVoiceProviderSchema])
        .optional()
        .describe("Optional voice configuration from either ElevenLabs or HeyGen provider"),
});
 
export const CharacterSchemaWithVoice = CharacterSchema.extend({
    voice: z.discriminatedUnion("provider", [ElevenLabsVoiceProviderSchema]),
});
 
export type Character = z.infer<typeof CharacterSchema>;
export type CharacterVoice = NonNullable<Character["voice"]>;
export type CharacterVoiceSettings = NonNullable<CharacterVoice["voiceSettings"]>;
 
export type TextToSpeechCharacterVoiceSettings = NonNullable<CharacterVoiceSettings["textToSpeech"]>;