Text to Dialogue quickstart

Learn how to generate immersive dialogue from text.

This guide will show you how to generate immersive, natural-sounding dialogue from text using the Text to Dialogue API.

Using the Text to Dialogue 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
3

Make the API request

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
5
6load_dotenv()
7
8elevenlabs = ElevenLabs(
9 api_key=os.getenv("ELEVENLABS_API_KEY"),
10)
11
12audio = elevenlabs.text_to_dialogue.convert(
13 inputs=[
14 {
15 "text": "[cheerfully] Hello, how are you?",
16 "voice_id": "9BWtsMINqrJLrRacOk9x",
17 },
18 {
19 "text": "[stuttering] I'm... I'm doing well, thank you",
20 "voice_id": "IKne3meq5aSn9XLyUdCD",
21 }
22 ]
23)
24
25play(audio)
4

Execute the code

1python example.py

You should hear the dialogue audio play.

Next steps

Explore the API reference for more information on the Text to Dialogue API and its options.