Vietnamese G2P is handled by vig2p.
This repository includes both the lightweight inference package and the
Vietnamese fine-tuning recipe. Training instructions are in
TRAINING.md.
git clone https://github.com/iamdinhthuan/Kokoro-Vietnamese.git
cd Kokoro-Vietnamese
pip install -e .For CUDA, install the PyTorch build that matches your machine first.
For training utilities:
pip install -e ".[training]"The CLI downloads these files from
contextboxai/Kokoro-Vietnamese
when local paths are not provided:
kokoro_vi.pthkokoro_vi.onnxkokoro_vi_voicepack.ptconfig.json
Use these names with voice=... in Python or --voice ... in the CLI.
| Voice | Name |
|---|---|
diem_trinh |
Diễm Trinh |
hung_thinh |
Hưng Thịnh |
mai_linh |
Mai Linh |
mai_loan |
Mai Loan |
manh_dung |
Mạnh Dũng |
my_yen |
Mỹ Yến |
ngoc_huyen |
Ngọc Huyền |
phat_tai |
Phát Tài |
thanh_dat |
Thành Đạt |
thuc_trinh |
Thục Trinh |
tuan_ngoc |
Tuấn Ngọc |
storyvert |
storyvert |
duc_an |
Đức An |
duc_duy |
đức duy |
import soundfile as sf
from kokoro_vietnamese import KokoroVietnamese
tts = KokoroVietnamese(device="cuda", voice="diem_trinh")
audio, phonemes = tts.synthesize(
"Giữa một buổi chiều yên tĩnh, cô ấy kể lại câu chuyện bằng một giọng nói ấm áp và chậm rãi."
)
sf.write("outputs/sample.wav", audio, 24000)
print(phonemes)The package uses the same Kokoro runtime path as the original Gradio predictor.
Pass normalize_peak=0.95 only if you want optional peak limiting before
writing WAV files.
audio, phonemes = tts.synthesize("Tường nhà khách.", normalize_peak=0.95)Use another voice:
tts = KokoroVietnamese(device="cuda", voice="mai_linh")
audio, phonemes = tts.synthesize("Hôm nay trời trong xanh, gió thổi nhẹ qua hiên nhà.")Use local files instead of downloading from Hugging Face:
tts = KokoroVietnamese(
device="cuda",
model_path="kokoro_vi.pth",
voicepack_path="voicepacks/diem_trinh.pt",
config_path="config.json",
)kokoro-vietnamese \
--text "Giữa một buổi chiều yên tĩnh, cô ấy kể lại câu chuyện bằng một giọng nói ấm áp và chậm rãi." \
--output outputs/sample.wav \
--voice diem_trinh \
--device cudakokoro-vietnamese --list-voiceskokoro-vietnamese \
--batch-file texts.txt \
--voice diem_trinh \
--output-dir outputs/batchInstall ONNX dependencies:
pip install -e ".[onnx]"Export the PyTorch checkpoint to ONNX:
kokoro-vietnamese-export-onnx \
--output outputs/kokoro_vi.onnxRun ONNX Runtime inference:
kokoro-vietnamese-onnx \
--text "Tường nhà khách đã được sơn lại." \
--onnx outputs/kokoro_vi.onnx \
--output outputs/onnx.wav \
--device cpu \
--print-phonemesWhen --onnx is omitted, the command downloads kokoro_vi.onnx from the
Hugging Face model repo. Install onnxruntime-gpu and pass --device cuda to
use CUDAExecutionProvider when available.
kokoro-vietnamese-gradio --device cuda --shareIf AlbertModel fails to import in an old environment:
pip install -U git+https://github.com/iamdinhthuan/Kokoro-Vietnamese.git "transformers>=4.48,<5"