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.4.tar.gz (21.5 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.4-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sinapsis_kokoro-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f4c1986a2a39d71f20d83e26c7668d403974be755ad140b891b8fa7bd409ad7e
MD5 374df8afcee64af2d9b24cc095c0bbab
BLAKE2b-256 0a46cd0f6e84b9f48bbd399ef0cfbbe7440becc8c7d0ea7ea42b2986a1bf5be3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sinapsis_kokoro-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 64eaaa1e18e5af2dd4b15d714cb4d2383cc0fa5e2c3b3e24428bd36e53ad3c69
MD5 6e208d9b1075d9f4ecaf6773245ea92d
BLAKE2b-256 cbe02dfe4261a6c6559d23fed6b749c74cdcc2bc4be0e30e690da661193dc2b2

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