Repository navigation
Running Kokoro voices on an NVIDIA GPU (optional patch, tested on 2.1.0) #78
jon333
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi! Thanks for TTSNative, I really like it. I wanted to share how I got the Kokoro voices running on my NVIDIA GPU instead of the CPU, in case it helps others or could become an option in the app.
Why Kokoro uses the CPU: TTSNative ships the CPU version of ONNX Runtime and asks only for the CPU (CPUExecutionProvider) in ltts/engines/kokoro.py. On my older CPU (i7-3770), Kokoro kept the processor at about 60% the whole time it was reading, with a short wait before each sentence.
What the patch does:
It downloads the GPU build of ONNX Runtime (onnxruntime-gpu 1.30.0, the same version TTSNative uses) plus the NVIDIA CUDA 13 and cuDNN 9 libraries, about 1.7 GB in total. They go into a separate folder, %LOCALAPPDATA%\TTSNative\gpu-kokoro\pkgs, and nothing is installed system-wide.
It changes ltts/onnx.py so that, if that folder exists, it loads the GPU build first and registers the CUDA library folders. If anything fails, it quietly falls back to the normal CPU build.
It changes ltts/engines/kokoro.py to ask for ["CUDAExecutionProvider", "CPUExecutionProvider"] when CUDA is available, and to log kokoro loaded providers=....
It backs up the originals as .reed-backup. One gotcha: the bundled pycache .pyc files are unchecked-hash files, so Python ignores the edited .py files until those are renamed. The patch moves them aside.
Result on my PC (RTX 3060, driver 616.64): Kokoro synthesis was about 9 times faster (1.2 s versus 10.7 s for 13 s of audio). CPU use dropped to almost nothing, and sentences start almost immediately.
Limits:
It only works on NVIDIA cards with a driver that supports CUDA 13 (version 580 or newer).
I've only tested it on Windows with TTSNative 2.1.0.
An app update will probably overwrite it, so you'd need to run the installer again.
The CUDA download is large compared with Kokoro itself, which is probably why it isn't the default.
The attached kit has install-gpu-patch.bat, undo-gpu-patch.bat and a README with manual steps. The installer matches the GPU build to the installed ONNX Runtime version, refuses to patch files it doesn't recognize, and verifies that CUDA is active at the end.
Suggestion: maybe an optional "GPU acceleration for Kokoro (NVIDIA)" download in Settings, like the Chatterbox engine has?
Use at your own risk. I'm not a developer; I put this together with help from my AI assistant.
TTSNative-Kokoro-GPU-patch-kit-public.zip
All reactions