Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

1.6 KB
Raw Blame
import { z } from "zod";
import { hearingConfigShape } from "./hearing-config.ts";
import { FISH_TTS_MODELS, fishSynthesisSchema } from "../../shared/fish-voice.ts";
import { VOICE_PLAYBACK_RATES, type VoicePlaybackRate } from "../../shared/voice-playback.ts";

export { FISH_TTS_MODELS, type FishTtsModel } from "../../shared/fish-voice.ts";

export const voiceProviders = ["elevenlabs", "fish", "system", "chatterbox", "xai", "gemini", "openai", "deepseek", "cartesia"] as const;
export type VoiceProvider = (typeof voiceProviders)[number];
const key = z.string().trim().optional();

export const ttsConfigSchema = z.object({
  key,
  fishKey: key,
  geminiKey: key,
  cartesiaKey: key,
  cartesiaModel: z.string().trim().max(100).optional(),
  cartesiaLanguage: z.string().trim().regex(/^(?:[a-z]{2,3}(?:-[A-Z]{2})?)?$/, "Use a Cartesia language code such as nl or en-GB").optional(),
  voice: z.string().optional(),
  provider: z.enum(voiceProviders).optional(),
  baseUrl: z.string().trim().max(2048)
    .refine((value) => !value || /^https?:\/\//i.test(value), "the Chatterbox server address must start with http:// or https://").optional(),
  model: z.string().optional(),
  ...hearingConfigShape,
  fishModel: z.enum(FISH_TTS_MODELS).optional(),
  fishSynthesis: fishSynthesisSchema.optional(),
  everyReply: z.boolean().optional(),
  playbackRate: z.number().refine((value): value is VoicePlaybackRate => VOICE_PLAYBACK_RATES.includes(value as VoicePlaybackRate), "playbackRate must be a supported voice speed").optional(),
});

export type TtsConfig = z.output<typeof ttsConfigSchema>;