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.6.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.6-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sinapsis_kokoro-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 43a5bc47bdb1c2c9c990e0ff800b67af61a6bb74f0aceaced58f9c0b53568bc3
MD5 19183ff31146899af75b9779b54709f7
BLAKE2b-256 acdba46f07960ecba4fe6aa2b476d1107112d1a96abc68e6a18bf93eacaaff34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sinapsis_kokoro-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0e96f95aee30c5dc33473b98e9c1cc10af1f36b868756a5b25241d39317c0426
MD5 09433b82d4e44b3402b94d3f779f0780
BLAKE2b-256 121e22bdc8d78c7eb0bba224f4511810c83e8da764a5dd4ef336a9ac32fabdbb

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