Skip to main content

Text to speech using Kokoro TTS model

Project description



Sinapsis Kokoro

Templates for advanced text-to-speech synthesis using the Kokoro 82M v1.0 model

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

This Sinapsis Kokoro package package provides a single template for integrating, configuring, and running text-to-speech (TTS) functionalities powered by Kokoro.

🐍 Installation

Install using your preferred package manager. We strongly recommend using uv. To install uv, refer to the official documentation.

Install with uv:

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

Or with raw pip:

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

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

With uv:

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

or with raw pip:

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

[!NOTE] Zonos depends on the eSpeak library phonemization. The installation depends on your OS. For Linux:

apt install -y espeak-ng

🚀 Features

Templates Supported

This module includes a template for text-to-speech synthesis using the Kokoro TTS model:

  • KokoroTTS: Converts text to speech using the Kokoro TTS model. The template processes text packets from the input container, generates corresponding audio using Kokoro, and adds the resulting audio packets to the container.

    Attributes
    • speed (Optional): The speed at which the speech will be generated (default: 1).
    • split_pattern (Optional): The regular expression pattern used to split the input text into smaller chunks (default: r"\+").
    • voice (Optional): The voice model to use for speech synthesis (default:af_heart).

    The list of languages and voices supported by Kokoro can be found here

[!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 KokoroTTS use sinapsis info --example-template-config KokoroTTS to produce an example config like:

agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: KokoroTTS
  class_name: KokoroTTS
  template_input: InputTemplate
  attributes:
    speed: 1
    split_pattern: \n+
    voice: af_heart

📚 Usage example

This example illustrates how to use the KokoroTTS template for text-to-speech synthesis. It converts text input into speech using the Kokoro 82M v1.0 model and saves the resulting audio files locally.

Config
agent:
  name: kokoro_tts_agent
  description: "Agent that generates speech from text using the Kokoro-TTS model."

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

- template_name: TextInput
  class_name: TextInput
  template_input: InputTemplate
  attributes:
    text: "[Kokoro](/kˈOkəɹO/) is an open-weight TTS model with 82 million parameters. Despite its lightweight architecture, it delivers comparable quality to larger models while being significantly faster and more cost-efficient. With Apache-licensed weights, [Kokoro](/kˈOkəɹO/) can be deployed anywhere from production environments to personal projects."

- template_name: KokoroTTS
  class_name: KokoroTTS
  template_input: TextInput
  attributes:
    speed: 1
    voice: af_heart

- template_name: AudioWriterSoundfile
  class_name: AudioWriterSoundfile
  template_input: KokoroTTS
  attributes:
    save_dir: "kokoro_tts"
    extension: "wav"

This configuration defines an agent and a sequence of templates for converting text to speech using Kokoro.

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

To run the config, use the CLI:

sinapsis run name_of_config.yml

🌐 Webapp

The webapp included in this project showcases the modularity of the `KokoroTTS` template 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

🐳 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-kokoro
  1. Check the logs
docker logs -f sinapsis-kokoro
  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/packet_tts_apps/kokoro_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_kokoro-0.1.8.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

sinapsis_kokoro-0.1.8-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file sinapsis_kokoro-0.1.8.tar.gz.

File metadata

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

File hashes

Hashes for sinapsis_kokoro-0.1.8.tar.gz
Algorithm Hash digest
SHA256 18b8200288a73fde9b9ee92df6a8ad86af4bfc7942a68547c658361916e5ad94
MD5 acaeabaafa535d9ffd88513d69bf710e
BLAKE2b-256 848ac30f9ae88477b6f9eab7cfd44c36be45d66a678207ca7fa0d6f2327443ee

See more details on using hashes here.

File details

Details for the file sinapsis_kokoro-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for sinapsis_kokoro-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7fa4de7a6adacec546294b62683bb8ec83fa49bd3d1e6ece1b6b02dee7c8a6b8
MD5 2b93fff2c661481b160f1811a58cd86f
BLAKE2b-256 ae4a1d58a7f02e12926e69cf10cc335cc70d1c6cf3998611c7d1e65c90f6d696

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