Module livekit.plugins.elevenlabs
Classes
class TTS (*, voice: Voice = Voice(id='EXAVITQu4vr4xnSDxMaL', name='Bella', category='premade', settings=VoiceSettings(stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True)), model_id: TTSModels = 'eleven_turbo_v2_5', api_key: str | None = None, base_url: str | None = None, encoding: TTSEncoding = 'mp3_22050_32', streaming_latency: int = 3, word_tokenizer: tokenize.WordTokenizer = <livekit.agents.tokenize.basic.WordTokenizer object>, enable_ssml_parsing: bool = False, chunk_length_schedule: list[int] = [80, 120, 200, 260], http_session: aiohttp.ClientSession | None = None)
-
Helper class that provides a standard way to create an ABC using inheritance.
Create a new instance of ElevenLabs TTS.
api_key
must be set to your ElevenLabs API key, either using the argument or by setting theELEVEN_API_KEY
environmental variable.Expand source code
class TTS(tts.TTS): def __init__( self, *, voice: Voice = DEFAULT_VOICE, model_id: TTSModels = "eleven_turbo_v2_5", api_key: str | None = None, base_url: str | None = None, encoding: TTSEncoding = "mp3_22050_32", streaming_latency: int = 3, word_tokenizer: tokenize.WordTokenizer = tokenize.basic.WordTokenizer( ignore_punctuation=False # punctuation can help for intonation ), enable_ssml_parsing: bool = False, chunk_length_schedule: list[int] = [80, 120, 200, 260], # range is [50, 500] http_session: aiohttp.ClientSession | None = None, ) -> None: """ Create a new instance of ElevenLabs TTS. ``api_key`` must be set to your ElevenLabs API key, either using the argument or by setting the ``ELEVEN_API_KEY`` environmental variable. """ super().__init__( capabilities=tts.TTSCapabilities( streaming=True, ), sample_rate=_sample_rate_from_format(encoding), num_channels=1, ) api_key = api_key or os.environ.get("ELEVEN_API_KEY") if not api_key: raise ValueError("ELEVEN_API_KEY must be set") self._opts = _TTSOptions( voice=voice, model_id=model_id, api_key=api_key, base_url=base_url or API_BASE_URL_V1, encoding=encoding, sample_rate=self.sample_rate, streaming_latency=streaming_latency, word_tokenizer=word_tokenizer, chunk_length_schedule=chunk_length_schedule, enable_ssml_parsing=enable_ssml_parsing, ) self._session = http_session def _ensure_session(self) -> aiohttp.ClientSession: if not self._session: self._session = utils.http_context.http_session() return self._session async def list_voices(self) -> List[Voice]: async with self._ensure_session().get( f"{self._opts.base_url}/voices", headers={AUTHORIZATION_HEADER: self._opts.api_key}, ) as resp: return _dict_to_voices_list(await resp.json()) def synthesize(self, text: str) -> "ChunkedStream": return ChunkedStream(text, self._opts, self._ensure_session()) def stream(self) -> "SynthesizeStream": return SynthesizeStream(self._ensure_session(), self._opts)
Ancestors
- TTS
- abc.ABC
Methods
async def list_voices(self) ‑> List[livekit.plugins.elevenlabs.tts.Voice]
def stream(self) ‑> livekit.plugins.elevenlabs.tts.SynthesizeStream
def synthesize(self, text: str) ‑> livekit.plugins.elevenlabs.tts.ChunkedStream
class Voice (id: str, name: str, category: str, settings: VoiceSettings | None = None)
-
Voice(id: 'str', name: 'str', category: 'str', settings: 'VoiceSettings | None' = None)
Expand source code
@dataclass class Voice: id: str name: str category: str settings: VoiceSettings | None = None
Class variables
var category : str
var id : str
var name : str
var settings : livekit.plugins.elevenlabs.tts.VoiceSettings | None
class VoiceSettings (stability: float, similarity_boost: float, style: float | None = None, use_speaker_boost: bool | None = False)
-
VoiceSettings(stability: 'float', similarity_boost: 'float', style: 'float | None' = None, use_speaker_boost: 'bool | None' = False)
Expand source code
@dataclass class VoiceSettings: stability: float # [0.0 - 1.0] similarity_boost: float # [0.0 - 1.0] style: float | None = None # [0.0 - 1.0] use_speaker_boost: bool | None = False
Class variables
var similarity_boost : float
var stability : float
var style : float | None
var use_speaker_boost : bool | None