kokoro-onnx

repository·main·Indexed 25 days ago

https://github.com/thewh1teagle/kokoro-onnx

A lightweight, high-performance Text-to-Speech (TTS) library based on Kokoro-TTS that utilizes the ONNX runtime. It supports multiple languages and voices, offering near real-time performance on hardware such as macOS M1. The library provides the Kokoro class for audio generation via create() and create_stream(), as well as a Tokenizer for processing text into phonemes using espeak-ng.

Tokens
1.5K
Snippets
5
Records
20
Agent score
83%

What's inside kokoro-onnx

  1. Publish a new version to PyPI

    main

    To build and publish a new version of the package, clear the existing dist directory, build the package using uv build, and then publish using uv publish with a PyPI token.

    rm -rf dist
    uv build
    UV_PUBLISH_TOKEN="pypi token here" uv publish
  2. Set up kokoro-onnx using uv (Recommended)

    main

    For an isolated Python environment, use uv to manage the project and dependencies. Follow these steps:

    1. Install uv:
      pip install uv
    2. Initialize a new project with Python 3.12:
       ```console
    uv init -p 3.12
    1. Add the required dependencies:
      uv add kokoro-onnx soundfile
    4. Download the required model files (`kokoro-v1.0.onnx` and `voices-v1.0.bin`) and place them in your project directory.
    5. Run your script using `uv run`.
    
    ```console
    uv init -p 3.12
    uv add kokoro-onnx soundfile
    uv run hello.py
  3. Initialize the Tokenizer

    main

    The Tokenizer class processes text input for the TTS engine. You can initialize it with an optional EspeakConfig object to specify paths for the espeak-ng library and data, or a custom vocab dictionary.

    If no configuration is provided, it attempts to locate the espeak-ng library automatically. You can also control the library path by setting the PHONEMIZER_ESPEAK_LIBRARY environment variable.

  4. Stream audio chunks with create_stream()

    main

    For low-latency applications, use create_stream to asynchronously yield audio chunks as they are processed. This method runs the heavy computation in a background thread to avoid blocking the event loop.

    Parameters: Same as create().

    Returns:

    • An AsyncGenerator yielding (audio_numpy_array, sample_rate) tuples.