Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

feat(tts): add ElevenLabs voice search, favorites, and model selection

lvalics9d95f51fb728
diff --git a/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx b/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx
index 8ae423b7..2adb2231 100644
--- a/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx
+++ b/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useCallback, useRef } from "react";
+import React, { useState, useCallback, useRef, useEffect } from "react";
import {
Mic,
Play,
@@ -9,6 +9,10 @@ import {
User,
Download,
Settings,
+ Search,
+ Star,
+ StarOff,
+ ChevronDown,
} from "lucide-react";
import { Slider } from "@openreel/ui";
import { useProjectStore } from "../../../stores/project-store";
@@ -23,6 +27,13 @@ const TTS_PROVIDERS = [
{ id: "elevenlabs" as const, label: "ElevenLabs", description: "Premium AI voices" },
];
+const ELEVENLABS_MODELS = [
+ { id: "eleven_multilingual_v2", label: "Multilingual v2", description: "Best quality, 29 languages" },
+ { id: "eleven_turbo_v2_5", label: "Turbo v2.5", description: "Low latency, high quality" },
+ { id: "eleven_turbo_v2", label: "Turbo v2", description: "Low latency, English optimized" },
+ { id: "eleven_monolingual_v1", label: "English v1", description: "Legacy English model" },
+];
+
interface Voice {
id: string;
name: string;
@@ -30,26 +41,35 @@ interface Voice {
language: string;
}
+interface ElevenLabsVoice {
+ voice_id: string;
+ name: string;
+ category: string;
+ labels: Record<string, string>;
+ preview_url?: string;
+}
+
const PIPER_VOICES: Voice[] = [
{ id: "amy", name: "Amy", gender: "female", language: "en-US" },
{ id: "ryan", name: "Ryan", gender: "male", language: "en-US" },
];
-const ELEVENLABS_VOICES: Voice[] = [
- { id: "rachel", name: "Rachel", gender: "female", language: "en-US" },
- { id: "drew", name: "Drew", gender: "male", language: "en-US" },
- { id: "bella", name: "Bella", gender: "female", language: "en-US" },
- { id: "antoni", name: "Antoni", gender: "male", language: "en-US" },
- { id: "elli", name: "Elli", gender: "female", language: "en-US" },
- { id: "josh", name: "Josh", gender: "male", language: "en-US" },
- { id: "adam", name: "Adam", gender: "male", language: "en-US" },
- { id: "sam", name: "Sam", gender: "male", language: "en-US" },
-];
+// Voice cache to avoid re-fetching
+let cachedElevenLabsVoices: ElevenLabsVoice[] | null = null;
export const TextToSpeechPanel: React.FC = () => {
const importMedia = useProjectStore((state) => state.importMedia);
const project = useProjectStore((state) => state.project);
- const { defaultTtsProvider, openSettings, configuredServices } = useSettingsStore();
+ const {
+ defaultTtsProvider,
+ openSettings,
+ configuredServices,
+ elevenLabsModel,
+ setElevenLabsModel,
+ favoriteVoices,
+ addFavoriteVoice,
+ removeFavoriteVoice,
+ } = useSettingsStore();
const defaultProvider: TtsProvider =
defaultTtsProvider === "elevenlabs" && configuredServices.includes("elevenlabs")
@@ -58,18 +78,131 @@ export const TextToSpeechPanel: React.FC = () => {
const [provider, setProvider] = useState<TtsProvider>(defaultProvider);
const [text, setText] = useState("");
- const [selectedVoice, setSelectedVoice] = useState<string>("amy");
+ const [selectedVoice, setSelectedVoice] = useState<string>(
+ defaultProvider === "elevenlabs" && favoriteVoices.length > 0
+ ? favoriteVoices[0].voiceId
+ : "amy",
+ );
const [speed, setSpeed] = useState(1.0);
const [isGenerating, setIsGenerating] = useState(false);
const [isPlaying, setIsPlaying] = useState(false);
const [generatedAudio, setGeneratedAudio] = useState<Blob | null>(null);
const [error, setError] = useState<string | null>(null);
+ // Voice search state
+ const [voiceSearch, setVoiceSearch] = useState("");
+ const [allVoices, setAllVoices] = useState<ElevenLabsVoice[]>([]);
+ const [isLoadingVoices, setIsLoadingVoices] = useState(false);
+ const [showAllVoices, setShowAllVoices] = useState(false);
+ const [previewingVoice, setPreviewingVoice] = useState<string | null>(null);
+
const audioRef = useRef<HTMLAudioElement | null>(null);
const audioUrlRef = useRef<string | null>(null);
+ const previewAudioRef = useRef<HTMLAudioElement | null>(null);
const hasElevenLabsKey = configuredServices.includes("elevenlabs");
- const voices = provider === "elevenlabs" ? ELEVENLABS_VOICES : PIPER_VOICES;
+
+ // Fetch ElevenLabs voices
+ const fetchVoices = useCallback(async () => {
+ if (cachedElevenLabsVoices) {
+ setAllVoices(cachedElevenLabsVoices);
+ return;
+ }
+
+ if (!isSessionUnlocked()) return;
+
+ const apiKey = await getSecret("elevenlabs");
+ if (!apiKey) return;
+
+ setIsLoadingVoices(true);
+ try {
+ const response = await fetch(`${ELEVENLABS_API_URL}/voices`, {
+ headers: { "xi-api-key": apiKey },
+ });
+
+ if (!response.ok) throw new Error("Failed to fetch voices");
+
+ const data = await response.json();
+ const voices = (data.voices ?? []) as ElevenLabsVoice[];
+ cachedElevenLabsVoices = voices;
+ setAllVoices(voices);
+ } catch {
+ // Silently fail — user can still use favorites
+ } finally {
+ setIsLoadingVoices(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ if (provider === "elevenlabs" && hasElevenLabsKey && allVoices.length === 0) {
+ fetchVoices();
+ }
+ }, [provider, hasElevenLabsKey, allVoices.length, fetchVoices]);
+
+ // Preview a voice sample
+ const previewVoice = useCallback((previewUrl?: string, voiceId?: string) => {
+ if (!previewUrl) return;
+
+ if (previewingVoice === voiceId) {
+ previewAudioRef.current?.pause();
+ setPreviewingVoice(null);
+ return;
+ }
+
+ if (previewAudioRef.current) {
+ previewAudioRef.current.pause();
+ }
+
+ const audio = new Audio(previewUrl);
+ previewAudioRef.current = audio;
+ setPreviewingVoice(voiceId ?? null);
+
+ audio.onended = () => setPreviewingVoice(null);
+ audio.play().catch(() => setPreviewingVoice(null));
+ }, [previewingVoice]);
+
+ const isFavorite = useCallback(
+ (voiceId: string) => favoriteVoices.some((v) => v.voiceId === voiceId),
+ [favoriteVoices],
+ );
+
+ const toggleFavorite = useCallback(
+ (voice: ElevenLabsVoice) => {
+ if (isFavorite(voice.voice_id)) {
+ removeFavoriteVoice(voice.voice_id);
+ } else {
+ addFavoriteVoice({
+ voiceId: voice.voice_id,
+ name: voice.name,
+ previewUrl: voice.preview_url,
+ });
+ }
+ },
+ [isFavorite, addFavoriteVoice, removeFavoriteVoice],
+ );
+
+ // Filtered voices for search
+ const filteredVoices = allVoices.filter((v) => {
+ if (!voiceSearch.trim()) return true;
+ const q = voiceSearch.toLowerCase();
+ return (
+ v.name.toLowerCase().includes(q) ||
+ v.category?.toLowerCase().includes(q) ||
+ Object.values(v.labels || {}).some((l) => l.toLowerCase().includes(q))
+ );
+ });
+
+ // Get display name for currently selected voice
+ const getSelectedVoiceName = useCallback((): string => {
+ if (provider === "piper") {
+ return PIPER_VOICES.find((v) => v.id === selectedVoice)?.name ?? "TTS";
+ }
+ const fav = favoriteVoices.find((v) => v.voiceId === selectedVoice);
+ if (fav) return fav.name;
+ const apiVoice = allVoices.find((v) => v.voice_id === selectedVoice);
+ if (apiVoice) return apiVoice.name;
+ return "TTS";
+ }, [provider, selectedVoice, favoriteVoices, allVoices]);
const generateWithPiper = useCallback(async (inputText: string, voice: string, spd: number): Promise<Blob> => {
const response = await fetch(`${OPENREEL_TTS_URL}/tts`, {
@@ -81,7 +214,7 @@ export const TextToSpeechPanel: React.FC = () => {
if (!response.ok) {
if (response.status === 429) {
throw new Error(
- "Rate limit reached. Please wait a minute before generating more speech. This free service is limited to 10 requests per minute.",
+ "Rate limit reached. Please wait a minute. Free service is limited to 10 req/min.",
);
}
const errorData = await response.json().catch(() => ({}));
@@ -91,7 +224,7 @@ export const TextToSpeechPanel: React.FC = () => {
return response.blob();
}, []);
- const generateWithElevenLabs = useCallback(async (inputText: string, voice: string): Promise<Blob> => {
+ const generateWithElevenLabs = useCallback(async (inputText: string, voiceId: string): Promise<Blob> => {
if (!isSessionUnlocked()) {
throw new Error("Session locked. Unlock in Settings > API Keys first.");
}
@@ -101,24 +234,6 @@ export const TextToSpeechPanel: React.FC = () => {
throw new Error("ElevenLabs API key not found. Add it in Settings > API Keys.");
}
- // Default voice IDs from ElevenLabs
- const voiceMap: Record<string, string> = {
- rachel: "21m00Tcm4TlvDq8ikWAM",
- drew: "29vD33N1CtxCmqQRPOHJ",
- clyde: "2EiwWnXFnvU5JabPnv8n",
- paul: "5Q0t7uMcjvnagumLfvZi",
- domi: "AZnzlk1XvdvUeBnXmlld",
- bella: "EXAVITQu4vr4xnSDxMaL",
- antoni: "ErXwobaYiN019PkySvjV",
- elli: "MF3mGyEYCl7XYWbV9V6O",
- josh: "TxGEqnHWrfWFTfGW9XjX",
- arnold: "VR6AewLTigWG4xSOukaG",
- adam: "pNInz6obpgDQGcFmaJgB",
- sam: "yoZ06aMxZJJ28mfd3POQ",
- };
-
- const voiceId = voiceMap[voice] ?? voiceMap.rachel;
-
const response = await fetch(
`${ELEVENLABS_API_URL}/text-to-speech/${voiceId}`,
{
@@ -129,23 +244,22 @@ export const TextToSpeechPanel: React.FC = () => {
},
body: JSON.stringify({
text: inputText,
- model_id: "eleven_monolingual_v1",
- voice_settings: { stability: 0.5, similarity_boost: 0.5 },
+ model_id: elevenLabsModel,
+ voice_settings: { stability: 0.5, similarity_boost: 0.75 },
}),
},
);
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
- throw new Error(
- (errorData as Record<string, unknown>).detail as string
- || (errorData as Record<string, unknown>).message as string
- || `ElevenLabs error (${response.status})`,
- );
+ const msg = (errorData as Record<string, unknown>).detail
+ ?? (errorData as Record<string, unknown>).message
+ ?? `ElevenLabs error (${response.status})`;
+ throw new Error(String(msg));
}
return response.blob();
- }, []);
+ }, [elevenLabsModel]);
const generateSpeech = useCallback(async () => {
if (!text.trim()) {
@@ -176,9 +290,7 @@ export const TextToSpeechPanel: React.FC = () => {
audioRef.current.src = url;
}
} catch (err) {
- setError(
- err instanceof Error ? err.message : "Failed to generate speech",
- );
+ setError(err instanceof Error ? err.message : "Failed to generate speech");
} finally {
setIsGenerating(false);
}
@@ -206,8 +318,7 @@ export const TextToSpeechPanel: React.FC = () => {
setIsGenerating(true);
try {
- const voiceName =
- voices.find((v) => v.id === selectedVoice)?.name || "TTS";
+ const voiceName = getSelectedVoiceName();
const timestamp = Date.now();
const fileName = `${voiceName}_${timestamp}.wav`;
@@ -233,18 +344,16 @@ export const TextToSpeechPanel: React.FC = () => {
audioUrlRef.current = null;
}
} catch (err) {
- setError(
- err instanceof Error ? err.message : "Failed to add to timeline",
- );
+ setError(err instanceof Error ? err.message : "Failed to add to timeline");
} finally {
setIsGenerating(false);
}
- }, [generatedAudio, project, selectedVoice, importMedia]);
+ }, [generatedAudio, project, getSelectedVoiceName, importMedia]);
const downloadAudio = useCallback(() => {
if (!generatedAudio) return;
- const voiceName = voices.find((v) => v.id === selectedVoice)?.name || "TTS";
+ const voiceName = getSelectedVoiceName();
const timestamp = Date.now();
const fileName = `${voiceName}_${timestamp}.wav`;
@@ -254,9 +363,8 @@ export const TextToSpeechPanel: React.FC = () => {
a.download = fileName;
a.click();
URL.revokeObjectURL(url);
- }, [generatedAudio, selectedVoice]);
+ }, [generatedAudio, getSelectedVoiceName]);
- const selectedVoiceData = voices.find((v) => v.id === selectedVoice);
const charCount = text.length;
const maxChars = 5000;
@@ -300,9 +408,13 @@ export const TextToSpeechPanel: React.FC = () => {
return;
}
setProvider(p.id);
- // Reset voice when switching provider
- setSelectedVoice(p.id === "elevenlabs" ? "rachel" : "amy");
+ setSelectedVoice(
+ p.id === "elevenlabs"
+ ? (favoriteVoices.length > 0 ? favoriteVoices[0].voiceId : "")
+ : "amy",
+ );
setGeneratedAudio(null);
+ setShowAllVoices(false);
}}
className={`flex-1 px-2 py-1.5 rounded-lg text-[10px] transition-colors ${
provider === p.id
@@ -318,13 +430,29 @@ export const TextToSpeechPanel: React.FC = () => {
);
})}
</div>
- {provider === "elevenlabs" && !hasElevenLabsKey && (
- <p className="text-[9px] text-amber-400">
- Add your ElevenLabs API key in Settings to use premium voices.
- </p>
- )}
</div>
+ {/* Model selector (ElevenLabs only) */}
+ {provider === "elevenlabs" && hasElevenLabsKey && (
+ <div className="space-y-2">
+ <label className="text-[10px] font-medium text-text-secondary">
+ Model
+ </label>
+ <select
+ value={elevenLabsModel}
+ onChange={(e) => setElevenLabsModel(e.target.value)}
+ className="w-full h-8 px-2 rounded-lg border border-border bg-background-tertiary text-[10px] text-text-primary focus:border-primary focus:outline-none"
+ >
+ {ELEVENLABS_MODELS.map((m) => (
+ <option key={m.id} value={m.id}>
+ {m.label} — {m.description}
+ </option>
+ ))}
+ </select>
+ </div>
+ )}
+
+ {/* Text input */}
<div className="space-y-2">
<label className="text-[10px] font-medium text-text-secondary">
Text
@@ -345,29 +473,191 @@ export const TextToSpeechPanel: React.FC = () => {
</div>
</div>
+ {/* Voice selector */}
<div className="space-y-2">
<label className="text-[10px] font-medium text-text-secondary">
Voice
</label>
- <div className="flex flex-wrap gap-1.5">
- {(provider === "elevenlabs" ? ELEVENLABS_VOICES : PIPER_VOICES).map((voice) => (
+
+ {provider === "piper" ? (
+ /* Piper: simple buttons */
+ <div className="flex flex-wrap gap-1.5">
+ {PIPER_VOICES.map((voice) => (
+ <button
+ key={voice.id}
+ onClick={() => setSelectedVoice(voice.id)}
+ className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[10px] transition-colors ${
+ selectedVoice === voice.id
+ ? "bg-primary text-white font-medium"
+ : "bg-background-tertiary text-text-secondary hover:text-text-primary border border-border"
+ }`}
+ >
+ <User size={10} />
+ <span>{voice.name}</span>
+ <span className="text-[8px] opacity-70">{voice.gender === "female" ? "F" : "M"}</span>
+ </button>
+ ))}
+ </div>
+ ) : (
+ /* ElevenLabs: favorites + searchable voice browser */
+ <div className="space-y-2">
+ {/* Favorites */}
+ {favoriteVoices.length > 0 && (
+ <div className="space-y-1.5">
+ <span className="text-[9px] text-text-muted flex items-center gap-1">
+ <Star size={9} className="text-amber-400 fill-amber-400" /> Favorites
+ </span>
+ <div className="flex flex-wrap gap-1.5">
+ {favoriteVoices.map((fav) => (
+ <button
+ key={fav.voiceId}
+ onClick={() => setSelectedVoice(fav.voiceId)}
+ className={`flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] transition-colors ${
+ selectedVoice === fav.voiceId
+ ? "bg-primary text-white font-medium"
+ : "bg-background-tertiary text-text-secondary hover:text-text-primary border border-border"
+ }`}
+ >
+ <Star size={8} className="text-amber-400 fill-amber-400" />
+ <span>{fav.name}</span>
+ {fav.previewUrl && (
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ previewVoice(fav.previewUrl, fav.voiceId);
+ }}
+ className="ml-0.5 opacity-60 hover:opacity-100"
+ title="Preview voice"
+ >
+ {previewingVoice === fav.voiceId ? (
+ <Pause size={8} />
+ ) : (
+ <Play size={8} />
+ )}
+ </button>
+ )}
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {/* Browse all voices toggle */}
<button
- key={voice.id}
- onClick={() => setSelectedVoice(voice.id)}
- className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[10px] transition-colors ${
- selectedVoice === voice.id
- ? "bg-primary text-white font-medium"
- : "bg-background-tertiary text-text-secondary hover:text-text-primary border border-border"
- }`}
+ onClick={() => setShowAllVoices(!showAllVoices)}
+ className="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-[10px] border border-dashed border-border text-text-muted hover:text-text-primary hover:border-primary/50 transition-colors"
>
- <User size={10} />
- <span>{voice.name}</span>
- <span className="text-[8px] opacity-70">{voice.gender === "female" ? "F" : "M"}</span>
+ <Search size={10} />
+ {showAllVoices ? "Hide voice browser" : "Browse & search voices"}
+ <ChevronDown size={10} className={`transition-transform ${showAllVoices ? "rotate-180" : ""}`} />
</button>
- ))}
- </div>
+
+ {/* Voice browser */}
+ {showAllVoices && (
+ <div className="border border-border rounded-lg overflow-hidden">
+ {/* Search input */}
+ <div className="flex items-center gap-2 px-2 py-1.5 border-b border-border bg-background-secondary">
+ <Search size={12} className="text-text-muted shrink-0" />
+ <input
+ type="text"
+ value={voiceSearch}
+ onChange={(e) => setVoiceSearch(e.target.value)}
+ placeholder="Search by name, accent, gender..."
+ className="flex-1 bg-transparent text-[10px] text-text-primary placeholder:text-text-muted focus:outline-none"
+ autoFocus
+ />
+ {isLoadingVoices && <Loader2 size={12} className="animate-spin text-text-muted" />}
+ </div>
+
+ {/* Voice list */}
+ <div className="max-h-48 overflow-y-auto">
+ {filteredVoices.length === 0 ? (
+ <div className="p-3 text-center text-[10px] text-text-muted">
+ {isLoadingVoices ? "Loading voices..." : allVoices.length === 0 ? "Unlock session to browse voices" : "No voices match your search"}
+ </div>
+ ) : (
+ filteredVoices.map((voice) => {
+ const gender = voice.labels?.gender ?? "";
+ const accent = voice.labels?.accent ?? "";
+ const isSelected = selectedVoice === voice.voice_id;
+ const isFav = isFavorite(voice.voice_id);
+
+ return (
+ <div
+ key={voice.voice_id}
+ className={`flex items-center gap-2 px-2 py-1.5 cursor-pointer transition-colors ${
+ isSelected
+ ? "bg-primary/10 border-l-2 border-primary"
+ : "hover:bg-background-tertiary border-l-2 border-transparent"
+ }`}
+ onClick={() => setSelectedVoice(voice.voice_id)}
+ >
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center gap-1.5">
+ <span className="text-[10px] font-medium text-text-primary truncate">
+ {voice.name}
+ </span>
+ {voice.category === "cloned" && (
+ <span className="text-[8px] px-1 py-0.5 rounded bg-purple-500/20 text-purple-400">
+ Cloned
+ </span>
+ )}
+ </div>
+ <div className="text-[8px] text-text-muted">
+ {[gender, accent, voice.category].filter(Boolean).join(" · ")}
+ </div>
+ </div>
+
+ <div className="flex items-center gap-1 shrink-0">
+ {voice.preview_url && (
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ previewVoice(voice.preview_url, voice.voice_id);
+ }}
+ className="p-1 rounded hover:bg-background-elevated text-text-muted hover:text-text-primary transition-colors"
+ title="Preview"
+ >
+ {previewingVoice === voice.voice_id ? (
+ <Pause size={10} />
+ ) : (
+ <Play size={10} />
+ )}
+ </button>
+ )}
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ toggleFavorite(voice);
+ }}
+ className={`p-1 rounded hover:bg-background-elevated transition-colors ${
+ isFav ? "text-amber-400" : "text-text-muted hover:text-amber-400"
+ }`}
+ title={isFav ? "Remove from favorites" : "Add to favorites"}
+ >
+ {isFav ? (
+ <Star size={10} className="fill-current" />
+ ) : (
+ <StarOff size={10} />
+ )}
+ </button>
+ </div>
+ </div>
+ );
+ })
+ )}
+ </div>
+
+ <div className="px-2 py-1 border-t border-border bg-background-secondary text-[8px] text-text-muted text-center">
+ {filteredVoices.length} of {allVoices.length} voices
+ </div>
+ </div>
+ )}
+ </div>
+ )}
</div>
+ {/* Speed (Piper only) */}
{provider === "piper" && (
<div className="space-y-2">
<div className="flex items-center justify-between">
@@ -401,7 +691,7 @@ export const TextToSpeechPanel: React.FC = () => {
<button
onClick={generateSpeech}
- disabled={isGenerating || !text.trim()}
+ disabled={isGenerating || !text.trim() || (provider === "elevenlabs" && !selectedVoice)}
className="w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary text-white rounded-lg text-[11px] font-medium transition-all hover:bg-primary-hover disabled:opacity-50 disabled:cursor-not-allowed"
>
{isGenerating ? (
@@ -426,7 +716,7 @@ export const TextToSpeechPanel: React.FC = () => {
</div>
<div>
<p className="text-[10px] font-medium text-text-primary">
- {selectedVoiceData?.name} Voice
+ {getSelectedVoiceName()} Voice
</p>
<p className="text-[9px] text-text-muted">
{(generatedAudio.size / 1024).toFixed(1)} KB
@@ -465,7 +755,8 @@ export const TextToSpeechPanel: React.FC = () => {
)}
<p className="text-[9px] text-text-muted text-center">
- Powered by {provider === "elevenlabs" ? "ElevenLabs" : "Piper TTS"} • {selectedVoiceData?.language}
+ Powered by {provider === "elevenlabs" ? "ElevenLabs" : "Piper TTS"}
+ {provider === "elevenlabs" && ` • ${ELEVENLABS_MODELS.find((m) => m.id === elevenLabsModel)?.label ?? elevenLabsModel}`}
</p>
</div>
);
diff --git a/apps/web/src/stores/settings-store.ts b/apps/web/src/stores/settings-store.ts
index 46ad3d3d..483af9ac 100644
--- a/apps/web/src/stores/settings-store.ts
+++ b/apps/web/src/stores/settings-store.ts
@@ -55,6 +55,8 @@ export interface SettingsState {
defaultTtsProvider: string;
defaultLlmProvider: string;
defaultAggregator: string;
+ elevenLabsModel: string;
+ favoriteVoices: Array<{ voiceId: string; name: string; previewUrl?: string }>;
configuredServices: string[]; // IDs of services with stored API keys
// Settings dialog state
@@ -68,6 +70,9 @@ export interface SettingsState {
setDefaultTtsProvider: (provider: string) => void;
setDefaultLlmProvider: (provider: string) => void;
setDefaultAggregator: (provider: string) => void;
+ setElevenLabsModel: (model: string) => void;
+ addFavoriteVoice: (voice: { voiceId: string; name: string; previewUrl?: string }) => void;
+ removeFavoriteVoice: (voiceId: string) => void;
addConfiguredService: (serviceId: string) => void;
removeConfiguredService: (serviceId: string) => void;
openSettings: (tab?: string) => void;
@@ -85,6 +90,8 @@ export const useSettingsStore = create<SettingsState>()(
defaultTtsProvider: "elevenlabs",
defaultLlmProvider: "openai",
defaultAggregator: "kie-ai",
+ elevenLabsModel: "eleven_multilingual_v2",
+ favoriteVoices: [],
configuredServices: [],
settingsOpen: false,
@@ -106,6 +113,21 @@ export const useSettingsStore = create<SettingsState>()(
setDefaultAggregator: (provider: string) =>
set({ defaultAggregator: provider }),
+ setElevenLabsModel: (model: string) =>
+ set({ elevenLabsModel: model }),
+
+ addFavoriteVoice: (voice) => {
+ const { favoriteVoices } = get();
+ if (!favoriteVoices.some((v) => v.voiceId === voice.voiceId)) {
+ set({ favoriteVoices: [...favoriteVoices, voice] });
+ }
+ },
+
+ removeFavoriteVoice: (voiceId: string) => {
+ const { favoriteVoices } = get();
+ set({ favoriteVoices: favoriteVoices.filter((v) => v.voiceId !== voiceId) });
+ },
+
addConfiguredService: (serviceId: string) => {
const { configuredServices } = get();
if (!configuredServices.includes(serviceId)) {
@@ -138,6 +160,8 @@ export const useSettingsStore = create<SettingsState>()(
defaultTtsProvider: state.defaultTtsProvider,
defaultLlmProvider: state.defaultLlmProvider,
defaultAggregator: state.defaultAggregator,
+ elevenLabsModel: state.elevenLabsModel,
+ favoriteVoices: state.favoriteVoices,
configuredServices: state.configuredServices,
}),
},