The ElevenLabs API provides a simple interface to state-of-the-art audio models and features. Follow this guide to learn how to create lifelike speech, generate and modify voices, produce immersive sound effects, isolate background noise from audio, and seamlessly dub audio/videos.
Create an API key in the dashboard here, which you’ll use to securely access the API. Store the key in a safe location, like a .zshrc file or another text file on your computer. Once you’ve generated an API key, export it as an environment variable in your terminal.
Export an environment variable on macOS or Linux systems
Copy
Ask AI
export ELEVENLABS_API_KEY="your_api_key_here"
Export an environment variable on macOS or Linux systems
With your ElevenLabs API key exported as an environment variable, you’re ready to make your first API request. You can either use the REST API directly with the HTTP client of your choice, or use one of our official SDKs as shown below.
To use the ElevenLabs API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official ElevenLabs SDK for TypeScript and JavaScript. Get started by installing the SDK using npm or your preferred package manager:
Install the ElevenLabs SDK with npm
Copy
Ask AI
npm install elevenlabs
To play the audio through your speakers, you may be prompted to install MPV and/or ffmpeg.
With the ElevenLabs SDK installed, create a file called example.mjs and copy one of the following examples into it:
Convert text into life-like audio
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";const client = new ElevenLabsClient();const audio = await client.textToSpeech.convert("JBFqnCBsd6RMkjVDRZzb", { text: "The first move is what sets everything in motion.", model_id: "eleven_multilingual_v2", output_format: "mp3_44100_128",});await play(audio);
Convert text into life-like audio
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";const client = new ElevenLabsClient();const audio = await client.textToSpeech.convert("JBFqnCBsd6RMkjVDRZzb", { text: "The first move is what sets everything in motion.", model_id: "eleven_multilingual_v2", output_format: "mp3_44100_128",});await play(audio);
Transform audio from one voice to another
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import fetch from "node-fetch";const client = new ElevenLabsClient();const voiceId = "JBFqnCBsd6RMkjVDRZzb";const audioUrl = "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3";const response = await fetch(audioUrl);const audioBlob = new Blob([await response.arrayBuffer()], { type: "audio/mp3" });const audioStream = await client.speechToSpeech.convert(voiceId, { audio: audioBlob, model_id: "eleven_multilingual_sts_v2", output_format: "mp3_44100_128",});await play(audioStream);
Convert text into sound effects
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";const client = new ElevenLabsClient();const audio = await client.textToSoundEffects.convert({ text: "Cinematic Braam, Horror",});await play(audio);
Removes background noise from audio.
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import fetch from "node-fetch";const client = new ElevenLabsClient();const audioUrl = "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/fin.mp3";const response = await fetch(audioUrl);const audioBlob = new Blob([await response.arrayBuffer()], { type: "audio/mp3",});const audioStream = await client.audioIsolation.audioIsolation({ audio: audioBlob,});await play(audioStream);
Generate voices from a single text prompt.
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import { Readable } from "stream";const client = new ElevenLabsClient();const voices = await client.textToVoice.createPreviews({ voice_description: "A sassy squeaky mouse", text: "Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.",});const voicePreview1 = voices.previews[0].audio_base_64;await play(Readable.from(Buffer.from(voicePreview1, "base64")));
Dub audio/video from one language to another
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import fetch from "node-fetch";const client = new ElevenLabsClient();const targetLang = "es"; // spanishconst sourceAudio = await fetch( "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3");const audioBlob = new Blob([await sourceAudio.arrayBuffer()], { type: "audio/mp3",});// Start dubbingconst dubbed = await client.dubbing.dubAVideoOrAnAudioFile({ file: audioBlob, target_lang: targetLang,});while (true) { const { status } = await client.dubbing.getDubbingProjectMetadata( dubbed.dubbing_id ); if (status === "dubbed") { const dubbedFile = await client.dubbing.getDubbedFile( dubbed.dubbing_id, targetLang ); await play(dubbedFile); break; } else { console.log("Audio is still being dubbed..."); } await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds between checks}
Execute the code with node example.mjs (or the equivalent command for Deno or Bun). In a few seconds, you should hear the audio play through your speaker.
To use the ElevenLabs API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official ElevenLabs SDK for TypeScript and JavaScript. Get started by installing the SDK using npm or your preferred package manager:
Install the ElevenLabs SDK with npm
Copy
Ask AI
npm install elevenlabs
To play the audio through your speakers, you may be prompted to install MPV and/or ffmpeg.
With the ElevenLabs SDK installed, create a file called example.mjs and copy one of the following examples into it:
Convert text into life-like audio
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";const client = new ElevenLabsClient();const audio = await client.textToSpeech.convert("JBFqnCBsd6RMkjVDRZzb", { text: "The first move is what sets everything in motion.", model_id: "eleven_multilingual_v2", output_format: "mp3_44100_128",});await play(audio);
Convert text into life-like audio
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";const client = new ElevenLabsClient();const audio = await client.textToSpeech.convert("JBFqnCBsd6RMkjVDRZzb", { text: "The first move is what sets everything in motion.", model_id: "eleven_multilingual_v2", output_format: "mp3_44100_128",});await play(audio);
Transform audio from one voice to another
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import fetch from "node-fetch";const client = new ElevenLabsClient();const voiceId = "JBFqnCBsd6RMkjVDRZzb";const audioUrl = "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3";const response = await fetch(audioUrl);const audioBlob = new Blob([await response.arrayBuffer()], { type: "audio/mp3" });const audioStream = await client.speechToSpeech.convert(voiceId, { audio: audioBlob, model_id: "eleven_multilingual_sts_v2", output_format: "mp3_44100_128",});await play(audioStream);
Convert text into sound effects
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";const client = new ElevenLabsClient();const audio = await client.textToSoundEffects.convert({ text: "Cinematic Braam, Horror",});await play(audio);
Removes background noise from audio.
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import fetch from "node-fetch";const client = new ElevenLabsClient();const audioUrl = "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/fin.mp3";const response = await fetch(audioUrl);const audioBlob = new Blob([await response.arrayBuffer()], { type: "audio/mp3",});const audioStream = await client.audioIsolation.audioIsolation({ audio: audioBlob,});await play(audioStream);
Generate voices from a single text prompt.
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import { Readable } from "stream";const client = new ElevenLabsClient();const voices = await client.textToVoice.createPreviews({ voice_description: "A sassy squeaky mouse", text: "Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.",});const voicePreview1 = voices.previews[0].audio_base_64;await play(Readable.from(Buffer.from(voicePreview1, "base64")));
Dub audio/video from one language to another
Copy
Ask AI
import { ElevenLabsClient, play } from "elevenlabs";import fetch from "node-fetch";const client = new ElevenLabsClient();const targetLang = "es"; // spanishconst sourceAudio = await fetch( "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3");const audioBlob = new Blob([await sourceAudio.arrayBuffer()], { type: "audio/mp3",});// Start dubbingconst dubbed = await client.dubbing.dubAVideoOrAnAudioFile({ file: audioBlob, target_lang: targetLang,});while (true) { const { status } = await client.dubbing.getDubbingProjectMetadata( dubbed.dubbing_id ); if (status === "dubbed") { const dubbedFile = await client.dubbing.getDubbedFile( dubbed.dubbing_id, targetLang ); await play(dubbedFile); break; } else { console.log("Audio is still being dubbed..."); } await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds between checks}
Execute the code with node example.mjs (or the equivalent command for Deno or Bun). In a few seconds, you should hear the audio play through your speaker.
To use the ElevenLabs API in Python, you can use the official ElevenLabs SDK for Python. Get started by installing the SDK using pip:
Install the ElevenLabs SDK with pip
Copy
Ask AI
pip install elevenlabs
To play the audio through your speakers, you may be prompted to install MPV and/or ffmpeg.
With the ElevenLabs SDK installed, create a file called example.py and copy one of the following examples into it:
Convert text into life-like audio
Copy
Ask AI
from elevenlabs.client import ElevenLabsfrom elevenlabs import playclient = ElevenLabs()audio = client.text_to_speech.convert( text="The first move is what sets everything in motion.", voice_id="JBFqnCBsd6RMkjVDRZzb", model_id="eleven_multilingual_v2", output_format="mp3_44100_128",)play(audio)
Convert text into life-like audio
Copy
Ask AI
from elevenlabs.client import ElevenLabsfrom elevenlabs import playclient = ElevenLabs()audio = client.text_to_speech.convert( text="The first move is what sets everything in motion.", voice_id="JBFqnCBsd6RMkjVDRZzb", model_id="eleven_multilingual_v2", output_format="mp3_44100_128",)play(audio)
import base64from elevenlabs.client import ElevenLabsfrom elevenlabs import playclient = ElevenLabs()voices = client.text_to_voice.create_previews( voice_description="A sassy squeaky mouse", text="Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.",)voice_preview = voices.previews[0].audio_base_64audio_bytes = base64.b64decode(voice_preview)play(audio_bytes)
Dub audio/video from one language to another
Copy
Ask AI
from elevenlabs.client import ElevenLabsfrom elevenlabs import playimport requestsfrom io import BytesIOimport timeclient = ElevenLabs()target_lang = "es" # Spanishaudio_url = ( "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3")response = requests.get(audio_url)audio_data = BytesIO(response.content)audio_data.name = "audio.mp3"# Start dubbingdubbed = client.dubbing.dub_a_video_or_an_audio_file( file=audio_data, target_lang=target_lang)while True: status = client.dubbing.get_dubbing_project_metadata(dubbed.dubbing_id).status if status == "dubbed": dubbed_file = client.dubbing.get_dubbed_file(dubbed.dubbing_id, target_lang) play(dubbed_file) break else: print("Audio is still being dubbed...") time.sleep(5)
Execute the code with python example.py. In a few seconds, you should hear the audio play through your speaker.