Skip to main content

ElevenLabs ElevenLabs

The ElevenLabsTTSService provides the highest quality AI voices with emotional range and personality. It's the recommended TTS provider for premium, high-fidelity voice applications.

Installation

To use ElevenLabs, install the required dependencies:

pip install "piopiy-ai[elevenlabs]"

Prerequisites

  • An ElevenLabs account and API key (Get yours here).
  • Set your API key in your environment:
    export ELEVENLABS_API_KEY="your_api_key_here"

Configuration

ElevenLabsTTSService Parameters

ParameterTypeDefaultDescription
api_keystrRequiredYour ElevenLabs API key.
voice_idstr"pNInz6obpgmqMHCicJ4A"Voice ID (e.g., "Rachel").
modelstr"eleven_turbo_v2_5"Model ID for synthesis.
output_formatstr"pcm_16000"Audio format (e.g., "pcm_16000").

Usage

Basic Setup

import os
from piopiy.services.elevenlabs.tts import ElevenLabsTTSService

tts = ElevenLabsTTSService(
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id="pNInz6obpgmqMHCicJ4A", # Rachel
model="eleven_turbo_v2_5"
)

Notes

  • Latency: eleven_turbo_v2_5 is recommended for real-time voice agents due to its optimized latency and high quality.
  • Custom Voices: You can use your own cloned voices by providing their unique voice_id.
  • WebSocket Streaming: This service uses ElevenLabs' WebSocket API to stream audio as it's generated.