Skip to main content

Generate realistic voices from text, other speeches, and more using the Elevenlabs library.

Project description



Sinapsis Elevenlabs

Templates for advanced speech generation with Elevenlabs

🐍 Installation 🚀 Features 📚 Usage example🌐 Webapp📙 Documentation🔍 License

This Sinapsis Elevenlabs package offers a suite of templates and utilities designed for effortless integrating, configuration, and execution of text-to-speech (TTS) and voice generation functionalities powered by ElevenLabs.

🐍 Installation

[!IMPORTANT] Sinapsis project requires Python 3.10 or higher.

Install using your favourite package manager. We strongly encourage the use of uv, although any other package manager should work too. If you need to install uv please see the official documentation.

Example with uv:

  uv pip install sinapsis-elevenlabs --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-elevenlabs --extra-index-url https://pypi.sinapsis.tech

[!IMPORTANT] Templates in each package may require extra dependencies. For development, we recommend installing the package with all the optional dependencies:

with uv:

  uv pip install sinapsis-elevenlabs[all] --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-elevenlabs[all] --extra-index-url https://pypi.sinapsis.tech

🚀 Features

Templates Supported

  • ElevenLabsTTS: Template for converting text into speech using ElevenLabs' voice models.

    Attributes
    • api_key(Optional): The API key used to authenticate with ElevenLabs' API. Although this parameter is optional in the function signature, the API key must be provided either through this argument or the ELEVENLABS_API_KEY environmental variable. If neither is provided, an error will be logged, and no speech will be generated.
    • model(Optional): The model identifier to use for speech synthesis (default: eleven_turbo_v2_5eleven_turbo_v2_5). Options: eleven_turbo_v2_5, eleven_multilingual_v2, eleven_turbo_v2, eleven_monolingual_v1, eleven_multilingual_v1.
    • output_format(Optional): The output audio format and quality (default: mp3_44100_128). Options: mp3_22050_32, mp3_44100_32, mp3_44100_64, mp3_44100_96, mp3_44100_128, mp3_44100_192, pcm_16000, pcm_22050, pcm_24000, pcm_44100, ulaw_8000.
    • output_folder(Optional): The folder where generated audio files will be saved (default: SINAPSIS_CACHE_DIR/elevenlabs/ audios).
    • stream(Optional): If True, the audio is returned as a stream; otherwise, saved to a file (default: False).
    • voice(Optional): Voice for speech synthesis. Can be a voice ID (str), name (str), or ElevenLabs voice object (Voice) (default: None).
    • voice_settings(Optional):Dictionary of voice control settings:
      • stability: Controls voice randomness and emotional range (range: 0.0 to 1.0).
      • similarity_boost: Adjusts how closely the voice matches the original (range: 0.0 to 1.0).
      • style: Amplifies the speaker’s style, consuming more resources (range: 0.0 to 1.0).
      • use_speaker_boost: Increases similarity to the speaker with higher computational cost (boolean: True or False).
      • speed: Adjusts speech speed (range: 0.7 to 1.2, default: 1.0).
  • ElevenLabsVoiceGeneration: Template for generating custom synthetic voices based on user-provided descriptions.

    Attributes
    • api_key(Optional): The API key used to authenticate with ElevenLabs' API. Although this parameter is optional in the function signature, the API key must be provided either through this argument or the ELEVENLABS_API_KEY environmental variable. If neither is provided, an error will be logged, and no speech will be generated.
    • model(Optional): The model identifier to use for speech synthesis (default: eleven_turbo_v2_5eleven_turbo_v2_5). Options: eleven_turbo_v2_5, eleven_multilingual_v2, eleven_turbo_v2, eleven_monolingual_v1, eleven_multilingual_v1.
    • output_format(Optional): The output audio format and quality (default: mp3_44100_128). Options: mp3_22050_32, mp3_44100_32, mp3_44100_64, mp3_44100_96, mp3_44100_128, mp3_44100_192, pcm_16000, pcm_22050, pcm_24000, pcm_44100, ulaw_8000.
    • output_folder(Optional): The folder where generated audio files will be saved (default: SINAPSIS_CACHE_DIR/elevenlabs/ audios).
    • stream(Optional): If True, the audio is returned as a stream; otherwise, saved to a file (default: False).
    • voice(Optional): Voice for speech synthesis. Can be a voice ID (str), name (str), or ElevenLabs voice object (Voice) (default: None).
    • voice_description(Required): A description of the voice to be used for synthesis. This field is mandatory and helps to define the voice's characteristics or style.
    • voice_settings(Optional):Dictionary of voice control settings:
      • stability: Controls voice randomness and emotional range (range: 0.0 to 1.0).
      • similarity_boost: Adjusts how closely the voice matches the original (range: 0.0 to 1.0).
      • style: Amplifies the speaker’s style, consuming more resources (range: 0.0 to 1.0).
      • use_speaker_boost: Increases similarity to the speaker with higher computational cost (boolean: True or False).
      • speed: Adjusts speech speed (range: 0.7 to 1.2, default: 1.0).

[!TIP] Use CLI command sinapsis info --example-template-config TEMPLATE_NAME to produce an example Agent config for the Template specified in TEMPLATE_NAME.

