File size: 4,650 Bytes
a1cd84e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""

Murli V2.0 Hugging Face Release Exporter.

Publishes weights-only (`model.safetensors`, `config.json`, `LICENSE`, clean `README.md`)

matching the Drama-3 style release hygiene while keeping source code in `ViuAI/Murli-V2-Code`.

"""

import argparse
import json
import os
import tempfile
from pathlib import Path

from huggingface_hub import HfApi
from safetensors.torch import load_file, save_file

from config import MurliV2Config
from models.tts_engine import MurliV2Engine


def generate_v2_model_card(repo_id: str) -> str:
    return f"""---

language:

  - hi

  - en

license: apache-2.0

license_link: LICENSE

pipeline_tag: text-to-speech

datasets:

  - ViuAI/Murli_TTS_Dataset

tags:

  - murli

  - murli-v2

  - bilingual

  - hindi

  - english

  - zero-shot-tts

  - dit

  - flow-matching

  - ot-cfm

---



# Murli V2.0



**Murli V2.0** is a **78.8M-parameter bilingual (Hindi + English / Hinglish)** Zero-Shot Diffusion Transformer (DiT) text-to-speech model trained at 24 kHz with Optimal Transport Conditional Flow Matching (OT-CFM).



- **78.80M trainable acoustic parameters**: 6-layer RoPE SwiGLU Phoneme Encoder, 4-layer Perceiver Zero-Shot Style Resampler, explicit Duration / $F_0$ Pitch / Energy predictors, and an 8-layer `AdaLN-Zero` DiT vector field

- **Bilingual Hindi + English / Hinglish**: Unified IPA + prosody frontend handles Devanagari schwa rules, contextual Anusvara, retroflex flaps (`ड़`, `ढ़`), and English loanwords seamlessly

- **Zero-shot multi-speaker voice cloning**: Clone male or female speakers across Hindi and English from a 3–10 second reference clip

- **Fast Midpoint ODE flow sampling**: 32-step Midpoint solver with Sway Sampling (`-1.0`) and Classifier-Free Guidance (`1.8`)



## Quickstart



Clone the runtime from [`ViuAI/Murli-V2-Code`](https://huggingface.co/ViuAI/Murli-V2-Code):



```bash

git clone https://huggingface.co/ViuAI/Murli-V2-Code && cd Murli-V2-Code

pip install -r requirements.txt

hf download {repo_id} model.safetensors --local-dir .

python infer.py --checkpoint model.safetensors --ref_audio ref_voice.wav --text "नमस्ते friend, आज weather बहुत अच्छा है!"

```



## Links



- [Murli V2.0 Model Weights](https://huggingface.co/{repo_id})

- [Murli V2 Source Code](https://huggingface.co/ViuAI/Murli-V2-Code)

- [Murli Unified Speech Dataset](https://huggingface.co/datasets/ViuAI/Murli_TTS_Dataset)



## License



Licensed under the [Apache License 2.0](https://huggingface.co/{repo_id}/blob/main/LICENSE).

"""


def export_v2(checkpoint_path: str, repo_id: str = "ViuAI/Murli-V2.0", token: str = None, private: bool = False) -> None:
    if not os.path.isfile(checkpoint_path):
        raise FileNotFoundError(f"Checkpoint not found: {checkpoint_path}")

    cfg = MurliV2Config()
    model = MurliV2Engine(cfg.model, cfg.training)
    state = load_file(checkpoint_path, device="cpu")
    model.load_state_dict({k:v for k,v in state.items() if not k.startswith("vocoder.")}, strict=True)
    del state

    with tempfile.TemporaryDirectory() as tmpdir:
        save_file({k: v.cpu().contiguous() for k, v in model.acoustic_state_dict().items()}, os.path.join(tmpdir, "model.safetensors"))
        with open(os.path.join(tmpdir, "config.json"), "w", encoding="utf-8") as f:
            json.dump({"audio": cfg.audio.__dict__, "model": cfg.model.__dict__}, f, indent=2)
        with open(os.path.join(tmpdir, "README.md"), "w", encoding="utf-8") as f:
            f.write(generate_v2_model_card(repo_id))
        with open(os.path.join(tmpdir, "LICENSE"), "w", encoding="utf-8") as f:
            f.write((Path(__file__).parent / "utils" / "Apache-2.0.txt").read_text(encoding="utf-8"))

        api = HfApi(token=token)
        api.create_repo(repo_id, repo_type="model", private=private, exist_ok=True)
        api.upload_folder(
            folder_path=tmpdir,
            repo_id=repo_id,
            repo_type="model",
            commit_message="Release Murli V2.0 (78.8M Bilingual DiT TTS)",
        )
        print(f"Published -> https://huggingface.co/{repo_id}")


if __name__ == "__main__":
    p = argparse.ArgumentParser(description="Export Murli V2.0 weights-only release to HF")
    p.add_argument("--checkpoint", type=str, required=True)
    p.add_argument("--repo_id", type=str, default="ViuAI/Murli-V2.0")
    p.add_argument("--token", type=str, default=None)
    p.add_argument("--private", action="store_true")
    a = p.parse_args()
    export_v2(a.checkpoint, a.repo_id, a.token or os.environ.get("HF_TOKEN"), a.private)