#how do i use the voices via api

1 messages · Page 1 of 1 (latest)

kind willowBOT
#
AI-generated Answer for unrepped_82061

To use voices via the API, you can follow these steps:

  1. Retrieve Available Voices: Use the Get Voices endpoint to fetch the list of voices available in your account. Here's an example in JavaScript:

    const { ElevenLabsClient } = require("elevenlabs");
    
    const client = new ElevenLabsClient({
        apiKey: "YOUR_API_KEY"
    });
    
    async function getVoices() {
        try {
            const voices = await client.voices.getAll();
            console.log('Voices:', voices);
            return voices;
        } catch (error) {
            console.error('Error on getting voices:', error);
            throw error;
        }
    }
    
    getVoices();
    
  2. Include Legacy Voices (Optional): If you need to include legacy voices, update the request like this:

    const voices = await client.voices.getAll({ show_legacy: true });
    
  3. Verify API Key and Account: Ensure your API key is correctly set in your code and linked to your account. You can test this by generating a short sentence using the text-to-speech endpoint and checking if it appears in your account's history.

  4. Access Shared Voices: If you want to use shared voices, ensure they are saved in your library first. You can do this by using the "Get Shared Voices" call and saving the desired voices to your library.

  5. Voice IDs: To find the IDs of voices saved in your library, you can either use the API's Get Voices endpoint or locate them in the Voice Library via the UI by navigating to "My Voices," clicking "View" for the desired voice, and copying the ID from the panel.

Make sure not to share your API key for security purposes. If you encounter issues, double-check that your account is properly linked and that the voice you want to use is saved in your library.

brisk dove
#

i need more help