Cqy2019 commited on
Commit
9914988
·
verified ·
1 Parent(s): eb293bd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +484 -482
README.md CHANGED
@@ -1,482 +1,484 @@
1
- ---
2
- license: apache-2.0
3
- ---
4
- # MOSS-TTS Family
5
-
6
-
7
- <br>
8
-
9
- <p align="center">
10
- &nbsp;&nbsp;&nbsp;&nbsp;
11
- <img src="https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_imgaes_demo/openmoss_x_mosi" height="50" align="middle" />
12
- </p>
13
-
14
-
15
-
16
- <div align="center">
17
- <a href="https://github.com/OpenMOSS/MOSS-TTS/tree/main"><img src="https://img.shields.io/badge/Project%20Page-GitHub-blue"></a>
18
- <a href="https://modelscope.cn/collections/OpenMOSS-Team/MOSS-TTS"><img src="https://img.shields.io/badge/ModelScope-Models-lightgrey?logo=modelscope&amp"></a>
19
- <a href="https://mosi.cn/#models"><img src="https://img.shields.io/badge/Blog-View-blue?logo=internet-explorer&amp"></a>
20
- <a href="https://github.com/OpenMOSS/MOSS-TTS"><img src="https://img.shields.io/badge/Arxiv-Coming%20soon-red?logo=arxiv&amp"></a>
21
-
22
- <a href="https://studio.mosi.cn"><img src="https://img.shields.io/badge/AIStudio-Try-green?logo=internet-explorer&amp"></a>
23
- <a href="https://studio.mosi.cn/docs/moss-tts"><img src="https://img.shields.io/badge/API-Docs-00A3FF?logo=fastapi&amp"></a>
24
- <a href="https://x.com/Open_MOSS"><img src="https://img.shields.io/badge/Twitter-Follow-black?logo=x&amp"></a>
25
- <a href="https://discord.gg/fvm5TaWjU3"><img src="https://img.shields.io/badge/Discord-Join-5865F2?logo=discord&amp"></a>
26
- </div>
27
-
28
-
29
- ## Overview
30
- MOSS‑TTS Family is an open‑source **speech and sound generation model family** from [MOSI.AI](https://mosi.cn/#hero) and the [OpenMOSS team](https://www.open-moss.com/). It is designed for **high‑fidelity**, **high‑expressiveness**, and **complex real‑world scenarios**, covering stable long‑form speech, multi‑speaker dialogue, voice/character design, environmental sound effects, and real‑time streaming TTS.
31
-
32
-
33
- ## Introduction
34
-
35
- <p align="center">
36
- <img src="https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_imgaes_demo/moss_tts_family_arch.jpeg" width="85%" />
37
- </p>
38
-
39
-
40
- When a single piece of audio needs to **sound like a real person**, **pronounce every word accurately**, **switch speaking styles across content**, **remain stable over tens of minutes**, and **support dialogue, role‑play, and real‑time interaction**, a single TTS model is often not enough. The **MOSS‑TTS Family** breaks the workflow into five production‑ready models that can be used independently or composed into a complete pipeline.
41
-
42
- - **MOSS‑TTS**: MOSS-TTS is the flagship production TTS foundation model, centered on high-fidelity zero-shot voice cloning with controllable long-form synthesis, pronunciation, and multilingual/code-switched speech. It serves as the core engine for scalable narration, dubbing, and voice-driven products.
43
- - **MOSS‑TTSD**: MOSS-TTSD is a production long-form dialogue model for expressive multi-speaker conversational audio at scale. It supports long-duration continuity, turn-taking control, and zero-shot voice cloning from short references for podcasts, audiobooks, commentary, dubbing, and entertainment dialogue.
44
- - **MOSS‑VoiceGenerator**: MOSS-VoiceGenerator is an open-source voice design model that creates speaker timbres directly from free-form text, without reference audio. It unifies timbre design, style control, and content synthesis, and can be used standalone or as a voice-design layer for downstream TTS.
45
- - **MOSS‑SoundEffect**: MOSS-SoundEffect is a high-fidelity text-to-sound model with broad category coverage and controllable duration for real content production. It generates stable audio from prompts across ambience, urban scenes, creatures, human actions, and music-like clips for film, games, interactive media, and data synthesis.
46
- - **MOSS‑TTS‑Realtime**: MOSS-TTS-Realtime is a context-aware, multi-turn streaming TTS model for real-time voice agents. By conditioning on dialogue history across both text and prior user acoustics, it delivers low-latency synthesis with coherent, consistent voice responses across turns.
47
-
48
-
49
- ## Released Models
50
-
51
- | Model | Architecture | Size | Model Card | Hugging Face |
52
- |---|---|---:|---|---|
53
- | **MOSS-TTS** | MossTTSDelay | 8B | [moss_tts_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_tts_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTS) |
54
- | | MossTTSLocal | 1.7B | [moss_tts_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_tts_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-Local-Transformer) |
55
- | **MOSS‑TTSD‑V1.0** | MossTTSDelay | 8B | [moss_ttsd_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_ttsd_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTSD-v1.0) |
56
- | **MOSS‑VoiceGenerator** | MossTTSDelay | 1.7B | [moss_voice_generator_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_voice_generator_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-Voice-Generator) |
57
- | **MOSS‑SoundEffect** | MossTTSDelay | 8B | [moss_sound_effect_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_sound_effect_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-SoundEffect) |
58
- | **MOSS‑TTS‑Realtime** | MossTTSRealtime | 1.7B | [moss_tts_realtime_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_tts_realtime_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-Realtime) |
59
-
60
-
61
-
62
- # MOSS-TTS
63
- **MOSS-TTS** is a next-generation, production-grade TTS foundation model focused on **voice cloning**, **ultra-long stable speech generation**, **token-level duration control**, **multilingual & code-switched synthesis**, and **fine-grained Pinyin/phoneme-level pronunciation control**. It is built on a clean autoregressive discrete-token recipe that emphasizes high-quality audio tokenization, large-scale diverse pre-training data, and efficient discrete token modeling.
64
-
65
- ## 1. Overview
66
- ### 1.1 TTS Family Positioning
67
- MOSS-TTS is the **flagship base model** in our open-source **TTS Family**. It is designed as a production-ready synthesis backbone that can serve as the primary high-quality engine for scalable voice applications, and as a strong research baseline for controllable TTS and discrete audio token modeling.
68
-
69
- **Design goals**
70
- - **Production readiness**: robust voice cloning with stable, on-brand speaker identity at scale
71
- - **Controllability**: duration and pronunciation controls that integrate into real workflows
72
- - **Long-form stability**: consistent identity and delivery for extended narration
73
- - **Multilingual coverage**: multilingual and code-switched synthesis as first-class capabilities
74
-
75
-
76
-
77
- ### 1.2 Key Capabilities
78
-
79
- MOSS-TTS delivers state-of-the-art quality while providing the fine-grained controllability and long-form stability required for production-grade voice applications, from zero-shot cloning and hour-long narration to token- and phoneme-level control across multilingual and code-switched speech.
80
-
81
- * **State-of-the-art evaluation performance** top-tier objective and subjective results across standard TTS benchmarks and in-house human preference testing, validating both fidelity and naturalness.
82
- * **Zero-shot Voice Cloning (Voice Clone)** — clone a target speaker’s timbre (and part of speaking style) from short reference audio, without speaker-specific fine-tuning.
83
- * **Ultra-long Speech Generation (up to 1 hour)** — support continuous long-form speech generation for up to one hour in a single run, designed for extended narration and long-session content creation.
84
- * **Token-level Duration Control** — control pacing, rhythm, pauses, and speaking rate at token resolution for precise alignment and expressive delivery.
85
- * **Phoneme-level Pronunciation Control** — supports:
86
-
87
- * pure **Pinyin** input
88
- * pure **IPA** phoneme input
89
- * mixed **Chinese / English / Pinyin / IPA** input in any combination
90
- * **Multilingual support** high-quality multilingual synthesis with robust generalization across languages and accents.
91
- * **Code-switching** — natural mixed-language generation within a single utterance (e.g., Chinese–English), with smooth transitions, consistent speaker identity, and pronunciation-aware rendering on both sides of the switch.
92
-
93
-
94
-
95
- ### 1.3 Model Architecture
96
-
97
- MOSS-TTS includes **two complementary architectures**, both trained and released to explore different performance/latency tradeoffs and to support downstream research.
98
-
99
- **Architecture A: Delay Pattern (MossTTSDelay)**
100
- - Single Transformer backbone with **(n_vq + 1) heads**.
101
- - Uses **delay scheduling** for multi-codebook audio tokens.
102
- - Strong long-context stability, efficient inference, and production-friendly behavior.
103
-
104
- **Architecture B: Global Latent + Local Transformer (MossTTSLocal)**
105
- - Backbone produces a **global latent** per time step.
106
- - A lightweight **Local Transformer** emits a token block per step.
107
- - **Streaming-friendly** with simpler alignment (no delay scheduling).
108
-
109
- **Why train both?**
110
- - **Exploration of architectural potential** and validation across multiple generation paradigms.
111
- - **Different tradeoffs**: Delay pattern tends to be faster and more stable for long-form synthesis; Local is smaller and excels on objective benchmarks.
112
- - **Open-source value**: two strong baselines for research, ablation, and downstream innovation.
113
-
114
- For full details, see:
115
- - **[moss_tts_delay/README.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/moss_tts_delay/README.md)**
116
- - **[moss_tts_local/README.md](https://github.com/OpenMOSS/MOSS-TTS/tree/main/moss_tts_local)**
117
-
118
-
119
-
120
- ### 1.4 Released Models
121
-
122
- | Model | Description |
123
- |---|---|
124
- | **MossTTSDelay-8B** | **Recommended for production**. Faster inference, stronger long-context stability, and robust voice cloning quality. Best for large-scale deployment and long-form narration. |
125
- | **MossTTSLocal-1.7B** | **Recommended for evaluation and research**. Smaller model size with SOTA objective metrics. Great for quick experiments, ablations, and academic studies. |
126
-
127
- **Recommended decoding hyperparameters (per model)**
128
-
129
- | Model | audio_temperature | audio_top_p | audio_top_k | audio_repetition_penalty |
130
- |---|---:|---:|---:|---:|
131
- | **MossTTSDelay-8B** | 1.7 | 0.8 | 25 | 1.0 |
132
- | **MossTTSLocal-1.7B** | 1.0 | 0.95 | 50 | 1.1 |
133
-
134
-
135
-
136
- ## 2. Quick Start
137
-
138
-
139
-
140
- ### Environment Setup
141
-
142
- We recommend a clean, isolated Python environment with **Transformers 5.0.0** to avoid dependency conflicts.
143
-
144
- ```bash
145
- conda create -n moss-tts python=3.12 -y
146
- conda activate moss-tts
147
- ```
148
-
149
- Install all required dependencies:
150
-
151
- ```bash
152
- git clone https://github.com/OpenMOSS/MOSS-TTS.git
153
- cd MOSS-TTS
154
- pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e .
155
- ```
156
-
157
- #### (Optional) Install FlashAttention 2
158
-
159
- For better speed and lower GPU memory usage, you can install FlashAttention 2 if your hardware supports it.
160
-
161
- ```bash
162
- pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]"
163
- ```
164
-
165
- If your machine has limited RAM and many CPU cores, you can cap build parallelism:
166
-
167
- ```bash
168
- MAX_JOBS=4 pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]"
169
- ```
170
-
171
- Notes:
172
- - Dependencies are managed in `pyproject.toml`, which currently pins `torch==2.9.1+cu128` and `torchaudio==2.9.1+cu128`.
173
- - If FlashAttention 2 fails to build on your machine, you can skip it and use the default attention backend.
174
- - FlashAttention 2 is only available on supported GPUs and is typically used with `torch.float16` or `torch.bfloat16`.
175
-
176
-
177
- ### Basic Usage
178
-
179
-
180
-
181
- > Tip: For production usage, prioritize **MossTTSDelay-8B**. The examples below use this model; **MossTTSLocal-1.7B** supports the same API, and a practical walkthrough is available in [moss_tts_local/README.md](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-Local-Transformer).
182
-
183
- MOSS-TTS provides a convenient `generate` interface for rapid usage. The examples below cover:
184
- 1. Direct generation (Chinese / English / Pinyin / IPA)
185
- 2. Voice cloning
186
- 3. Duration control
187
-
188
- ```python
189
- import os
190
- from pathlib import Path
191
- import torch
192
- import torchaudio
193
- from transformers import AutoModel, AutoProcessor
194
- # Disable the broken cuDNN SDPA backend
195
- torch.backends.cuda.enable_cudnn_sdp(False)
196
- # Keep these enabled as fallbacks
197
- torch.backends.cuda.enable_flash_sdp(True)
198
- torch.backends.cuda.enable_mem_efficient_sdp(True)
199
- torch.backends.cuda.enable_math_sdp(True)
200
-
201
-
202
- pretrained_model_name_or_path = "OpenMOSS-Team/MOSS-TTS"
203
- device = "cuda" if torch.cuda.is_available() else "cpu"
204
- dtype = torch.bfloat16 if device == "cuda" else torch.float32
205
-
206
- processor = AutoProcessor.from_pretrained(
207
- pretrained_model_name_or_path,
208
- trust_remote_code=True,
209
- )
210
- processor.audio_tokenizer = processor.audio_tokenizer.to(device)
211
-
212
- 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祝你永远带着笑容向前走。"
213
- 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."
214
- text_3 = "nin2 hao3,qing3 wen4 nin2 lai2 zi4 na3 zuo4 cheng2 shi4?"
215
- text_4 = "nin2 hao3,qing4 wen3 nin2 lai2 zi4 na4 zuo3 cheng4 shi3?"
216
- text_5 = "您好,请问您来自哪 zuo4 cheng2 shi4?"
217
- text_6 = "/həloʊ, meɪ æsk wɪtʃ sɪti juː ɑːr frʌm?/"
218
-
219
- ref_audio_1 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
220
- ref_audio_2 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
221
-
222
- conversations = [
223
- # Direct TTS (no reference)
224
- [processor.build_user_message(text=text_1)],
225
- [processor.build_user_message(text=text_2)],
226
- # Pinyin or IPA input
227
- [processor.build_user_message(text=text_3)],
228
- [processor.build_user_message(text=text_4)],
229
- [processor.build_user_message(text=text_5)],
230
- [processor.build_user_message(text=text_6)],
231
- # Voice cloning (with reference)
232
- [processor.build_user_message(text=text_1, reference=[ref_audio_1])],
233
- [processor.build_user_message(text=text_2, reference=[ref_audio_2])],
234
- # Duration control
235
- [processor.build_user_message(text=text_2, tokens=325)],
236
- [processor.build_user_message(text=text_2, tokens=600)],
237
- ]
238
-
239
- model = AutoModel.from_pretrained(
240
- pretrained_model_name_or_path,
241
- trust_remote_code=True,
242
- attn_implementation="sdpa",
243
- torch_dtype=dtype,
244
- ).to(device)
245
- model.eval()
246
-
247
- batch_size = 1
248
-
249
- messages = []
250
- save_dir = Path("inference_root")
251
- save_dir.mkdir(exist_ok=True, parents=True)
252
- sample_idx = 0
253
- with torch.no_grad():
254
- for start in range(0, len(conversations), batch_size):
255
- batch_conversations = conversations[start : start + batch_size]
256
- batch = processor(batch_conversations, mode="generation")
257
- input_ids = batch["input_ids"].to(device)
258
- attention_mask = batch["attention_mask"].to(device)
259
-
260
- outputs = model.generate(
261
- input_ids=input_ids,
262
- attention_mask=attention_mask,
263
- max_new_tokens=4096,
264
- )
265
-
266
- for message in processor.decode(outputs):
267
- audio = message.audio_codes_list[0]
268
- out_path = save_dir / f"sample{sample_idx}.wav"
269
- sample_idx += 1
270
- torchaudio.save(out_path, audio.unsqueeze(0), processor.model_config.sampling_rate)
271
-
272
- ```
273
-
274
- ### Continuation + Voice Cloning (Prefix Audio + Text)
275
-
276
- MOSS-TTS supports continuation-based cloning: provide a prefix audio clip in the assistant message, and make sure the **prefix transcript** is included in the text. The model continues in the same speaker identity and style.
277
-
278
- ```python
279
- import os
280
- from pathlib import Path
281
- import torch
282
- import torchaudio
283
- from transformers import AutoModel, AutoProcessor
284
- # Disable the broken cuDNN SDPA backend
285
- torch.backends.cuda.enable_cudnn_sdp(False)
286
- # Keep these enabled as fallbacks
287
- torch.backends.cuda.enable_flash_sdp(True)
288
- torch.backends.cuda.enable_mem_efficient_sdp(True)
289
- torch.backends.cuda.enable_math_sdp(True)
290
-
291
-
292
- pretrained_model_name_or_path = "OpenMOSS-Team/MOSS-TTS"
293
- device = "cuda" if torch.cuda.is_available() else "cpu"
294
- dtype = torch.bfloat16 if device == "cuda" else torch.float32
295
-
296
- processor = AutoProcessor.from_pretrained(
297
- pretrained_model_name_or_path,
298
- trust_remote_code=True
299
- )
300
- processor.audio_tokenizer = processor.audio_tokenizer.to(device)
301
-
302
- 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祝你永远带着笑容向前走。"
303
- 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."
304
- ref_text_1 = "太阳系八大行星之一。"
305
- ref_text_2 = "But I really can't complain about not having a normal college experience to you."
306
- ref_audio_1 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
307
- ref_audio_2 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
308
-
309
- conversations = [
310
- # Continuatoin only
311
- [
312
- processor.build_user_message(text=ref_text_1 + text_1),
313
- processor.build_assistant_message(audio_codes_list=[ref_audio_1])
314
- ],
315
- # Continuation with voice cloning
316
- [
317
- processor.build_user_message(text=ref_text_2 + text_2, reference=[ref_audio_2]),
318
- processor.build_assistant_message(audio_codes_list=[ref_audio_2])
319
- ],
320
- ]
321
-
322
- model = AutoModel.from_pretrained(
323
- pretrained_model_name_or_path,
324
- trust_remote_code=True,
325
- attn_implementation="sdpa",
326
- torch_dtype=dtype,
327
- ).to(device)
328
- model.eval()
329
-
330
- batch_size = 1
331
-
332
- messages = []
333
- save_dir = Path("inference_root")
334
- save_dir.mkdir(exist_ok=True, parents=True)
335
- sample_idx = 0
336
- with torch.no_grad():
337
- for start in range(0, len(conversations), batch_size):
338
- batch_conversations = conversations[start : start + batch_size]
339
- batch = processor(batch_conversations, mode="continuation")
340
- input_ids = batch["input_ids"].to(device)
341
- attention_mask = batch["attention_mask"].to(device)
342
-
343
- outputs = model.generate(
344
- input_ids=input_ids,
345
- attention_mask=attention_mask,
346
- max_new_tokens=4096,
347
- )
348
-
349
- for message in processor.decode(outputs):
350
- audio = message.audio_codes_list[0]
351
- out_path = save_dir / f"sample{sample_idx}.wav"
352
- sample_idx += 1
353
- torchaudio.save(out_path, audio.unsqueeze(0), processor.model_config.sampling_rate)
354
-
355
- ```
356
-
357
-
358
-
359
- ### Input Types
360
-
361
- **UserMessage**
362
-
363
- | Field | Type | Required | Description |
364
- |---|---|---:|---|
365
- | `text` | `str` | Yes | Text to synthesize. Supports Chinese, English, German, French, Spanish, Japanese, Korean, etc. Can mix raw text with Pinyin or IPA for pronunciation control. |
366
- | `reference` | `List[str]` | No | Reference audio for voice cloning. For current MOSS-TTS, **one audio** is expected in the list. |
367
- | `tokens` | `int` | No | Expected number of audio tokens. **1s 12.5 tokens**. |
368
-
369
- **AssistantMessage**
370
-
371
- | Field | Type | Required | Description |
372
- |---|---|---:|---|
373
- | `audio_codes_list` | `List[str]` | Only for continuation | Prefix audio for continuation-based cloning. Use audio file paths or URLs. |
374
-
375
-
376
-
377
- ### Generation Hyperparameters
378
-
379
- | Parameter | Type | Default | Description |
380
- |---|---|---:|---|
381
- | `max_new_tokens` | `int` | | Controls total generated audio tokens. Use duration rule: **1s ≈ 12.5 tokens**. |
382
- | `audio_temperature` | `float` | 1.7 | Higher values increase variation; lower values stabilize prosody. |
383
- | `audio_top_p` | `float` | 0.8 | Nucleus sampling cutoff. Lower values are more conservative. |
384
- | `audio_top_k` | `int` | 25 | Top-K sampling. Lower values tighten sampling space. |
385
- | `audio_repetition_penalty` | `float` | 1.0 | >1.0 discourages repeating patterns. |
386
-
387
- > Note: MOSS-TTS is a pretrained base model and is **sensitive to decoding hyperparameters**. See **Released Models** for recommended defaults.
388
-
389
-
390
-
391
- ### Pinyin Input
392
-
393
- Use tone-numbered Pinyin such as `ni3 hao3 wo3 men1`. You can convert Chinese text with [pypinyin](https://github.com/mozillazg/python-pinyin), then adjust tones for pronunciation control.
394
-
395
- ```python
396
- import re
397
- from pypinyin import pinyin, Style
398
-
399
- CN_PUNCT = r",。!?;:、()“”‘’"
400
-
401
-
402
- def fix_punctuation_spacing(s: str) -> str:
403
- s = re.sub(rf"\s+([{CN_PUNCT}])", r"\1", s)
404
- s = re.sub(rf"([{CN_PUNCT}])\s+", r"\1", s)
405
- return s
406
-
407
-
408
- def zh_to_pinyin_tone3(text: str, strict: bool = True) -> str:
409
- result = pinyin(
410
- text,
411
- style=Style.TONE3,
412
- heteronym=False,
413
- strict=strict,
414
- errors="default",
415
- )
416
-
417
- s = " ".join(item[0] for item in result)
418
- return fix_punctuation_spacing(s)
419
-
420
- text = zh_to_pinyin_tone3("您好,请问您来自哪座城市?")
421
- print(text)
422
-
423
- # Expected: nin2 hao3,qing3 wen4 nin2 lai2 zi4 na3 zuo4 cheng2 shi4?
424
- # Try: nin2 hao3,qing4 wen3 nin2 lai2 zi4 na4 zuo3 cheng4 shi3?
425
- ```
426
-
427
-
428
-
429
- ### IPA Input
430
-
431
- Use `/.../` to wrap IPA sequences so they are distinct from normal text. You can use [DeepPhonemizer](https://github.com/spring-media/DeepPhonemizer) to convert English paragraphs or words into IPA sequences.
432
-
433
- ```python
434
- from dp.phonemizer import Phonemizer
435
-
436
- # Download a phonemizer checkpoint from https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt
437
- model_path = "<path-to-phonemizer-checkpoint>"
438
- phonemizer = Phonemizer.from_checkpoint(model_path)
439
-
440
- english_texts = "Hello, may I ask which city you are from?"
441
- phoneme_outputs = phonemizer(
442
- english_texts,
443
- lang="en_us",
444
- batch_size=8
445
- )
446
- model_input_text = f"/{phoneme_outputs}/"
447
- print(model_input_text)
448
-
449
- # Expected: /həloʊ, meɪ aɪ æsk wɪtʃ sɪti juː ɑːr frʌm?/
450
- ```
451
-
452
-
453
-
454
- ## 3. Evaluation
455
- MOSS-TTS achieved state-of-the-art results on the open-source zero-shot TTS benchmark Seed-TTS-eval, not only surpassing all open-source models but also rivaling the most powerful closed-source models.
456
-
457
- | Model | Params | Open-source | EN WER (%) | EN SIM (%) | ZH CER (%) | ZH SIM (%) ↑ |
458
- |---|---:|:---:|---:|---:|---:|---:|
459
- | DiTAR | 0.6B | | 1.69 | 73.5 | 1.02 | 75.3 |
460
- | FishAudio-S1 | 4B | ❌ | 1.72 | 62.57 | 1.22 | 72.1 |
461
- | Seed-TTS | | ❌ | 2.25 | 76.2 | 1.12 | 79.6 |
462
- | MiniMax-Speech | | ❌ | 1.65 | 69.2 | 0.83 | 78.3 |
463
- | | | | | | | |
464
- | CosyVoice | 0.3B | | 4.29 | 60.9 | 3.63 | 72.3 |
465
- | CosyVoice2 | 0.5B || 3.09 | 65.9 | 1.38 | 75.7 |
466
- | CosyVoice3 | 0.5B | ✅ | 2.02 | 71.8 | 1.16 | 78 |
467
- | CosyVoice3 | 1.5B | ✅ | 2.22 | 72 | 1.12 | 78.1 |
468
- | F5-TTS | 0.3B | ✅ | 2 | 67 | 1.53 | 76 |
469
- | SparkTTS | 0.5B | ✅ | 3.14 | 57.3 | 1.54 | 66 |
470
- | FireRedTTS | 0.5B | ✅ | 3.82 | 46 | 1.51 | 63.5 |
471
- | FireRedTTS-2 | 1.5B | ✅ | 1.95 | 66.5 | 1.14 | 73.6 |
472
- | Qwen2.5-Omni | 7B | ✅ | 2.72 | 63.2 | 1.7 | 75.2 |
473
- | FishAudio-S1-mini | 0.5B | ✅ | 1.94 | 55 | 1.18 | 68.5 |
474
- | IndexTTS2 | 1.5B | ✅ | 2.23 | 70.6 | 1.03 | 76.5 |
475
- | VibeVoice | 1.5B | ✅ | 3.04 | 68.9 | 1.16 | 74.4 |
476
- | HiggsAudio-v2 | 3B | ✅ | 2.44 | 67.7 | 1.5 | 74 |
477
- | VoxCPM | 0.5B | ✅ | 1.85 | 72.9 | **0.93** | 77.2 |
478
- | Qwen3-TTS | 0.6B | ✅ | 1.68 | 70.39 | 1.23 | 76.4 |
479
- | Qwen3-TTS | 1.7B | ✅ | **1.5** | 71.45 | 1.33 | 76.72 |
480
- | | | | | | | |
481
- | MossTTSDelay | 8B | ✅ | 1.79 | 71.46 | 1.32 | 77.05 |
482
- | MossTTSLocal | 1.7B || 1.85 | **73.42** | 1.2 | **78.82** |
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - text-to-speech
5
+ ---
6
+ # MOSS-TTS Family
7
+
8
+
9
+ <br>
10
+
11
+ <p align="center">
12
+ &nbsp;&nbsp;&nbsp;&nbsp;
13
+ <img src="https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_imgaes_demo/openmoss_x_mosi" height="50" align="middle" />
14
+ </p>
15
+
16
+
17
+
18
+ <div align="center">
19
+ <a href="https://github.com/OpenMOSS/MOSS-TTS/tree/main"><img src="https://img.shields.io/badge/Project%20Page-GitHub-blue"></a>
20
+ <a href="https://modelscope.cn/collections/OpenMOSS-Team/MOSS-TTS"><img src="https://img.shields.io/badge/ModelScope-Models-lightgrey?logo=modelscope&amp"></a>
21
+ <a href="https://mosi.cn/#models"><img src="https://img.shields.io/badge/Blog-View-blue?logo=internet-explorer&amp"></a>
22
+ <a href="https://github.com/OpenMOSS/MOSS-TTS"><img src="https://img.shields.io/badge/Arxiv-Coming%20soon-red?logo=arxiv&amp"></a>
23
+
24
+ <a href="https://studio.mosi.cn"><img src="https://img.shields.io/badge/AIStudio-Try-green?logo=internet-explorer&amp"></a>
25
+ <a href="https://studio.mosi.cn/docs/moss-tts"><img src="https://img.shields.io/badge/API-Docs-00A3FF?logo=fastapi&amp"></a>
26
+ <a href="https://x.com/Open_MOSS"><img src="https://img.shields.io/badge/Twitter-Follow-black?logo=x&amp"></a>
27
+ <a href="https://discord.gg/fvm5TaWjU3"><img src="https://img.shields.io/badge/Discord-Join-5865F2?logo=discord&amp"></a>
28
+ </div>
29
+
30
+
31
+ ## Overview
32
+ MOSS‑TTS Family is an open‑source **speech and sound generation model family** from [MOSI.AI](https://mosi.cn/#hero) and the [OpenMOSS team](https://www.open-moss.com/). It is designed for **high‑fidelity**, **high‑expressiveness**, and **complex real‑world scenarios**, covering stable long‑form speech, multi‑speaker dialogue, voice/character design, environmental sound effects, and real‑time streaming TTS.
33
+
34
+
35
+ ## Introduction
36
+
37
+ <p align="center">
38
+ <img src="https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_imgaes_demo/moss_tts_family_arch.jpeg" width="85%" />
39
+ </p>
40
+
41
+
42
+ When a single piece of audio needs to **sound like a real person**, **pronounce every word accurately**, **switch speaking styles across content**, **remain stable over tens of minutes**, and **support dialogue, role‑play, and real‑time interaction**, a single TTS model is often not enough. The **MOSS‑TTS Family** breaks the workflow into five production‑ready models that can be used independently or composed into a complete pipeline.
43
+
44
+ - **MOSS‑TTS**: MOSS-TTS is the flagship production TTS foundation model, centered on high-fidelity zero-shot voice cloning with controllable long-form synthesis, pronunciation, and multilingual/code-switched speech. It serves as the core engine for scalable narration, dubbing, and voice-driven products.
45
+ - **MOSS‑TTSD**: MOSS-TTSD is a production long-form dialogue model for expressive multi-speaker conversational audio at scale. It supports long-duration continuity, turn-taking control, and zero-shot voice cloning from short references for podcasts, audiobooks, commentary, dubbing, and entertainment dialogue.
46
+ - **MOSS‑VoiceGenerator**: MOSS-VoiceGenerator is an open-source voice design model that creates speaker timbres directly from free-form text, without reference audio. It unifies timbre design, style control, and content synthesis, and can be used standalone or as a voice-design layer for downstream TTS.
47
+ - **MOSS‑SoundEffect**: MOSS-SoundEffect is a high-fidelity text-to-sound model with broad category coverage and controllable duration for real content production. It generates stable audio from prompts across ambience, urban scenes, creatures, human actions, and music-like clips for film, games, interactive media, and data synthesis.
48
+ - **MOSS‑TTS‑Realtime**: MOSS-TTS-Realtime is a context-aware, multi-turn streaming TTS model for real-time voice agents. By conditioning on dialogue history across both text and prior user acoustics, it delivers low-latency synthesis with coherent, consistent voice responses across turns.
49
+
50
+
51
+ ## Released Models
52
+
53
+ | Model | Architecture | Size | Model Card | Hugging Face |
54
+ |---|---|---:|---|---|
55
+ | **MOSS-TTS** | MossTTSDelay | 8B | [moss_tts_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_tts_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTS) |
56
+ | | MossTTSLocal | 1.7B | [moss_tts_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_tts_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-Local-Transformer) |
57
+ | **MOSS‑TTSD‑V1.0** | MossTTSDelay | 8B | [moss_ttsd_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_ttsd_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTSD-v1.0) |
58
+ | **MOSS‑VoiceGenerator** | MossTTSDelay | 1.7B | [moss_voice_generator_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_voice_generator_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-Voice-Generator) |
59
+ | **MOSS‑SoundEffect** | MossTTSDelay | 8B | [moss_sound_effect_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_sound_effect_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-SoundEffect) |
60
+ | **MOSS‑TTS‑Realtime** | MossTTSRealtime | 1.7B | [moss_tts_realtime_model_card.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/docs/moss_tts_realtime_model_card.md) | 🤗 [Huggingface](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-Realtime) |
61
+
62
+
63
+
64
+ # MOSS-TTS
65
+ **MOSS-TTS** is a next-generation, production-grade TTS foundation model focused on **voice cloning**, **ultra-long stable speech generation**, **token-level duration control**, **multilingual & code-switched synthesis**, and **fine-grained Pinyin/phoneme-level pronunciation control**. It is built on a clean autoregressive discrete-token recipe that emphasizes high-quality audio tokenization, large-scale diverse pre-training data, and efficient discrete token modeling.
66
+
67
+ ## 1. Overview
68
+ ### 1.1 TTS Family Positioning
69
+ MOSS-TTS is the **flagship base model** in our open-source **TTS Family**. It is designed as a production-ready synthesis backbone that can serve as the primary high-quality engine for scalable voice applications, and as a strong research baseline for controllable TTS and discrete audio token modeling.
70
+
71
+ **Design goals**
72
+ - **Production readiness**: robust voice cloning with stable, on-brand speaker identity at scale
73
+ - **Controllability**: duration and pronunciation controls that integrate into real workflows
74
+ - **Long-form stability**: consistent identity and delivery for extended narration
75
+ - **Multilingual coverage**: multilingual and code-switched synthesis as first-class capabilities
76
+
77
+
78
+
79
+ ### 1.2 Key Capabilities
80
+
81
+ MOSS-TTS delivers state-of-the-art quality while providing the fine-grained controllability and long-form stability required for production-grade voice applications, from zero-shot cloning and hour-long narration to token- and phoneme-level control across multilingual and code-switched speech.
82
+
83
+ * **State-of-the-art evaluation performance** — top-tier objective and subjective results across standard TTS benchmarks and in-house human preference testing, validating both fidelity and naturalness.
84
+ * **Zero-shot Voice Cloning (Voice Clone)** — clone a target speaker’s timbre (and part of speaking style) from short reference audio, without speaker-specific fine-tuning.
85
+ * **Ultra-long Speech Generation (up to 1 hour)** — support continuous long-form speech generation for up to one hour in a single run, designed for extended narration and long-session content creation.
86
+ * **Token-level Duration Control** — control pacing, rhythm, pauses, and speaking rate at token resolution for precise alignment and expressive delivery.
87
+ * **Phoneme-level Pronunciation Control** — supports:
88
+
89
+ * pure **Pinyin** input
90
+ * pure **IPA** phoneme input
91
+ * mixed **Chinese / English / Pinyin / IPA** input in any combination
92
+ * **Multilingual support** — high-quality multilingual synthesis with robust generalization across languages and accents.
93
+ * **Code-switching** — natural mixed-language generation within a single utterance (e.g., Chinese–English), with smooth transitions, consistent speaker identity, and pronunciation-aware rendering on both sides of the switch.
94
+
95
+
96
+
97
+ ### 1.3 Model Architecture
98
+
99
+ MOSS-TTS includes **two complementary architectures**, both trained and released to explore different performance/latency tradeoffs and to support downstream research.
100
+
101
+ **Architecture A: Delay Pattern (MossTTSDelay)**
102
+ - Single Transformer backbone with **(n_vq + 1) heads**.
103
+ - Uses **delay scheduling** for multi-codebook audio tokens.
104
+ - Strong long-context stability, efficient inference, and production-friendly behavior.
105
+
106
+ **Architecture B: Global Latent + Local Transformer (MossTTSLocal)**
107
+ - Backbone produces a **global latent** per time step.
108
+ - A lightweight **Local Transformer** emits a token block per step.
109
+ - **Streaming-friendly** with simpler alignment (no delay scheduling).
110
+
111
+ **Why train both?**
112
+ - **Exploration of architectural potential** and validation across multiple generation paradigms.
113
+ - **Different tradeoffs**: Delay pattern tends to be faster and more stable for long-form synthesis; Local is smaller and excels on objective benchmarks.
114
+ - **Open-source value**: two strong baselines for research, ablation, and downstream innovation.
115
+
116
+ For full details, see:
117
+ - **[moss_tts_delay/README.md](https://github.com/OpenMOSS/MOSS-TTS/blob/main/moss_tts_delay/README.md)**
118
+ - **[moss_tts_local/README.md](https://github.com/OpenMOSS/MOSS-TTS/tree/main/moss_tts_local)**
119
+
120
+
121
+
122
+ ### 1.4 Released Models
123
+
124
+ | Model | Description |
125
+ |---|---|
126
+ | **MossTTSDelay-8B** | **Recommended for production**. Faster inference, stronger long-context stability, and robust voice cloning quality. Best for large-scale deployment and long-form narration. |
127
+ | **MossTTSLocal-1.7B** | **Recommended for evaluation and research**. Smaller model size with SOTA objective metrics. Great for quick experiments, ablations, and academic studies. |
128
+
129
+ **Recommended decoding hyperparameters (per model)**
130
+
131
+ | Model | audio_temperature | audio_top_p | audio_top_k | audio_repetition_penalty |
132
+ |---|---:|---:|---:|---:|
133
+ | **MossTTSDelay-8B** | 1.7 | 0.8 | 25 | 1.0 |
134
+ | **MossTTSLocal-1.7B** | 1.0 | 0.95 | 50 | 1.1 |
135
+
136
+
137
+
138
+ ## 2. Quick Start
139
+
140
+
141
+
142
+ ### Environment Setup
143
+
144
+ We recommend a clean, isolated Python environment with **Transformers 5.0.0** to avoid dependency conflicts.
145
+
146
+ ```bash
147
+ conda create -n moss-tts python=3.12 -y
148
+ conda activate moss-tts
149
+ ```
150
+
151
+ Install all required dependencies:
152
+
153
+ ```bash
154
+ git clone https://github.com/OpenMOSS/MOSS-TTS.git
155
+ cd MOSS-TTS
156
+ pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e .
157
+ ```
158
+
159
+ #### (Optional) Install FlashAttention 2
160
+
161
+ For better speed and lower GPU memory usage, you can install FlashAttention 2 if your hardware supports it.
162
+
163
+ ```bash
164
+ pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]"
165
+ ```
166
+
167
+ If your machine has limited RAM and many CPU cores, you can cap build parallelism:
168
+
169
+ ```bash
170
+ MAX_JOBS=4 pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]"
171
+ ```
172
+
173
+ Notes:
174
+ - Dependencies are managed in `pyproject.toml`, which currently pins `torch==2.9.1+cu128` and `torchaudio==2.9.1+cu128`.
175
+ - If FlashAttention 2 fails to build on your machine, you can skip it and use the default attention backend.
176
+ - FlashAttention 2 is only available on supported GPUs and is typically used with `torch.float16` or `torch.bfloat16`.
177
+
178
+
179
+ ### Basic Usage
180
+
181
+
182
+
183
+ > Tip: For production usage, prioritize **MossTTSDelay-8B**. The examples below use this model; **MossTTSLocal-1.7B** supports the same API, and a practical walkthrough is available in [moss_tts_local/README.md](https://huggingface.co/OpenMOSS-Team/MOSS-TTS-Local-Transformer).
184
+
185
+ MOSS-TTS provides a convenient `generate` interface for rapid usage. The examples below cover:
186
+ 1. Direct generation (Chinese / English / Pinyin / IPA)
187
+ 2. Voice cloning
188
+ 3. Duration control
189
+
190
+ ```python
191
+ import os
192
+ from pathlib import Path
193
+ import torch
194
+ import torchaudio
195
+ from transformers import AutoModel, AutoProcessor
196
+ # Disable the broken cuDNN SDPA backend
197
+ torch.backends.cuda.enable_cudnn_sdp(False)
198
+ # Keep these enabled as fallbacks
199
+ torch.backends.cuda.enable_flash_sdp(True)
200
+ torch.backends.cuda.enable_mem_efficient_sdp(True)
201
+ torch.backends.cuda.enable_math_sdp(True)
202
+
203
+
204
+ pretrained_model_name_or_path = "OpenMOSS-Team/MOSS-TTS"
205
+ device = "cuda" if torch.cuda.is_available() else "cpu"
206
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
207
+
208
+ processor = AutoProcessor.from_pretrained(
209
+ pretrained_model_name_or_path,
210
+ trust_remote_code=True,
211
+ )
212
+ processor.audio_tokenizer = processor.audio_tokenizer.to(device)
213
+
214
+ 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祝你永远带着笑容向前走。"
215
+ 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."
216
+ text_3 = "nin2 hao3,qing3 wen4 nin2 lai2 zi4 na3 zuo4 cheng2 shi4?"
217
+ text_4 = "nin2 hao3,qing4 wen3 nin2 lai2 zi4 na4 zuo3 cheng4 shi3?"
218
+ text_5 = "您好,请问您来自哪 zuo4 cheng2 shi4?"
219
+ text_6 = "/həloʊ, meɪ aɪ æsk wɪtʃ sɪti juː ɑːr frʌm?/"
220
+
221
+ ref_audio_1 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
222
+ ref_audio_2 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
223
+
224
+ conversations = [
225
+ # Direct TTS (no reference)
226
+ [processor.build_user_message(text=text_1)],
227
+ [processor.build_user_message(text=text_2)],
228
+ # Pinyin or IPA input
229
+ [processor.build_user_message(text=text_3)],
230
+ [processor.build_user_message(text=text_4)],
231
+ [processor.build_user_message(text=text_5)],
232
+ [processor.build_user_message(text=text_6)],
233
+ # Voice cloning (with reference)
234
+ [processor.build_user_message(text=text_1, reference=[ref_audio_1])],
235
+ [processor.build_user_message(text=text_2, reference=[ref_audio_2])],
236
+ # Duration control
237
+ [processor.build_user_message(text=text_2, tokens=325)],
238
+ [processor.build_user_message(text=text_2, tokens=600)],
239
+ ]
240
+
241
+ model = AutoModel.from_pretrained(
242
+ pretrained_model_name_or_path,
243
+ trust_remote_code=True,
244
+ attn_implementation="sdpa",
245
+ torch_dtype=dtype,
246
+ ).to(device)
247
+ model.eval()
248
+
249
+ batch_size = 1
250
+
251
+ messages = []
252
+ save_dir = Path("inference_root")
253
+ save_dir.mkdir(exist_ok=True, parents=True)
254
+ sample_idx = 0
255
+ with torch.no_grad():
256
+ for start in range(0, len(conversations), batch_size):
257
+ batch_conversations = conversations[start : start + batch_size]
258
+ batch = processor(batch_conversations, mode="generation")
259
+ input_ids = batch["input_ids"].to(device)
260
+ attention_mask = batch["attention_mask"].to(device)
261
+
262
+ outputs = model.generate(
263
+ input_ids=input_ids,
264
+ attention_mask=attention_mask,
265
+ max_new_tokens=4096,
266
+ )
267
+
268
+ for message in processor.decode(outputs):
269
+ audio = message.audio_codes_list[0]
270
+ out_path = save_dir / f"sample{sample_idx}.wav"
271
+ sample_idx += 1
272
+ torchaudio.save(out_path, audio.unsqueeze(0), processor.model_config.sampling_rate)
273
+
274
+ ```
275
+
276
+ ### Continuation + Voice Cloning (Prefix Audio + Text)
277
+
278
+ MOSS-TTS supports continuation-based cloning: provide a prefix audio clip in the assistant message, and make sure the **prefix transcript** is included in the text. The model continues in the same speaker identity and style.
279
+
280
+ ```python
281
+ import os
282
+ from pathlib import Path
283
+ import torch
284
+ import torchaudio
285
+ from transformers import AutoModel, AutoProcessor
286
+ # Disable the broken cuDNN SDPA backend
287
+ torch.backends.cuda.enable_cudnn_sdp(False)
288
+ # Keep these enabled as fallbacks
289
+ torch.backends.cuda.enable_flash_sdp(True)
290
+ torch.backends.cuda.enable_mem_efficient_sdp(True)
291
+ torch.backends.cuda.enable_math_sdp(True)
292
+
293
+
294
+ pretrained_model_name_or_path = "OpenMOSS-Team/MOSS-TTS"
295
+ device = "cuda" if torch.cuda.is_available() else "cpu"
296
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
297
+
298
+ processor = AutoProcessor.from_pretrained(
299
+ pretrained_model_name_or_path,
300
+ trust_remote_code=True
301
+ )
302
+ processor.audio_tokenizer = processor.audio_tokenizer.to(device)
303
+
304
+ 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祝你永远带着笑容向前走。"
305
+ 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."
306
+ ref_text_1 = "太阳系八大行星之一。"
307
+ ref_text_2 = "But I really can't complain about not having a normal college experience to you."
308
+ ref_audio_1 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
309
+ ref_audio_2 = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
310
+
311
+ conversations = [
312
+ # Continuatoin only
313
+ [
314
+ processor.build_user_message(text=ref_text_1 + text_1),
315
+ processor.build_assistant_message(audio_codes_list=[ref_audio_1])
316
+ ],
317
+ # Continuation with voice cloning
318
+ [
319
+ processor.build_user_message(text=ref_text_2 + text_2, reference=[ref_audio_2]),
320
+ processor.build_assistant_message(audio_codes_list=[ref_audio_2])
321
+ ],
322
+ ]
323
+
324
+ model = AutoModel.from_pretrained(
325
+ pretrained_model_name_or_path,
326
+ trust_remote_code=True,
327
+ attn_implementation="sdpa",
328
+ torch_dtype=dtype,
329
+ ).to(device)
330
+ model.eval()
331
+
332
+ batch_size = 1
333
+
334
+ messages = []
335
+ save_dir = Path("inference_root")
336
+ save_dir.mkdir(exist_ok=True, parents=True)
337
+ sample_idx = 0
338
+ with torch.no_grad():
339
+ for start in range(0, len(conversations), batch_size):
340
+ batch_conversations = conversations[start : start + batch_size]
341
+ batch = processor(batch_conversations, mode="continuation")
342
+ input_ids = batch["input_ids"].to(device)
343
+ attention_mask = batch["attention_mask"].to(device)
344
+
345
+ outputs = model.generate(
346
+ input_ids=input_ids,
347
+ attention_mask=attention_mask,
348
+ max_new_tokens=4096,
349
+ )
350
+
351
+ for message in processor.decode(outputs):
352
+ audio = message.audio_codes_list[0]
353
+ out_path = save_dir / f"sample{sample_idx}.wav"
354
+ sample_idx += 1
355
+ torchaudio.save(out_path, audio.unsqueeze(0), processor.model_config.sampling_rate)
356
+
357
+ ```
358
+
359
+
360
+
361
+ ### Input Types
362
+
363
+ **UserMessage**
364
+
365
+ | Field | Type | Required | Description |
366
+ |---|---|---:|---|
367
+ | `text` | `str` | Yes | Text to synthesize. Supports Chinese, English, German, French, Spanish, Japanese, Korean, etc. Can mix raw text with Pinyin or IPA for pronunciation control. |
368
+ | `reference` | `List[str]` | No | Reference audio for voice cloning. For current MOSS-TTS, **one audio** is expected in the list. |
369
+ | `tokens` | `int` | No | Expected number of audio tokens. **1s ≈ 12.5 tokens**. |
370
+
371
+ **AssistantMessage**
372
+
373
+ | Field | Type | Required | Description |
374
+ |---|---|---:|---|
375
+ | `audio_codes_list` | `List[str]` | Only for continuation | Prefix audio for continuation-based cloning. Use audio file paths or URLs. |
376
+
377
+
378
+
379
+ ### Generation Hyperparameters
380
+
381
+ | Parameter | Type | Default | Description |
382
+ |---|---|---:|---|
383
+ | `max_new_tokens` | `int` | | Controls total generated audio tokens. Use duration rule: **1s ≈ 12.5 tokens**. |
384
+ | `audio_temperature` | `float` | 1.7 | Higher values increase variation; lower values stabilize prosody. |
385
+ | `audio_top_p` | `float` | 0.8 | Nucleus sampling cutoff. Lower values are more conservative. |
386
+ | `audio_top_k` | `int` | 25 | Top-K sampling. Lower values tighten sampling space. |
387
+ | `audio_repetition_penalty` | `float` | 1.0 | >1.0 discourages repeating patterns. |
388
+
389
+ > Note: MOSS-TTS is a pretrained base model and is **sensitive to decoding hyperparameters**. See **Released Models** for recommended defaults.
390
+
391
+
392
+
393
+ ### Pinyin Input
394
+
395
+ Use tone-numbered Pinyin such as `ni3 hao3 wo3 men1`. You can convert Chinese text with [pypinyin](https://github.com/mozillazg/python-pinyin), then adjust tones for pronunciation control.
396
+
397
+ ```python
398
+ import re
399
+ from pypinyin import pinyin, Style
400
+
401
+ CN_PUNCT = r",。!?;:、()“”‘’"
402
+
403
+
404
+ def fix_punctuation_spacing(s: str) -> str:
405
+ s = re.sub(rf"\s+([{CN_PUNCT}])", r"\1", s)
406
+ s = re.sub(rf"([{CN_PUNCT}])\s+", r"\1", s)
407
+ return s
408
+
409
+
410
+ def zh_to_pinyin_tone3(text: str, strict: bool = True) -> str:
411
+ result = pinyin(
412
+ text,
413
+ style=Style.TONE3,
414
+ heteronym=False,
415
+ strict=strict,
416
+ errors="default",
417
+ )
418
+
419
+ s = " ".join(item[0] for item in result)
420
+ return fix_punctuation_spacing(s)
421
+
422
+ text = zh_to_pinyin_tone3("您好,请问您来自哪座城市?")
423
+ print(text)
424
+
425
+ # Expected: nin2 hao3,qing3 wen4 nin2 lai2 zi4 na3 zuo4 cheng2 shi4?
426
+ # Try: nin2 hao3,qing4 wen3 nin2 lai2 zi4 na4 zuo3 cheng4 shi3?
427
+ ```
428
+
429
+
430
+
431
+ ### IPA Input
432
+
433
+ Use `/.../` to wrap IPA sequences so they are distinct from normal text. You can use [DeepPhonemizer](https://github.com/spring-media/DeepPhonemizer) to convert English paragraphs or words into IPA sequences.
434
+
435
+ ```python
436
+ from dp.phonemizer import Phonemizer
437
+
438
+ # Download a phonemizer checkpoint from https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt
439
+ model_path = "<path-to-phonemizer-checkpoint>"
440
+ phonemizer = Phonemizer.from_checkpoint(model_path)
441
+
442
+ english_texts = "Hello, may I ask which city you are from?"
443
+ phoneme_outputs = phonemizer(
444
+ english_texts,
445
+ lang="en_us",
446
+ batch_size=8
447
+ )
448
+ model_input_text = f"/{phoneme_outputs}/"
449
+ print(model_input_text)
450
+
451
+ # Expected: /həloʊ, meɪ aɪ æsk wɪtʃ sɪti juː ɑːr frʌm?/
452
+ ```
453
+
454
+
455
+
456
+ ## 3. Evaluation
457
+ MOSS-TTS achieved state-of-the-art results on the open-source zero-shot TTS benchmark Seed-TTS-eval, not only surpassing all open-source models but also rivaling the most powerful closed-source models.
458
+
459
+ | Model | Params | Open-source | EN WER (%) ↓ | EN SIM (%) ↑ | ZH CER (%) ↓ | ZH SIM (%) ↑ |
460
+ |---|---:|:---:|---:|---:|---:|---:|
461
+ | DiTAR | 0.6B | ❌ | 1.69 | 73.5 | 1.02 | 75.3 |
462
+ | FishAudio-S1 | 4B | ❌ | 1.72 | 62.57 | 1.22 | 72.1 |
463
+ | Seed-TTS | || 2.25 | 76.2 | 1.12 | 79.6 |
464
+ | MiniMax-Speech | | | 1.65 | 69.2 | 0.83 | 78.3 |
465
+ | | | | | | | |
466
+ | CosyVoice | 0.3B | ✅ | 4.29 | 60.9 | 3.63 | 72.3 |
467
+ | CosyVoice2 | 0.5B | ✅ | 3.09 | 65.9 | 1.38 | 75.7 |
468
+ | CosyVoice3 | 0.5B | ✅ | 2.02 | 71.8 | 1.16 | 78 |
469
+ | CosyVoice3 | 1.5B | ✅ | 2.22 | 72 | 1.12 | 78.1 |
470
+ | F5-TTS | 0.3B | ✅ | 2 | 67 | 1.53 | 76 |
471
+ | SparkTTS | 0.5B | ✅ | 3.14 | 57.3 | 1.54 | 66 |
472
+ | FireRedTTS | 0.5B | ✅ | 3.82 | 46 | 1.51 | 63.5 |
473
+ | FireRedTTS-2 | 1.5B | ✅ | 1.95 | 66.5 | 1.14 | 73.6 |
474
+ | Qwen2.5-Omni | 7B | ✅ | 2.72 | 63.2 | 1.7 | 75.2 |
475
+ | FishAudio-S1-mini | 0.5B | ✅ | 1.94 | 55 | 1.18 | 68.5 |
476
+ | IndexTTS2 | 1.5B | ✅ | 2.23 | 70.6 | 1.03 | 76.5 |
477
+ | VibeVoice | 1.5B | ✅ | 3.04 | 68.9 | 1.16 | 74.4 |
478
+ | HiggsAudio-v2 | 3B | ✅ | 2.44 | 67.7 | 1.5 | 74 |
479
+ | VoxCPM | 0.5B | ✅ | 1.85 | 72.9 | **0.93** | 77.2 |
480
+ | Qwen3-TTS | 0.6B || 1.68 | 70.39 | 1.23 | 76.4 |
481
+ | Qwen3-TTS | 1.7B | ✅ | **1.5** | 71.45 | 1.33 | 76.72 |
482
+ | | | | | | | |
483
+ | MossTTSDelay | 8B | ✅ | 1.79 | 71.46 | 1.32 | 77.05 |
484
+ | MossTTSLocal | 1.7B | ✅ | 1.85 | **73.42** | 1.2 | **78.82** |