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[kokoro-app] --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.0.tar.gz (21.4 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.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sinapsis_kokoro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d22e2bdf61bdd75f0dd589f8c0f36769333ec9f8c5b48303272db3470b4853f5
MD5 571a7f95f413b6a43f6a122d22aefc30
BLAKE2b-256 744764a3107d21774afafaa2ebfa9191b99779a6eedf10d47a6b35007fd117d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sinapsis_kokoro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccfb7a55ed006f7f94d2bd6ee35c6ed5f2b9c5092b8d2b3db0ca514522e65e38
MD5 4e4f68c30b167d8babcab4b8ce934879
BLAKE2b-256 db8345904e833a709a2be28035bc5b4112eac30ea231ffad6700a0909d776d71

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