Skip to content

Evaluation scripts for the Open TTS Leaderboard: https://huggingface.co/spaces/hf-audio/open_tts_leaderboard

Python

Add Kokoro-Vietnamese evaluation backend (#33)

zohuyhieuzo03380d6933d15e
diff --git a/kokoro-vietnamese/run_eval.py b/kokoro-vietnamese/run_eval.py
new file mode 100644
index 0000000..6e39ffb
--- /dev/null
+++ b/kokoro-vietnamese/run_eval.py
@@ -0,0 +1,103 @@
+"""
+TTS synthesis for the Open TTS Leaderboard (Kokoro-Vietnamese backend, stage 1).
+
+Kokoro-Vietnamese (contextboxai/Kokoro-Vietnamese, Apache-2.0) is a Vietnamese fine-tune of the
+Kokoro-82M StyleTTS2 architecture, loaded in-process via the `kokoro_vietnamese` package
+(https://github.com/iamdinhthuan/Kokoro-Vietnamese). Fixed built-in voice, so no stage 3 (SIM).
+Synthesis is serial (no batched API), like the `kokoro/` backend.
+
+Output is 24 kHz. Vietnamese G2P is `vig2p`, which does not declare a license (see
+https://github.com/iamdinhthuan/Kokoro-Vietnamese/issues/5).
+"""
+
+import argparse
+import os
+import time
+
+import numpy as np
+import soundfile as sf
+import torch
+from tqdm import tqdm
+
+from kokoro_vietnamese import KokoroVietnamese
+
+from run_eval_utils import (
+ add_common_args, load_done_entries, load_tts_dataset, manifest_entry, open_manifest, output_paths,
+ pending_batches, print_model_size, print_next_steps, set_seed, warm_up, wav_rel_path, write_entry,
+)
+
+SAMPLING_RATE = 24_000
+
+
+def main(args):
+ set_seed(args.seed)
+
+ tts = KokoroVietnamese(device=args.device, voice=args.voice)
+ print(f"Loaded Kokoro-Vietnamese (voice={args.voice}, device={args.device})")
+ print_model_size(getattr(tts, "model", None))
+
+ is_cuda = args.device.startswith("cuda")
+
+ def synth_one(text):
+ """Synthesize one text. Return (audio_1d_numpy, elapsed_s)."""
+ if is_cuda:
+ torch.cuda.synchronize()
+ start = time.perf_counter()
+ audio, _phonemes = tts.synthesize(text)
+ if is_cuda:
+ torch.cuda.synchronize()
+ elapsed = time.perf_counter() - start
+ audio = np.asarray(audio, dtype=np.float32).reshape(-1)
+ if audio.size == 0:
+ audio = np.zeros(1, dtype=np.float32)
+ return audio, elapsed
+
+ paths = output_paths(args)
+ model_dir, dataset_dir_name, manifest_path = paths.model_dir, paths.dataset_dir_name, paths.manifest_path
+
+ dataset = load_tts_dataset(args)
+
+ if args.ttfa_probe != 0:
+ raise SystemExit("--ttfa_probe is not implemented for this backend (no streaming API).")
+
+ done_entries = load_done_entries(manifest_path, args.resume)
+ manifest_file = open_manifest(manifest_path, done_entries)
+
+ starts = pending_batches(dataset, 1, done_entries, dataset_dir_name)
+ warm_up(lambda batch: [synth_one(t) for t in batch[args.text_column]], dataset, starts, 1, args.warmup_steps)
+ set_seed(args.seed) # warm-up must not shift the RNG stream of the timed run
+
+ for i in tqdm(starts, desc="Generating"):
+ sample_id = dataset[i]["id"]
+ text = dataset[i][args.text_column]
+
+ rel_path = wav_rel_path(dataset_dir_name, sample_id)
+ path = os.path.join(model_dir, rel_path)
+
+ audio, elapsed = synth_one(text)
+ sf.write(path, audio, SAMPLING_RATE)
+
+ write_entry(manifest_file, manifest_entry(rel_path, len(audio) / SAMPLING_RATE, elapsed, text))
+ manifest_file.flush()
+
+ manifest_file.close()
+ print("Results saved at path:", os.path.abspath(manifest_path))
+ print_next_steps(voice_clone=False)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--model_id", type=str, default="contextboxai/Kokoro-Vietnamese",
+ help="Model repo id (recorded in the manifest folder name; weights are fetched by the package).")
+ parser.add_argument("--voice", type=str, default="diem_trinh",
+ help="Built-in voice (diem_trinh, hung_thinh, mai_linh, mai_loan, manh_dung, ...).")
+ add_common_args(parser)
+ parser.set_defaults(split="vi")
+
+ args = parser.parse_args()
+
+ print("*" * 100)
+ print(f"Generating TTS with {args.model_id} on {args.dataset_path} / {args.dataset} / {args.split}")
+ print("*" * 100)
+
+ main(args)
diff --git a/kokoro-vietnamese/submit_jobs.sh b/kokoro-vietnamese/submit_jobs.sh
new file mode 100755
index 0000000..af750b8
--- /dev/null
+++ b/kokoro-vietnamese/submit_jobs.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# HF Jobs TTS eval — Kokoro-Vietnamese backend (fixed voice → generate → transcribe → score; no SIM).
+# Runs locally; submits HF Jobs. Usage: HF_TOKEN=hf_... bash submit_jobs.sh ["contextboxai/Kokoro-Vietnamese" ...]
+# Shared orchestration (stages 2/3, injection, logging, scoring) lives in scripts/tts_jobs_common.sh.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/scripts/tts_jobs_common.sh"
+
+# ── Backend config ───────────────────────────────────────────────────────────
+TTS_SPACE="${TTS_SPACE:-bezzam/evals-kokoro-vi}" # stage-1 image (Dockerfile in the Space: https://huggingface.co/spaces/bezzam/evals-kokoro-vi/blob/main/Dockerfile)
+# gen FLAVOR (h200) is set centrally in tts_jobs_common.sh for RTFx comparability — don't override.
+DEFAULT_STAGES="generate transcribe" # no SIM (fixed voice); no UTMOS (English only)
+RUN_EVAL_INJECT="$(inject_run_eval)"
+
+# Vietnamese only. Built-in voices: diem_trinh, hung_thinh, mai_linh, mai_loan, manh_dung, my_yen, ...
+KOKORO_VI_VOICE="${KOKORO_VI_VOICE:-diem_trinh}"
+supports_language() { [[ "$1" == "vi" ]]; }
+
+# ── Stage 1: TTS generation (serial synthesis, one sample at a time) ─────────
+generate_stage() {
+ hf jobs run \
+ --flavor "${FLAVOR}" --timeout "${GEN_TIMEOUT:-8h}" --secrets HF_TOKEN ${NAMESPACE_ARG} \
+ --volume "hf://buckets/${RESULTS_BUCKET}:/results" "${TTS_IMAGE}" \
+ bash -c "
+ ${RUN_EVAL_INJECT}
+ cd /app/kokoro-vietnamese && python run_eval.py \
+ --model_id=${MODEL_ID} \
+ --voice=${KOKORO_VI_VOICE} \
+ --dataset_path=${DATASET_PATH} \
+ --dataset=${DATASET} \
+ --split=${SPLIT} \
+ --device=cuda:0 \
+ --max_eval_samples=${MAX_EVAL_SAMPLES} &&
+ mkdir -p /results &&
+ cp -r results/${MODEL_SAFE} /results/
+ "
+}
+
+# ── Datasets: "config split asr_language [dataset_path]" ─────────────────────
+# MiniMax multilingual: 100 sentences per language, public at hf-audio/minimax_eval.
+DATASET_CONFIGS=(
+ "tts vi vi ${MINIMAX_EVAL_PATH}"
+)
+
+# ── Models: "model_id" (CLI args override) ───────────────────────────────────
+MODEL_CONFIGS=("contextboxai/Kokoro-Vietnamese")
+[[ $# -gt 0 ]] && MODEL_CONFIGS=("$@")
+
+run_pipeline