KokoroSharp.CPU
0.8.1
dotnet add package KokoroSharp.CPU --version 0.8.1
NuGet\Install-Package KokoroSharp.CPU -Version 0.8.1
<PackageReference Include="KokoroSharp.CPU" Version="0.8.1" />
<PackageVersion Include="KokoroSharp.CPU" Version="0.8.1" />
<PackageReference Include="KokoroSharp.CPU" />
paket add KokoroSharp.CPU --version 0.8.1
#r "nuget: KokoroSharp.CPU, 0.8.1"
#:package KokoroSharp.CPU@0.8.1
#addin nuget:?package=KokoroSharp.CPU&version=0.8.1
#tool nuget:?package=KokoroSharp.CPU&version=0.8.1
https://github.com/user-attachments/assets/82a32382-2e9b-4233-a66f-987b2802717e
KokoroSharp
KokoroSharp is a fully-featured inference engine for Kokoro TTS, built entirely in C# with ONNX runtime. It enables developers to perform flexible and fast text-to-speech synthesis utilizing multiple speakers and languages.
Features
- Plug & Play integration via the nuget package. All dependencies are handled automatically.
- Nuget package includes ALL voices released by hexgrad with their Kokoro 82M v1.0 and v1.1-zh releases.
- High-level interface designed to suit both beginners and power users.
- Text-segment streaming for seamless text-to-speech. Responses feel instant.
- Voice mixing with no restrictions on the amounts of voices mixed, and ability to save/load mixed voices.
- Linear job scheduling with background worker as dispatcher.
- Optional multi-platform playback support with pre-integrated audio queue handling.
Supports languages/accents:
[American English, British English, MandarinChinese, Japanese, Hindi, Spanish, French, Italian, Brazilian/Portuguese].
How to setup
- On Windows, Linux, and MacOS: Install via Nuget (Package Manager or CLI), and you're set!
- Selecting the correct package: KokoroSharp.CPU is plug-and-play. For GPU support, see RUNNING_ON_GPU.md.
- On Other platforms: KokoroSharp should work on mobile as of v0.8.1, as long as the model gets downloaded appropriately. Requires more testing though.
Getting started with the KokoroSharp.CPU package:
KokoroTTS tts = KokoroTTS.LoadModel(); // Load or download the model (~320MB for full precision)
KokoroVoice heartVoice = KokoroVoiceManager.GetVoice("af_heart"); // Grab a voice of your liking,
while (true) { tts.SpeakFast(Console.ReadLine(), heartVoice); } // .. and have it speak your text!
// Note: Language detection is automated based on what the loaded voice supports.
For running on GPU, check out RUNNING_ON_GPU.md.
Above is a simple way to get started on the highest level. For more control, check out the example Program, which covers more advanced parts like job scheduling, voice mixing, and long-term, speaker-agnostic playback queuing.
Models can be found on KokoroSharpBinaries' releases, and can be loaded via KokoroTTS.LoadModel("path/to/model"), or downloaded automatically with KokoroTTS.LoadModel(). Check out the various overloads of KokoroTTS.LoadModel for background loading.
Kokoro v1.1-zh (Chinese model & voices)
KokoroTTS tts = KokoroTTS.LoadModel(KModel.zh_float32); // Load or download the Kokoro v1.1-zh model,
tts.SpeakFast("你好,世界!", KokoroVoiceManager.GetVoice("zf_001")); // .. and speak with any of its voices!
The v1.1-zh voices come bundled with the package in voices/voices-zh, loaded automatically alongside the v1.0 ones.
Notes
KokoroSharp prioritizes a smooth developer experience by logging potential misuse instead of throwing exceptions. Wherever possible, the library attempts to automatically resolve issues to minimize disruptions.
All communication with the AI model and playback devices happens on background threads, letting the main thread focus on rendering the UI in peace. The library is carefully designed with thread-safety in mind.
The
voicesfolder is automatically copied to your build path when you build and is ready to be accessed. Developers may opt to remove it when shipping their apps.Mind that
LoadVoicesFromPathexists as an option, in case developers want to implement their custom voice-loading logic when shipping a project that utilizes KokoroSharp for text-to-speech synthesis.In addition, the built-in tokenization (
text -> tokens) is NOT mandatory, and can be bypassed for platforms likeAndroid/iOS, given developers provide pre-phonemized input with their phonemization solution of choice.
License
- This project is licensed under the MIT License.
- The Kokoro 82M model and its voices are released under the Apache License.
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- KokoroSharp (>= 0.8.1)
- Microsoft.ML.OnnxRuntime (>= 1.22.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on KokoroSharp.CPU:
| Package | Downloads |
|---|---|
|
ElBruno.KokoroTTS.Realtime
Bridge between KokoroSharp and ElBruno.Realtime — provides ITextToSpeechClient adapter and DI extensions for Kokoro TTS integration with the real-time conversation pipeline. |
GitHub repositories
This package is not used by any popular GitHub repositories.