lab.et commited on
Commit ·
1412013
1
Parent(s): 6a9a41c
Fix inference packaging: public indextts imports, add infer_azemari.py and install_kaggle.sh
Browse filesmodel_v2.py imported indextts_ethiopic (internal fork namespace, not published),
so the repo could not be loaded against the public IndexTTS-2.5 codebase.
Imports now target indextts; the only remaining delta from upstream a371df7 is
the training-only langs argument.
Adds infer_azemari.py (CLI, JSONL batch, emotion parsing, patch checks),
install_kaggle.sh (pinned checkout + patch + verification), and corrects the
README install/usage/aux-file sections.
Files changed (4)
- README.md+81-15
- infer_azemari.pyAdded+147
- install_kaggle.shAdded+72
- model_v2.py+11-7
35 unmodified lines36373839404142434445464748495051525354555657585960616263646566676869707172737475769 unmodified lines8687888990919235 unmodified lines## Capabilities| Control | Token ||---|---|| Amharic | `<\|am\|>` || Afaan Oromoo | `<\|om\|>` || Tigrinya | `<\|ti\|>` || Shewa dialect | `<\|am\|><\|DIALECT_SHEWA\|>` || Emotion | 8-dim vector (happy, angry, sad, afraid, disgusted, melancholic, surprised, calm) || Voice | CAMPPlus speaker embedding from reference audio |## Usage**Everything needed for inference is in this repository** — download it and run; no external model downloads required.```bashpip install -U "huggingface_hub[cli]"hf download Lab-et/azemari --local-dir azemari```1. Set up the [IndexTTS-2.5 codebase](https://github.com/index-tts/index-tts)2. Point it at the downloaded `azemari/` directory as your checkpoint dir (it replaces the official `checkpoints/`)3. Generate. Control language with `<|am|>`, `<|om|>`, `<|ti|>` prefixes and dialects with `<|DIALECT_SHEWA|>` / `<|DIALECT_GOJJAM|>`### Repository contents| File | What it is ||---|---|| `gpt.pth` | **Azemari** — the fine-tuned GPT (this is the model) || `config.yaml` | adapted config (60,513 text tokens, +2 language rows) || `model_v2.py`, `tokenizer_ethiopic.py` | adapted inference code + Ethiopian tokenizer || `codec.pth`, `s2mel.pth`, `feat1.pt`, `feat2.pt`, `wav2vec2bert_stats.pt` | official IndexTTS-2.5 inference components || `qwen0.6bemo4-merge/` | official emotion model || `multilingual_zh_ja_yue_char_del.tiktoken` | base tokenizer (Ethiopic special tokens extend it) || `bigvgan_generator.pth` | BigVGAN vocoder (official IndexTTS component) |The only runtime fetch is the CAMPPlus speaker encoder, which the official code path loads from ModelScope (`iic/speech_campplus_sv_zh-cn_16k-common`).## Samples9 unmodified lines## LicenseInherited from [IndexTeam/IndexTTS-2.5](https://huggingface.co/IndexTeam/IndexTTS-2.5) — [bilibili Model Use License Agreement](https://huggingface.co/IndexTeam/IndexTTS-2.5/blob/main/LICENSE).## About lab.et35 unmodified lines363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411429 unmodified lines15215315415515615715835 unmodified lines## Capabilities| Control | How ||---|---|| Amharic | `lang="am"` || Afaan Oromoo | `lang="om"` || Tigrinya | `lang="ti"` || Shewa dialect | `<\|DIALECT_SHEWA\|>` prefix in text || Emotion | 8-dim vector (happy, angry, sad, afraid, disgusted, melancholic, surprised, calm) || Voice | CAMPPlus speaker embedding from reference audio |## Install> **Fixed 2026-11-26.** Earlier copies of `model_v2.py` imported `indextts_ethiopic`, the> internal fork namespace we trained with, which is not published. The file here now targets> the public `indextts` package, and `install_kaggle.sh` applies the whole patch.```bashhf download Lab-et/azemari --local-dir azemaribash azemari/install_kaggle.sh # clones index-tts @ a371df7, applies the patch, verifies````install_kaggle.sh` works on Kaggle, Colab and a local GPU box. It needs internet on the firstrun. Manual equivalent:```bashgit clone https://github.com/index-tts/index-tts && cd index-ttsgit checkout a371df7 && pip install -e .cp ../azemari/tokenizer_ethiopic.py indextts/utils/tokenizer.pycp ../azemari/model_v2.py indextts/gpt/model_v2.py```## Generate```bashpython azemari/infer_azemari.py \--model-dir azemari \--ref voice_ref.wav \--text "ሰላም፣ ይህ የአዜማሪ ድምፅ ሙከራ ነው።" \--lang am --emotion calm --out line.wav```Python:```pythonimport osfrom indextts.infer_v2_5 import IndexTTS2AZ = "azemari"tts = IndexTTS2(cfg_path=os.path.join(AZ, "config.yaml"), model_dir=AZ, use_qwen_emo=False)tts.infer(spk_audio_prompt="voice_ref.wav",text="ሰላም፣ ይህ የአዜማሪ ድምፅ ሙከራ ነው።",output_path="line.wav",lang="am",emo_vector=[0, 0, 0, 0, 0, 0, 0, 1.0],emo_alpha=1.0,)```Pass plain text: the pipeline prepends the `<|am|>` language token from `lang`.Emotion vector order is `[happy, angry, sad, afraid, disgusted, melancholic, surprised, calm]`.Values are relative weights. `emo_alpha` scales the whole vector; `emo_audio_prompt="acted.wav"`usually transfers emotion better than the vector.### Long-form work (dubbing, audiobooks)- One reference clip per speaker, 10–20 s, mono, clean, no music. Reuse that exact file.- Keep `emo_vector` fixed per character; vary it at scene level, not per line.- Render per sentence or subtitle cue (`max_text_tokens_per_segment`, default 120), then assemble.- `duration_factor` stretches delivery to fit a cue; ±10% is safe, more sounds unnatural.- For a voice locked across many episodes, a speaker-adapter fine-tune is more stable thanrepeated zero-shot cloning — contact us for that.## Hosted alternativeYou do not need a GPU to use these voices. Amharic, Afaan Oromoo and Tigrinya TTS are servedthrough [yakal.et](https://yakal.et) (prepaid in Birr) and [voice.et](https://voice.et), withspeech recognition on the same platform. Write to `sales@lab.et` for API access.## Repository contents| File | What it is ||---|---|| `gpt.pth` | **Azemari** — the fine-tuned GPT (this is the model) || `config.yaml` | adapted config (60,513 text tokens, +2 language rows) || `model_v2.py` | drop-in replacement for `indextts/gpt/model_v2.py` (public package names) || `tokenizer_ethiopic.py` | drop-in replacement for `indextts/utils/tokenizer.py` (adds `om`, `ti`) || `infer_azemari.py` | CLI + JSONL batch inference, emotion parsing, patch checks || `install_kaggle.sh` | one-shot setup and verification for Kaggle/Colab/local || `codec.pth`, `s2mel.pth`, `feat1.pt`, `feat2.pt`, `wav2vec2bert_stats.pt` | official IndexTTS-2.5 inference components || `qwen0.6bemo4-merge/` | official emotion model || `multilingual_zh_ja_yue_char_del.tiktoken` | base tokenizer (Ethiopic special tokens extend it) || `bigvgan_generator.pth` | BigVGAN vocoder (official IndexTTS component) |Three auxiliary components are fetched once into `<model_dir>/hf_cache/` on first run:| Component | Source | Size ||---|---|---|| `w2v-bert-2.0/` | `facebook/w2v-bert-2.0` | ~2.3 GB || `campplus_cn_common.bin` | `funasr/campplus` | ~28 MB || `bigvgan/` | `nvidia/bigvgan_v2_22khz_80band_256x` | ~14 MB |## Samples9 unmodified lines## LicenseInherited from [IndexTeam/IndexTTS-2.5](https://huggingface.co/IndexTeam/IndexTTS-2.5) — [bilibili Model Use License Agreement](https://huggingface.co/IndexTeam/IndexTTS-2.5/blob/main/LICENSE). This is not an unrestricted commercial licence; check it before commercial release (film, broadcast, paid products) or contact `sales@lab.et` about a commercial arrangement.## About lab.et
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147#!/usr/bin/env python3"""Azemari inference — Amharic, Afaan Oromoo, Tigrinya TTS with voice cloning.
Requires the public IndexTTS-2.5 codebase with the Azemari patch applied(see install_kaggle.sh in this repo). Everything needed for inference is in themodel directory; only w2v-bert-2.0, CAMPPlus and BigVGAN are fetched once into<model_dir>/hf_cache on first run.
Single line: python infer_azemari.py --model-dir ./azemari --ref voice.wav \ --text "ሰላም፣ እንዴት ነህ?" --lang am --emotion calm --out line.wav
Full script (JSONL, one object per line: {"text": "...", "out": "a.wav", "emotion": "sad"}): python infer_azemari.py --model-dir ./azemari --ref voice.wav --script lines.jsonl"""from __future__ import annotations
import argparseimport jsonimport osimport sysimport timefrom pathlib import Path
EMOTIONS = ["happy", "angry", "sad", "afraid", "disgusted", "melancholic", "surprised", "calm"]LANGS = ("am", "om", "ti")
def parse_emotion(value: str | None) -> list[float] | None: """'calm' -> one-hot vector; '0,0,0,0,0,0,0,1' -> explicit vector.""" if not value: return None if "," in value: vec = [float(x) for x in value.split(",")] if len(vec) != len(EMOTIONS): raise SystemExit(f"emotion vector needs {len(EMOTIONS)} values, got {len(vec)}") return vec if value not in EMOTIONS: raise SystemExit(f"unknown emotion {value!r}; choose from {', '.join(EMOTIONS)}") return [1.0 if name == value else 0.0 for name in EMOTIONS]
def check_patch() -> None: """Fail early with a useful message if the Azemari patch is not applied.""" try: from indextts.utils.tokenizer import LANGUAGE_DICT except ModuleNotFoundError as exc: raise SystemExit( "The public IndexTTS-2.5 codebase is not importable. Run install_kaggle.sh, " "or pip install -e . from the index-tts checkout.\n" + str(exc) ) from exc missing = [lang for lang in LANGS if lang not in LANGUAGE_DICT] if missing: raise SystemExit( "Azemari tokenizer patch missing for: " + ", ".join(missing) + "\nCopy tokenizer_ethiopic.py over indextts/utils/tokenizer.py (install_kaggle.sh does this)." )
def build_tts(model_dir: str, device: str | None, use_bf16: bool, qwen_emo: bool): from indextts.infer_v2_5 import IndexTTS2
cfg = os.path.join(model_dir, "config.yaml") if not os.path.isfile(cfg): raise SystemExit(f"config.yaml not found in {model_dir} — point --model-dir at the hf download of Lab-et/azemari") tts = IndexTTS2(cfg_path=cfg, model_dir=model_dir, use_bf16=use_bf16, device=device, use_qwen_emo=qwen_emo) return tts
def generate(tts, ref: str, text: str, out: str, lang: str, emo: list[float] | None, emo_audio: str | None, emo_alpha: float, interval_silence: int, max_tokens: int, duration_factor: float, verbose: bool) -> float: Path(out).parent.mkdir(parents=True, exist_ok=True) t0 = time.time() tts.infer( spk_audio_prompt=ref, text=text, output_path=out, lang=lang, emo_vector=emo, emo_audio_prompt=emo_audio, emo_alpha=emo_alpha, interval_silence=interval_silence, max_text_tokens_per_segment=max_tokens, duration_factor=duration_factor, verbose=verbose, ) return time.time() - t0
def main() -> int: ap = argparse.ArgumentParser(description="Azemari TTS inference") ap.add_argument("--model-dir", default="azemari", help="path to the Lab-et/azemari download") ap.add_argument("--ref", required=True, help="reference voice clip, 10-20 s, clean, one speaker") ap.add_argument("--text") ap.add_argument("--out") ap.add_argument("--script", help="JSONL with {text, out, lang?, emotion?} per line") ap.add_argument("--lang", default="am", choices=list(LANGS)) ap.add_argument("--emotion", help="name (" + ", ".join(EMOTIONS) + ") or 8 comma-separated weights") ap.add_argument("--emo-audio", help="acted reference clip for emotion transfer (overrides --emotion)") ap.add_argument("--emo-alpha", type=float, default=1.0, help="emotion strength multiplier") ap.add_argument("--interval-silence", type=int, default=200, help="ms of silence between segments") ap.add_argument("--max-text-tokens", type=int, default=120, help="lower if long lines truncate") ap.add_argument("--duration-factor", type=float, default=1.0, help="stretch delivery to fit a cue") ap.add_argument("--device", help="cuda:0, mps, cpu (default: auto)") ap.add_argument("--bf16", action="store_true", help="bfloat16 on supported GPUs") ap.add_argument("--qwen-emo", action="store_true", help="load QwenEmotion for emo_text") ap.add_argument("--verbose", action="store_true") args = ap.parse_args()
if not os.path.isfile(args.ref): raise SystemExit(f"reference audio not found: {args.ref}") if not args.script and not (args.text and args.out): raise SystemExit("provide --text and --out, or --script")
check_patch() tts = build_tts(args.model_dir, args.device, args.bf16, args.qwen_emo)
jobs = [] if args.script: with open(args.script, encoding="utf-8") as fh: for i, line in enumerate(fh, 1): line = line.strip() if not line: continue row = json.loads(line) jobs.append({ "text": row["text"], "out": row.get("out") or f"line_{i:04d}.wav", "lang": row.get("lang", args.lang), "emotion": row.get("emotion", args.emotion), }) else: jobs.append({"text": args.text, "out": args.out, "lang": args.lang, "emotion": args.emotion})
for job in jobs: emo = parse_emotion(job["emotion"]) took = generate(tts, args.ref, job["text"], job["out"], job["lang"], emo, args.emo_audio, args.emo_alpha, args.interval_silence, args.max_text_tokens, args.duration_factor, args.verbose) print(f"[{job['lang']}] {job['out']} {took:.1f}s {job['text'][:60]}") return 0
if __name__ == "__main__": sys.exit(main())123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172#!/usr/bin/env bash# Azemari setup — Kaggle, Colab, or a local GPU box.## Fixes the published packaging bug: model_v2.py in the model repo imported the# internal fork namespace `indextts_ethiopic`, which is not published. The public# IndexTTS-2.5 codebase uses `indextts`. We patch the two files in place.## Usage:# bash install_kaggle.sh [/path/to/workdir]# MODEL_DIR=./azemari bash install_kaggle.shset -euo pipefail
WORK="${1:-${WORK:-/kaggle/working}}"AZ="${MODEL_DIR:-$WORK/azemari}"REPO="$WORK/index-tts"PIN=a371df7d0746a0ae7fdf075798b6b04e34a0132e # IndexTTS-2.5 commit Azemari was trained against
mkdir -p "$WORK"
echo "==> 1/4 code @ ${PIN:0:7}"if [ ! -d "$REPO/.git" ]; then git init -q "$REPO" git -C "$REPO" remote add origin https://github.com/index-tts/index-ttsfigit -C "$REPO" fetch -q --depth 1 origin "$PIN"git -C "$REPO" checkout -q FETCH_HEADpip install -q -e "$REPO"
echo "==> 2/4 weights -> $AZ"python - "$AZ" <<'PY'import sys, osfrom huggingface_hub import snapshot_downloaddest = sys.argv[1]snapshot_download("Lab-et/azemari", local_dir=dest, allow_patterns=["*.pth", "*.pt", "*.yaml", "*.py", "*.json", "*.tiktoken", "*.jinja", "*.txt", "*.md"])print("downloaded:", dest)PY
echo "==> 3/4 patch model_v2 + tokenizer"cp "$AZ/tokenizer_ethiopic.py" "$REPO/indextts/utils/tokenizer.py"python - "$AZ" "$REPO" <<'PY'import sys, pathlibaz, repo = map(pathlib.Path, sys.argv[1:3])src = (az / "model_v2.py").read_text(encoding="utf-8")assert "indextts_ethiopic" in src, "unexpected model_v2.py: fork imports not found"out = src.replace("indextts_ethiopic", "indextts")(repo / "indextts/gpt/model_v2.py").write_text(out, encoding="utf-8")print("patched", repo / "indextts/gpt/model_v2.py")PY
echo "==> 4/4 verify"cd "$REPO"python - <<'PY'from indextts.utils.tokenizer import LANGUAGE_DICTfrom indextts.gpt.model_v2 import UnifiedVoicemissing = [l for l in ("am", "om", "ti") if l not in LANGUAGE_DICT]assert not missing, f"tokenizer patch incomplete: {missing}"print("ok — languages:", ", ".join(l for l in ("am", "om", "ti") if l in LANGUAGE_DICT))PY
cat <<EOF
Done.
Next: cd $REPO python $WORK/azemari/infer_azemari.py --model-dir $AZ --ref voice.wav \\ --text "ሰላም፣ እንዴት ነህ?" --lang am --emotion calm --out line.wav
First run fetches w2v-bert-2.0, CAMPPlus and BigVGAN into $AZ/hf_cache (~2.4 GB).Kaggle: Settings -> Internet -> On.EOF1232 unmodified lines67891011121314151617181920212223415 unmodified lines439440441442443444445import functoolsimport torch2 unmodified linesimport transformersfrom transformers import GPT2Config, LogitsProcessorListfrom indextts_ethiopic.gpt.transformers_gpt2 import GPT2PreTrainedModel, GPT2Model# from transformers import GPT2Config, GPT2PreTrainedModel, LogitsProcessorListfrom transformers.modeling_outputs import CausalLMOutputWithCrossAttentionsfrom transformers.utils.model_parallel_utils import (assert_device_map,get_device_map)from indextts_ethiopic.gpt.conformer_encoder import ConformerEncoderfrom indextts_ethiopic.gpt.perceiver import PerceiverResamplerfrom indextts_ethiopic.utils.arch_util import AttentionBlockfrom indextts_ethiopic.utils.typical_sampling import TypicalLogitsWarperfrom indextts_ethiopic.utils.tokenizer import LANGUAGE_DICTdef null_position_embeddings(range, dim):415 unmodified linesexcept ImportError:raise ImportError("flash_attn is required for acceleration but not installed. Please install from https://github.com/Dao-AILab/flash-attention/releases/")from indextts_ethiopic.accel import GPT2AccelModel, AccelInferenceEngine# Create accel modelaccel_gpt = GPT2AccelModel(gpt_config)12345672 unmodified lines101112131415161718192021222324252627415 unmodified lines443444445446447448449# Azemari — Ethiopian multilingual TTS (lab.et)# Drop-in replacement for indextts/gpt/model_v2.py in the public IndexTTS-2.5 codebase.# Changes vs upstream (index-tts @ a371df7): package name (indextts_ethiopic -> indextts)# and a training-only `langs` argument in forward(). Inference paths are unchanged.import functoolsimport torch2 unmodified linesimport transformersfrom transformers import GPT2Config, LogitsProcessorListfrom indextts.gpt.transformers_gpt2 import GPT2PreTrainedModel, GPT2Model# from transformers import GPT2Config, GPT2PreTrainedModel, LogitsProcessorListfrom transformers.modeling_outputs import CausalLMOutputWithCrossAttentionsfrom transformers.utils.model_parallel_utils import (assert_device_map,get_device_map)from indextts.gpt.conformer_encoder import ConformerEncoderfrom indextts.gpt.perceiver import PerceiverResamplerfrom indextts.utils.arch_util import AttentionBlockfrom indextts.utils.typical_sampling import TypicalLogitsWarperfrom indextts.utils.tokenizer import LANGUAGE_DICTdef null_position_embeddings(range, dim):415 unmodified linesexcept ImportError:raise ImportError("flash_attn is required for acceleration but not installed. Please install from https://github.com/Dao-AILab/flash-attention/releases/")from indextts.accel import GPT2AccelModel, AccelInferenceEngine# Create accel modelaccel_gpt = GPT2AccelModel(gpt_config)
README.md+81-15
infer_azemari.pyAdded+147
install_kaggle.shAdded+72
model_v2.py+11-7