jennyxue commited on
Commit
bde4b1a
·
verified ·
1 Parent(s): 013f8f7

Model card and the original license

Browse files
Files changed (1) hide show
  1. README.md +324 -0
README.md ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: OpenMOSS-Team/MOSS-TTS-v1.5
3
+ base_model_relation: quantized
4
+ license: apache-2.0
5
+ pipeline_tag: text-to-speech
6
+ library_name: mlx-audio
7
+ tags:
8
+ - mlx
9
+ - moonbox
10
+ - mlx-audio
11
+ - moss-tts
12
+ - openmoss
13
+ - text-to-speech
14
+ - voice-cloning
15
+ - qwen3
16
+ ---
17
+
18
+ # MOSS-TTS v1.5 MLX
19
+
20
+ MLX builds of [MOSS-TTS v1.5](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-v1.5), made by Moonbox for Apple Silicon Macs. Each precision is a folder; keep a folder's
21
+ files together. Only the parts listed below are converted: the rest of the pipeline comes from the original
22
+ repository unless the section below says otherwise.
23
+
24
+ ## Files
25
+
26
+ The last column is how far each build is from the original PyTorch model on the same inputs (see the section below
27
+ for what was measured).
28
+
29
+ | Precision | File | Size | sha256 | Checked against the original |
30
+ |---|---|---|---|---|
31
+ | bf16 | [`bf16/added_tokens.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/added_tokens.json) | 0.7 kB | `9dfb40d3a3f8` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
32
+ | bf16 | [`bf16/chat_template.jinja`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/chat_template.jinja) | 0.4 kB | `894e3ace884e` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
33
+ | bf16 | [`bf16/config.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/config.json) | 2.7 kB | `32dc731f256e` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
34
+ | bf16 | [`bf16/merges.txt`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/merges.txt) | 1.7 MB | `8831e4f1a044` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
35
+ | bf16 | [`bf16/model-00001-of-00004.safetensors`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/model-00001-of-00004.safetensors) | 5.32 GB | `ad91aa5d7bc9` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
36
+ | bf16 | [`bf16/model-00002-of-00004.safetensors`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/model-00002-of-00004.safetensors) | 5.30 GB | `0dac139d80f7` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
37
+ | bf16 | [`bf16/model-00003-of-00004.safetensors`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/model-00003-of-00004.safetensors) | 4.82 GB | `bbff7aa8ad80` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
38
+ | bf16 | [`bf16/model-00004-of-00004.safetensors`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/model-00004-of-00004.safetensors) | 1.54 GB | `2e1fe38aed3b` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
39
+ | bf16 | [`bf16/model.safetensors.index.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/model.safetensors.index.json) | 42.2 kB | `378fd1b3e608` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
40
+ | bf16 | [`bf16/processor_config.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/processor_config.json) | 0.1 kB | `6821d4805f10` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
41
+ | bf16 | [`bf16/special_tokens_map.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/special_tokens_map.json) | 0.6 kB | `55cbd0665670` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
42
+ | bf16 | [`bf16/tokenizer.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/tokenizer.json) | 11.4 MB | `cb3c8fa82993` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
43
+ | bf16 | [`bf16/tokenizer_config.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/tokenizer_config.json) | 5.5 kB | `87b1f37a4a73` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
44
+ | bf16 | [`bf16/vocab.json`](https://huggingface.co/moonbox-dev/MOSS-TTS-v1.5-MLX/blob/main/bf16/vocab.json) | 2.8 MB | `ca10d7e9fb3e` | not checkable on 24 GB: weights bit-identical to the original's bf16; 1 English clip: WER 0.0 %, speaker sim 0.985, DNSMOS 3.25 (original 0.0 %, 0.976, 3.27) |
45
+
46
+ ## How to run
47
+
48
+ MOSS-TTS v1.5 (OpenMOSS, 8B MossTTSDelay on a Qwen3 backbone: zero-shot voice cloning from reference audio alone,
49
+ many languages) for [mlx-audio](https://github.com/Blaizzy/mlx-audio). Each folder is a complete mlx-audio model
50
+ except the audio tokenizer: mlx-audio fetches
51
+ [OpenMOSS-Team/MOSS-Audio-Tokenizer](https://huggingface.co/OpenMOSS-Team/MOSS-Audio-Tokenizer) (1.6B, 7 GB float32)
52
+ at first use, or takes a local copy via `audio_tokenizer_source`. The original's remote-code `.py` files are left out
53
+ (mlx-audio has its own implementation). Tested with `mlx-audio==0.6.5`:
54
+
55
+ ```python
56
+ from mlx_audio.tts.utils import load_model
57
+ import numpy as np, soundfile as sf
58
+
59
+ model = load_model("8bit") # a downloaded folder
60
+ res = list(model.generate(text="Hello from Moonbox.", ref_audio="voice.wav", language="English"))
61
+ sf.write("out.wav", np.concatenate([np.array(r.audio).reshape(-1) for r in res]), res[0].sample_rate)
62
+ ```
63
+
64
+ `8bit/`, `6bit/` and `4bit/` quantize the transformer layers (MLX affine, group size 64); embeddings and audio heads
65
+ stay bf16. **License:** Apache-2.0.
66
+
67
+ **How they were checked.** Voice cloning of 6 English and 4 Chinese sentences, one seed each (the 8B model plus its
68
+ audio tokenizer fill a 24 GB Mac), with the original (its own transformers code at the pinned revision, PyTorch
69
+ bfloat16 on MPS, the same audio tokenizer) and every MLX build, the model's own sampling defaults. Judged by Whisper
70
+ large-v3-turbo WER / CER, WavLM speaker similarity to the prompt, DNSMOS. Pass: error rate at most 2 points above the
71
+ original's, similarity at most 0.03 below, DNSMOS at most 0.2 below.
72
+
73
+ | Precision | Size | WER en / CER zh | Speaker similarity en / zh | DNSMOS en / zh | Real-time factor, M5 24 GB | Peak memory |
74
+ |---|---|---|---|---|---|---|
75
+ | original (PyTorch bf16, MPS) | - | 0.0 % / 0.0 % | 0.968 / 0.950 | 2.94 / 2.36 | 28.9 | - |
76
+ | `bf16/` | 16 GB | not checkable on 24 GB (swaps); weights bit-identical to the original; 1 clip: 0.0 %, sim 0.985, DNSMOS 3.25 | | | ~28 (swapping) | - |
77
+ | `fp16/` | 16 GB | not checkable on 24 GB; weights within 3e-8 of the original | | | - | - |
78
+ | `8bit/` | 8.5 GB | 0.0 % / 0.0 % | 0.970 / 0.955 | 3.11 / 2.72 | 5.9 | 17.2 GB |
79
+ | `6bit/` | 6.6 GB | 0.0 % / 0.0 % | 0.961 / 0.942 | 3.09 / 2.52 | 2.4 | 15.1 GB |
80
+ | `4bit/` (experimental) | 4.6 GB | 3.6 % / 1.3 % | 0.967 / 0.943 | 3.14 / 2.79 | 1.5 | 13.0 GB |
81
+
82
+ `4bit/` is below the threshold: it garbled one English tongue twister ("the shells she sells") and one Chinese word.
83
+ Real-time factor = generation time / audio length, one sentence at a time; peak memory includes the audio tokenizer.
84
+ bf16 / fp16 need more than 24 GB of unified memory.
85
+
86
+ ## How these were made
87
+
88
+ From [MOSS-TTS v1.5](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-v1.5) at revision `cdd3b911b1`: the original weights loaded in MLX and stored as bf16 or fp16, or
89
+ quantized with MLX's affine quantization (`8bit`, `6bit`, `4bit`, group size 64; layers MLX can't quantize, such as
90
+ convolutions and norms, stay bf16). Every build was checked against the original before upload; the `sha256` column
91
+ above is what the files must hash to.
92
+
93
+ ## License
94
+
95
+ Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this
96
+ repository, and it governs your use of these files. The original model card follows unchanged.
97
+
98
+ ---
99
+
100
+ # Original model card
101
+
102
+ # MOSS-TTS Family
103
+
104
+
105
+ <br>
106
+
107
+ <p align="center">
108
+ &nbsp;&nbsp;&nbsp;&nbsp;
109
+ <img src="https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_imgaes_demo/openmoss_x_mosi" height="50" align="middle" />
110
+ </p>
111
+
112
+
113
+
114
+ <div align="center">
115
+ <a href="https://github.com/OpenMOSS/MOSS-TTS/tree/main"><img src="https://img.shields.io/badge/Project%20Page-GitHub-blue"></a>
116
+ <a href="https://modelscope.cn/collections/OpenMOSS-Team/MOSS-TTS"><img src="https://img.shields.io/badge/ModelScope-Models-lightgrey?logo=modelscope&amp"></a>
117
+ <a href="https://mosi.cn/#models"><img src="https://img.shields.io/badge/Blog-View-blue?logo=internet-explorer&amp"></a>
118
+ <a href="https://arxiv.org/abs/2603.18090"><img src="https://img.shields.io/badge/Arxiv-2603.18090-red?logo=Arxiv&amp"></a>
119
+
120
+ <a href="https://studio.mosi.cn"><img src="https://img.shields.io/badge/AIStudio-Try-green?logo=internet-explorer&amp"></a>
121
+ <a href="https://studio.mosi.cn/docs/moss-tts"><img src="https://img.shields.io/badge/API-Docs-00A3FF?logo=fastapi&amp"></a>
122
+ <a href="https://x.com/Open_MOSS"><img src="https://img.shields.io/badge/Twitter-Follow-black?logo=x&amp"></a>
123
+ <a href="https://discord.gg/fvm5TaWjU3"><img src="https://img.shields.io/badge/Discord-Join-5865F2?logo=discord&amp"></a>
124
+ </div>
125
+
126
+
127
+ # MOSS-TTS-v1.5
128
+
129
+ **MOSS-TTS-v1.5** is continued from [MOSS-TTS 1.0](https://huggingface.co/OpenMOSS-Team/MOSS-TTS). It preserves the main 1.0 capabilities, including zero-shot voice cloning, long-form speech generation, token-level duration control, Pinyin/IPA pronunciation control, multilingual synthesis, and code-switching. For the full 1.0 feature walkthrough, input schema, decoding hyperparameters, and evaluation tables, please refer to the [MOSS-TTS 1.0 README](https://huggingface.co/OpenMOSS-Team/MOSS-TTS).
130
+
131
+ Compared with MOSS-TTS 1.0, v1.5 focuses on the following improvements:
132
+
133
+ - **Stronger multilingual synthesis with language tags**: when the `language` field is omitted, v1.5 may improve some languages and regress slightly on others compared with 1.0. When the language is specified, v1.5 is stronger than 1.0 on almost all supported languages. Set the tag when building the user message, for example `processor.build_user_message(text=text_fr, language="French")`.
134
+ - **More stable voice cloning**: v1.5 improves speaker similarity and reduces cloning variance, making repeated generations more consistent.
135
+ - **Better long-reference, short-text cloning**: v1.5 handles scenarios where the reference audio is much longer than the target text more reliably than 1.0.
136
+ - **More stable punctuation-following prosody**: v1.5 follows punctuation-driven pauses more closely, especially in long sentences.
137
+ - **Explicit pause control**: v1.5 supports inline pause markers such as `"[pause 3.2s]"`. For example, `我今天学习了一首中国的古诗,它的名字是[pause 3.2s]静夜思!` inserts an explicit 3.2s pause before `静夜思`.
138
+
139
+ ## Supported Languages
140
+
141
+ MOSS-TTS-v1.5 currently supports **31 languages**. It keeps the 20 languages supported by [MOSS-TTS 1.0](https://huggingface.co/OpenMOSS-Team/MOSS-TTS) and extends multilingual continued training to additional languages including Cantonese, Dutch, Finnish, Hindi, Macedonian, Malay, Romanian, Swahili, Tagalog, Thai, and Vietnamese.
142
+
143
+ | Language | Code | Flag | Language | Code | Flag | Language | Code | Flag |
144
+ |---|---|---|---|---|---|---|---|---|
145
+ | Chinese | zh | 🇨🇳 | Cantonese | yue | 🇭🇰 | English | en | 🇺🇸 |
146
+ | Arabic | ar | 🇸🇦 | Czech | cs | 🇨🇿 | Danish | da | 🇩🇰 |
147
+ | Dutch | nl | 🇳🇱 | Finnish | fi | 🇫🇮 | French | fr | 🇫🇷 |
148
+ | German | de | 🇩🇪 | Greek | el | 🇬🇷 | Hebrew | he | 🇮🇱 |
149
+ | Hindi | hi | 🇮🇳 | Hungarian | hu | 🇭🇺 | Italian | it | 🇮🇹 |
150
+ | Japanese | ja | 🇯🇵 | Korean | ko | 🇰🇷 | Macedonian | mk | 🇲🇰 |
151
+ | Malay | ms | 🇲🇾 | Persian (Farsi) | fa | 🇮🇷 | Polish | pl | 🇵🇱 |
152
+ | Portuguese | pt | 🇵🇹 | Romanian | ro | 🇷🇴 | Russian | ru | 🇷🇺 |
153
+ | Spanish | es | 🇪🇸 | Swahili | sw | 🇹🇿 | Swedish | sv | 🇸🇪 |
154
+ | Tagalog | tl | 🇵🇭 | Thai | th | 🇹🇭 | Turkish | tr | 🇹🇷 |
155
+ | Vietnamese | vi | 🇻🇳 | | | | | | |
156
+
157
+
158
+ ## Quick Start
159
+
160
+ ### Environment Setup
161
+
162
+ We recommend a clean, isolated Python environment with **Transformers 5.0.0** to avoid dependency conflicts.
163
+
164
+ ```bash
165
+ conda create -n moss-tts python=3.12 -y
166
+ conda activate moss-tts
167
+ ```
168
+
169
+ Install all required dependencies:
170
+
171
+ ```bash
172
+ git clone https://github.com/OpenMOSS/MOSS-TTS.git
173
+ cd MOSS-TTS
174
+ pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e .
175
+ ```
176
+
177
+ #### (Optional) Install FlashAttention 2
178
+
179
+ For better speed and lower GPU memory usage, you can install FlashAttention 2 if your hardware supports it.
180
+
181
+ ```bash
182
+ pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]"
183
+ ```
184
+
185
+ If your machine has limited RAM and many CPU cores, you can cap build parallelism:
186
+
187
+ ```bash
188
+ MAX_JOBS=4 pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]"
189
+ ```
190
+
191
+ Notes:
192
+ - Dependencies are managed in `pyproject.toml`, which currently pins `torch==2.9.1+cu128` and `torchaudio==2.9.1+cu128`.
193
+ - If FlashAttention 2 fails to build on your machine, you can skip it and use the default attention backend.
194
+ - FlashAttention 2 is only available on supported GPUs and is typically used with `torch.float16` or `torch.bfloat16`.
195
+
196
+
197
+ ### Basic Usage
198
+
199
+ > Tip: MOSS-TTS-v1.5 uses the same generation API as the 1.0 **MossTTSDelay-8B** checkpoint. For multilingual inputs, set `language` whenever the language is known.
200
+
201
+ MOSS-TTS provides a convenient `generate` interface for rapid usage. The examples below cover:
202
+ 1. Direct generation (Chinese / English / multilingual text with language tags / Pinyin / IPA)
203
+ 2. Voice cloning
204
+ 3. Duration control
205
+ 4. Explicit pause control with `[pause X.Ys]`
206
+
207
+ ```python
208
+ from pathlib import Path
209
+ import importlib.util
210
+ import torch
211
+ import torchaudio
212
+ from transformers import AutoModel, AutoProcessor
213
+ # Disable the broken cuDNN SDPA backend
214
+ torch.backends.cuda.enable_cudnn_sdp(False)
215
+ # Keep these enabled as fallbacks
216
+ torch.backends.cuda.enable_flash_sdp(True)
217
+ torch.backends.cuda.enable_mem_efficient_sdp(True)
218
+ torch.backends.cuda.enable_math_sdp(True)
219
+
220
+
221
+ pretrained_model_name_or_path = "OpenMOSS-Team/MOSS-TTS-v1.5"
222
+ device = "cuda" if torch.cuda.is_available() else "cpu"
223
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
224
+
225
+ def resolve_attn_implementation() -> str:
226
+ # Prefer FlashAttention 2 when package + device conditions are met.
227
+ if (
228
+ device == "cuda"
229
+ and importlib.util.find_spec("flash_attn") is not None
230
+ and dtype in {torch.float16, torch.bfloat16}
231
+ ):
232
+ major, _ = torch.cuda.get_device_capability()
233
+ if major >= 8:
234
+ return "flash_attention_2"
235
+
236
+ # CUDA fallback: use PyTorch SDPA kernels.
237
+ if device == "cuda":
238
+ return "sdpa"
239
+
240
+ # CPU fallback.
241
+ return "eager"
242
+
243
+
244
+ attn_implementation = resolve_attn_implementation()
245
+ print(f"[INFO] Using attn_implementation={attn_implementation}")
246
+
247
+ processor = AutoProcessor.from_pretrained(
248
+ pretrained_model_name_or_path,
249
+ trust_remote_code=True,
250
+ )
251
+ processor.audio_tokenizer = processor.audio_tokenizer.to(device)
252
+
253
+ text_1 = "亲爱的你,\n你好呀。\n\n今天,我想用最认真、最温柔的声音,对你说一些重要的话。\n这些话,像一颗小小的星星,希望能在你的心里慢慢发光。\n\n首先,我想祝你——\n每天都能平平安安、快快乐乐。\n\n希望你早上醒来的时候,\n窗外有光,屋子里很安静,\n你的心是轻轻的,没有着急,也没有害怕。\n\n希望你吃饭的时候胃口很好,\n走路的时候脚步稳稳,\n晚上睡觉的时候,能做一个又一个甜甜的梦。\n\n我希望你能一直保持好奇心。\n对世界充满问题,\n对天空、星星、花草、书本和故事感兴趣。\n当你问“为什么”的时候,\n希望总有人愿意认真地听你说话。\n\n我也希望你学会温柔。\n温柔地对待朋友,\n温柔地对待小动物,\n也温柔地对待自己。\n\n如果有一天你犯了错,\n请不要太快责怪自己,\n因为每一个认真成长的人,\n都会在路上慢慢学会更好的方法。\n\n愿你拥有勇气。\n当你站在陌生的地方时,\n当你第一次举手发言时,\n当你遇到困难、感到害怕的时候,\n希望你能轻轻地告诉自己:\n“我可以试一试。”\n\n就算没有一次成功,也没有关系。\n失败不是坏事,\n它只是告诉你,你正在努力。\n\n我希望你学会分享快乐。\n把开心的事情告诉别人,\n把笑声送给身边的人,\n因为快乐被分享的时候,\n会变得更大、更亮。\n\n如果有一天你感到难过,\n我希望你知道——\n难过并不丢脸,\n哭泣也不是软弱。\n\n愿你能找到一个安全的地方,\n慢慢把心里的话说出来,\n然后再一次抬起头,看见希望。\n\n我还希望你能拥有梦想。\n这个梦想也许很大,\n也许很小,\n也许现在还说不清楚。\n\n没关系。\n梦想会和你一起长大,\n在时间里慢慢变得清楚。\n\n最后,我想送你一个最最重要的祝福:\n\n愿你被世界温柔对待,\n也愿你成为一个温柔的人。\n\n愿你的每一天,\n都值得被记住,\n都值得被珍惜。\n\n亲爱的你,\n请记住,\n你是独一无二的,\n你已经很棒了,\n而你的未来,\n一定会慢慢变得闪闪发光。\n\n祝你健康、勇敢、幸福,\n祝你永远带着笑容向前走。"
254
+ text_2 = "We stand on the threshold of the AI era.\nArtificial intelligence is no longer just a concept in laboratories, but is entering every industry, every creative endeavor, and every decision. It has learned to see, hear, speak, and think, and is beginning to become an extension of human capabilities. AI is not about replacing humans, but about amplifying human creativity, making knowledge more equitable, more efficient, and allowing imagination to reach further. A new era, jointly shaped by humans and intelligent systems, has arrived."
255
+ text_3 = "nin2 hao3,qing3 wen4 nin2 lai2 zi4 na3 zuo4 cheng2 shi4?"
256
+ text_4 = "nin2 hao3,qing4 wen3 nin2 lai2 zi4 na4 zuo3 cheng4 shi3?"
257
+ text_5 = "您好,请问您来自哪 zuo4 cheng2 shi4?"
258
+ text_6 = "/həloʊ, meɪ aɪ æsk wɪtʃ sɪti juː ɑːr frʌm?/"
259
+ text_7 = "Bonjour, je voudrais essayer une voix française naturelle et stable."
260
+ text_8 = "我今天学习了一首中国的古诗,它的名字是[pause 3.2s]静夜思!"
261
+
262
+ # Use audio from ./assets/audio to avoid downloading from the cloud.
263
+ ref_audio_1 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
264
+ ref_audio_2 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
265
+
266
+ conversations = [
267
+ # Direct TTS (no reference). Language tags are recommended in v1.5.
268
+ [processor.build_user_message(text=text_1)],
269
+ [processor.build_user_message(text=text_2)],
270
+ # Direct TTS (no reference). For languages ​​other than Chinese and English, it is recommended to use language tags.
271
+ [processor.build_user_message(text=text_7, language="French")],
272
+ # Pinyin or IPA input
273
+ [processor.build_user_message(text=text_3)],
274
+ [processor.build_user_message(text=text_4)],
275
+ [processor.build_user_message(text=text_5)],
276
+ [processor.build_user_message(text=text_6)],
277
+ # Explicit pause control. Use [pause X.Ys], such as [pause 3.2s].
278
+ [processor.build_user_message(text=text_8)],
279
+ # Voice cloning (with reference)
280
+ [processor.build_user_message(text=text_1, reference=[ref_audio_1])],
281
+ [processor.build_user_message(text=text_2, reference=[ref_audio_2])],
282
+ # Duration control
283
+ [processor.build_user_message(text=text_2, tokens=325)],
284
+ [processor.build_user_message(text=text_2, tokens=600)],
285
+ ]
286
+
287
+ model = AutoModel.from_pretrained(
288
+ pretrained_model_name_or_path,
289
+ trust_remote_code=True,
290
+ # If FlashAttention 2 is installed, you can set attn_implementation="flash_attention_2"
291
+ attn_implementation=attn_implementation,
292
+ torch_dtype=dtype,
293
+ ).to(device)
294
+ model.eval()
295
+
296
+ batch_size = 1
297
+
298
+ save_dir = Path("inference_root")
299
+ save_dir.mkdir(exist_ok=True, parents=True)
300
+ sample_idx = 0
301
+ with torch.no_grad():
302
+ for start in range(0, len(conversations), batch_size):
303
+ batch_conversations = conversations[start : start + batch_size]
304
+ batch = processor(batch_conversations, mode="generation")
305
+ input_ids = batch["input_ids"].to(device)
306
+ attention_mask = batch["attention_mask"].to(device)
307
+
308
+ outputs = model.generate(
309
+ input_ids=input_ids,
310
+ attention_mask=attention_mask,
311
+ max_new_tokens=4096,
312
+ )
313
+
314
+ for message in processor.decode(outputs):
315
+ audio = message.audio_codes_list[0]
316
+ out_path = save_dir / f"sample{sample_idx}.wav"
317
+ sample_idx += 1
318
+ torchaudio.save(out_path, audio.unsqueeze(0), processor.model_config.sampling_rate)
319
+
320
+ ```
321
+
322
+ ## More Usage
323
+
324
+ MOSS-TTS-v1.5 is API-compatible with MOSS-TTS 1.0. For continuation with prefix audio, detailed `UserMessage` and `AssistantMessage` fields, generation hyperparameters, Pinyin/IPA preprocessing examples, and evaluation results, see the [MOSS-TTS 1.0 README](https://huggingface.co/OpenMOSS-Team/MOSS-TTS).