For example, for ElevenLabsTTS use sinapsis info --example-template-config ElevenLabsTTS to produce an example config like:

agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: ElevenLabsTTS
  class_name: ElevenLabsTTS
  template_input: InputTemplate
  attributes:
    api_key: null
    voice: null
    voice_settings:
      stability: null
      similarity_boost: null
      style: null
      use_speaker_boost: null
      speed: null
    model: eleven_turbo_v2_5
    output_format: mp3_44100_128
    output_folder: ~/.cache/sinapsis/elevenlabs/audios
    stream: false

📚 Usage example

This example shows how to use the ElevenLabsVoiceGeneration template to convert text into speech. It generates speech based on a voice created from the user's description and saves the resulting audio file locally.

Config
agent:
  name: voice_creation
  description: voice generation agent using Elevenlabs

templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}

- template_name: TextInput
  class_name: TextInput
  template_input: InputTemplate
  attributes:
    text: En la oscuridad de la noche, se escuchaban los llantos lejanos de una mujer. Nadie sabía exactamente de dónde venían, pero todos los habitantes del pueblo aseguraban que era el llanto de La Llorona. Se decía que era el espíritu de una mujer que, en vida, había perdido a sus hijos y que, condenada por su dolor y su culpa, deambulaba por las orillas de los ríos buscando a sus pequeños. Nadie se atrevía a acercarse al agua cuando oían su llanto, pues sabían que, si la escuchabas cerca, su destino también estaba sellado...

- template_name: ElevenLabsVoiceGeneration
  class_name: ElevenLabsVoiceGeneration
  template_input: TextInput
  attributes:
    voice_description: A warm and engaging Mexican Spanish female voice, perfect for storytelling, audiobooks, and podcasts. Clear and expressive, with a natural, captivating tone, ideal for social media, YouTube, TikTok, and more.

This configuration defines an agent and a sequence of templates for speech synthesis, using a custom voice created through ElevenLabs.

[!IMPORTANT] The TextInput template correspond to sinapsis-data-readers. If you want to use the example, please make sure you install the package.

To run the config, use the CLI:

sinapsis run name_of_config.yml

🌐 Webapp

The webapps included in this project showcase the modularity of the ElevenLabs templates, in this case for speech generation tasks.

[!IMPORTANT] To run the app you first need to clone this repository:

git clone git@github.com:Sinapsis-ai/sinapsis-speech.git
cd sinapsis-speech

[!NOTE] If you'd like to enable external app sharing in Gradio, export GRADIO_SHARE_APP=True

[!IMPORTANT] Elevenlabs requires an API key to run any inference. To get started, visit the official website and create an account. If you already have an account, go to the API keys page to generate a token.

[!IMPORTANT] Set your env var using export ELEVENLABS_API_KEY='your-api-key'

🐳 Docker

IMPORTANT This docker image depends on the sinapsis-nvidia:base image. Please refer to the official sinapsis instructions to Build with Docker.

  1. Build the sinapsis-speech image:
docker compose -f docker/compose.yaml build
  1. Start the app container:
docker compose -f docker/compose_apps.yaml up -d sinapsis-elevenlabs
  1. Check the logs
docker logs -f sinapsis-elevenlabs
  1. The logs will display the URL to access the webapp, e.g.,::
Running on local URL:  http://127.0.0.1:7860

NOTE: The url may be different, check the output of logs.

  1. To stop the app:
docker compose -f docker/compose_apps.yaml down
💻 UV

To run the webapp using the uv package manager, follow these steps:

  1. Sync the virtual environment:
uv sync --frozen
  1. Install the wheel:
uv pip install sinapsis-speech[all] --extra-index-url https://pypi.sinapsis.tech
  1. Run the webapp:
uv run webapps/elevenlabs/elevenlabs_tts_app.py
  1. The terminal will display the URL to access the webapp (e.g.):
Running on local URL:  http://127.0.0.1:7860

NOTE: The URL may vary; check the terminal output for the correct address.

📙 Documentation

Documentation is available on the sinapsis website

Tutorials for different projects within sinapsis are available at sinapsis tutorials page

🔍 License

This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.

For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sinapsis_elevenlabs-0.1.1.tar.gz (50.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sinapsis_elevenlabs-0.1.1-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file sinapsis_elevenlabs-0.1.1.tar.gz.

File metadata

  • Download URL: sinapsis_elevenlabs-0.1.1.tar.gz
  • Upload date:
  • Size: 50.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.16

File hashes

Hashes for sinapsis_elevenlabs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0e7b69de178c60a5c5954dc1c543ea1fb5ccff6865f44889d904a92041de3684
MD5 29bbc4b5bc10adfc4bf6266601bddc7d
BLAKE2b-256 08f733d39be72abaee62f8fde056e32de48025e89ec9a3a6a16a33e348c0b9a1

See more details on using hashes here.

File details

Details for the file sinapsis_elevenlabs-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sinapsis_elevenlabs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b858fa17cff41a522af7582a08dc5109fb12b55ce2087351ce127e076fb7500
MD5 2a1c6df34ac7f7a08026e093b1b6dd23
BLAKE2b-256 0bf47bcb27c176f982e844950f2402e59dad635b7f2d8c8e978b4f06653cdf03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page