Voice Design quickstart

Learn how to design a voice via a prompt using the Voice Design API.

This guide will show you how to design a voice via a prompt using the Voice Design API.

Using the Voice Design API

1

Create an API key

Create an API key in the dashboard here, which you’ll use to securely access the API.

Store the key as a managed secret and pass it to the SDKs either as a environment variable via an .env file, or directly in your app’s configuration depending on your preference.

.env
1ELEVENLABS_API_KEY=<your_api_key_here>
2

Install the SDK

We’ll also use the dotenv library to load our API key from an environment variable.

1pip install elevenlabs
2pip install python-dotenv

To play the audio through your speakers, you may be prompted to install MPV and/or ffmpeg.

3

Make the API request

Designing a voice via a prompt has two steps:

  1. Generate previews based on a prompt.
  2. Select the best preview and use it to create a new voice.

We’ll start by generating previews based on a prompt.

Create a new file named example.py or example.mts, depending on your language of choice and add the following code:

1# example.py
2from dotenv import load_dotenv
3from elevenlabs.client import ElevenLabs
4from elevenlabs import play
5import base64
6
7load_dotenv()
8
9client = ElevenLabs(
10 api_key=os.getenv("ELEVENLABS_API_KEY"),
11)
12
13voices = client.text_to_voice.create_previews(
14 voice_description="A huge giant, at least as tall as a building. A deep booming voice, loud and jolly.",
15 text="Greetings little human. I am a mighty giant from a far away land. Would you like me to tell you a story?"
16)
17
18for preview in voices.previews:
19 # Convert base64 to audio buffer
20 audio_buffer = base64.b64decode(preview.audio_base_64)
21
22 print(f"Playing preview: {preview.generated_voice_id}")
23
24 play(audio_buffer)
4

Execute the code

1python example.py

You should hear the generated voice previews playing through your speakers, one at a time.

5

Add generated voice to your library

Once you’ve generated the previews and picked your favorite, you can add it to your voice library via the generated voice ID so it can be used with other APIs.

1voice = client.text_to_voice.create_voice_from_preview(
2 voice_name="Jolly giant",
3 voice_description="A huge giant, at least as tall as a building. A deep booming voice, loud and jolly.",
4 # The generated voice ID of the preview you want to use,
5 # using the first in the list for this example
6 generated_voice_id=voices.previews[0].generated_voice_id
7)
8
9print(voice.voice_id)

Next steps

Explore the API reference for more information on the Voice Design API and its options.