Skip to main content

Text to speech using Kokoro TTS model

Project description

sp



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.11.tar.gz (22.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_kokoro-0.1.11-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sinapsis_kokoro-0.1.11.tar.gz
Algorithm Hash digest
SHA256 2ccf33a7aae31ad257552ff5ad28a40f457e96bc985ec99100a5a5b8eddef51b
MD5 fd74faeba098a3fb55b116be0aface71
BLAKE2b-256 0e4cf35c4b641fc6ba3158550fee16898a425db198f905073b964d58704eb16a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sinapsis_kokoro-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 0e8da13245f988fc101fd81cb044ca54fa1a6aa891662a03fbff37bdde9d408f
MD5 4a14f2f7ce5b189bc95d914961b3068d
BLAKE2b-256 d7c7340210bd868c76ee18c710dd5d3891b6303d2e93c5e2be144178190df734

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