List ElevenLabs Voices
Fetch available voices from ElevenLabs API for selection
Source Code
const apiKey = "15fd8afd4509c340bf5af364d6fd32a2a8728b0eaa658a1c1323da68477ab804";
const [search = "", voiceType = "", pageSize = "30"] = process.argv.slice(2);
async function main() {
const params = new URLSearchParams();
params.set("page_size", pageSize);
if (search && search.trim()) {
params.set("search", search.trim());
}
if (voiceType && voiceType.trim()) {
params.set("voice_type", voiceType.trim());
}
const url = `https://api.elevenlabs.io/v1/voices/search?${params.toString()}`;
console.log("Fetching voices from ElevenLabs...");
const response = await fetch(url, {
method: "GET",
headers: {
"xi-api-key": apiKey,
},
});
if (!response.ok) {
const errorText = await response.text();
console.error(`API error (${response.status}): ${errorText}`);
process.exit(1);
}
const data = await response.json();
const voices = data.voices.map((v) => ({
id: v.voice_id,
name: v.name,
description: v.description || "",
category: v.category || "unknown",
labels: v.labels || {},
previewUrl: v.preview_url || null,
}));
console.log(`Found ${voices.length} voices`);
console.log(JSON.stringify(voices, null, 2));
}
main().catch((err) => {
console.error("Error:", err.message);
process.exit(1);
});