Views
No views yet
[channels, samples] tensor returned by processor.decode(...) directly.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")."[pause 3.2s]". For example, 我今天学习了一首中国的古诗,它的名字是[pause 3.2s]静夜思! inserts an explicit 3.2s pause before 静夜思.| Language | Code | Flag | Language | Code | Flag | Language | Code | Flag |
|---|---|---|---|---|---|---|---|---|
| Chinese | zh | 🇨🇳 | Cantonese | yue | 🇭🇰 | English | en | 🇺🇸 |
| Arabic | ar | 🇸🇦 | Czech | cs | 🇨🇿 | Danish | da | 🇩🇰 |
| Dutch | nl | 🇳🇱 | Finnish | fi | 🇫🇮 | French | fr | 🇫🇷 |
| German | de | 🇩🇪 | Greek | el | 🇬🇷 | Hebrew | he | 🇮🇱 |
| Hindi | hi | 🇮🇳 | Hungarian | hu | 🇭🇺 | Italian | it | 🇮🇹 |
| Japanese | ja | 🇯🇵 | Korean | ko | 🇰🇷 | Macedonian | mk | 🇲🇰 |
| Malay | ms | 🇲🇾 | Persian (Farsi) | fa | 🇮🇷 | Polish | pl | 🇵🇱 |
| Portuguese | pt | 🇵🇹 | Romanian | ro | 🇷🇴 | Russian | ru | 🇷🇺 |
| Spanish | es | 🇪🇸 | Swahili | sw | 🇹🇿 | Swedish | sv | 🇸🇪 |
| Tagalog | tl | 🇵🇭 | Thai | th | 🇹🇭 | Turkish | tr | 🇹🇷 |
| Vietnamese | vi | 🇻🇳 |
1conda create -n moss-tts python=3.12 -y
2conda activate moss-tts1git clone https://github.com/OpenMOSS/MOSS-TTS.git
2cd MOSS-TTS
3pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[torch-runtime]"pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]" --no-build-isolationMAX_JOBS=4 pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e ".[flash-attn]" --no-build-isolationpyproject.toml, which currently pins torch==2.9.1+cu128 and torchaudio==2.9.1+cu128.torch.float16 or torch.bfloat16.Tip: MOSS-TTS-Local-Transformer-v1.5 uses a fixed 12-codebook RVQ depth. Do not setn_vq_for_inferenceto a value different fromconfig.n_vq.
AutoProcessor and AutoModel interface. The examples below cover:[pause X.Ys]1from pathlib import Path
2from tqdm import tqdm
3import importlib.util
4
5import torch
6import torchaudio
7from transformers import AutoModel, AutoProcessor
8
9# Disable the broken cuDNN SDPA backend on some CUDA/PyTorch combinations.
10torch.backends.cuda.enable_cudnn_sdp(False)
11# Keep these enabled as fallbacks.
12torch.backends.cuda.enable_flash_sdp(True)
13torch.backends.cuda.enable_mem_efficient_sdp(True)
14torch.backends.cuda.enable_math_sdp(True)
15
16pretrained_model_name_or_path = "OpenMOSS-Team/MOSS-TTS-Local-Transformer-v1.5"
17device = "cuda" if torch.cuda.is_available() else "cpu"
18dtype = torch.bfloat16 if device == "cuda" else torch.float32
19
20
21def resolve_attn_implementation() -> str:
22 # Prefer FlashAttention 2 when package + device conditions are met.
23 if (
24 device == "cuda"
25 and importlib.util.find_spec("flash_attn") is not None
26 and dtype in {torch.float16, torch.bfloat16}
27 ):
28 major, _ = torch.cuda.get_device_capability()
29 if major >= 8:
30 return "flash_attention_2"
31 # CUDA fallback: use PyTorch SDPA kernels.
32 if device == "cuda":
33 return "sdpa"
34 # CPU fallback.
35 return "eager"
36
37
38attn_implementation = resolve_attn_implementation()
39print(f"[INFO] Using attn_implementation={attn_implementation}")
40
41processor = AutoProcessor.from_pretrained(
42 pretrained_model_name_or_path,
43 trust_remote_code=True,
44)
45processor.audio_tokenizer = processor.audio_tokenizer.to(device)
46
47text_zh = "亲爱的你,愿你的每一天都值得被记住,也值得被珍惜。"
48text_en = "We stand on the threshold of the AI era, where intelligence becomes an extension of human creativity."
49text_fr = "Bonjour, je voudrais essayer une voix francaise naturelle et stable."
50text_pause = "我今天学习了一首中国的古诗,它的名字是[pause 3.2s]静夜思!"
51
52# Use remote demo audio to avoid requiring local assets.
53ref_audio_zh = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
54ref_audio_en = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
55
56conversations = [
57 # Direct TTS. Language tags are recommended in v1.5 when the language is known.
58 [processor.build_user_message(text=text_zh, language="Chinese")],
59 [processor.build_user_message(text=text_en, language="English")],
60 [processor.build_user_message(text=text_fr, language="French")],
61 # Explicit pause control. Use [pause X.Ys], such as [pause 3.2s].
62 [processor.build_user_message(text=text_pause, language="Chinese")],
63 # Voice cloning with a reference audio.
64 [processor.build_user_message(text=text_zh, reference=[ref_audio_zh], language="Chinese")],
65 [processor.build_user_message(text=text_en, reference=[ref_audio_en], language="English")],
66 # Duration control. At 12.5 frames per second, 125 frames is about 10 seconds.
67 [processor.build_user_message(text=text_en, tokens=125, language="English")],
68]
69
70model = AutoModel.from_pretrained(
71 pretrained_model_name_or_path,
72 trust_remote_code=True,
73 attn_implementation=attn_implementation,
74 torch_dtype=dtype,
75).to(device)
76model.eval()
77
78batch_size = 1
79save_dir = Path("inference_root_moss_tts_local_v1_5")
80save_dir.mkdir(exist_ok=True, parents=True)
81sample_idx = 0
82
83with torch.no_grad():
84 for start in tqdm(range(0, len(conversations), batch_size)):
85 batch_conversations = conversations[start : start + batch_size]
86 batch = processor(batch_conversations, mode="generation")
87 input_ids = batch["input_ids"].to(device)
88 attention_mask = batch["attention_mask"].to(device)
89
90 outputs = model.generate(
91 input_ids=input_ids,
92 attention_mask=attention_mask,
93 max_new_tokens=4096,
94 do_sample=True,
95 audio_temperature=1.7,
96 audio_top_p=0.8,
97 audio_top_k=25,
98 audio_repetition_penalty=1.0,
99 )
100
101 for message in processor.decode(outputs):
102 if message is None:
103 continue
104 audio = message.audio_codes_list[0]
105 out_path = save_dir / f"sample{sample_idx}.wav"
106 sample_idx += 1
107 # MOSS-TTS Local v1.5 codec returns stereo audio as [channels, samples].
108 # Save the two-channel tensor directly.
109 torchaudio.save(str(out_path), audio, processor.model_config.sampling_rate)| Parameter | Recommended | Description |
|---|---|---|
audio_temperature | 1.7 | Sampling temperature for audio RVQ layers. |
audio_top_p | 0.8 | Nucleus sampling cutoff for audio RVQ layers. |
audio_top_k | 25 | Top-k sampling cutoff for audio RVQ layers. |
audio_repetition_penalty | 1.0 | Penalty for repeated acoustic token patterns. |
n_vq_for_inference | 12 | Fixed by this release. Values other than config.n_vq are rejected. |
trust_remote_code=True.processor.decode(...) returns audio tensors shaped as [channels, samples], so save them directly with torchaudio.save(path, audio, sampling_rate).OpenMOSS-Team/MOSS-Audio-Tokenizer-v2.sampling_rate to 48000 and n_vq to 12./v1/audio/speech API for reference-less synthesis, zero-shot voice cloning, streaming, duration control, and language/style hints.sglang-omni by following the SGLang-Omni installation guide, then download and serve the model:1hf download OpenMOSS-Team/MOSS-TTS-Local-Transformer-v1.5
2
3sgl-omni serve \
4 --model-path OpenMOSS-Team/MOSS-TTS-Local-Transformer-v1.5 \
5 --port 8000examples/configs/moss_tts_local.yaml.1curl -X POST http://localhost:8000/v1/audio/speech \
2 -H "Content-Type: application/json" \
3 -d '{"input": "SGLang-Omni is a great project!"}' \
4 --output output.wavaudio_path may be a local path readable by the server, an HTTP(S) URL, or a base64 data URI.1curl -X POST http://localhost:8000/v1/audio/speech \
2 -H "Content-Type: application/json" \
3 -d '{
4 "input": "SGLang-Omni is a great project!",
5 "references": [{
6 "audio_path": "https://huggingface.co/datasets/zhaochenyang20/seed-tts-eval-mini/resolve/main/en/prompt-wavs/common_voice_en_10119832.wav"
7 }]
8 }' \
9 --output output.wavref_audio and ref_text are accepted as shorthand for references[0].audio_path and references[0].text."stream": true, "response_format": "pcm", and "stream_format": "audio" to receive raw 48 kHz PCM chunks. Pipe the stream through ffmpeg to write a playable WAV file:1curl -N -X POST http://localhost:8000/v1/audio/speech \
2 -H "Content-Type: application/json" \
3 -d '{
4 "input": "Get the trust fund to the bank early.",
5 "ref_audio": "https://huggingface.co/datasets/zhaochenyang20/seed-tts-eval-mini/resolve/main/en/prompt-wavs/common_voice_en_10119832.wav",
6 "stream": true,
7 "response_format": "pcm",
8 "stream_format": "audio"
9 }' \
10 | ffmpeg -f s16le -ar 48000 -ac 1 -i pipe:0 output_stream.wav${token:N} prefix or with token_count / duration_tokens. Inline markup such as [pause 0.5s], Pinyin, and IPA is passed through unchanged. Use language to hint the target language and instructions for free-form style guidance.1curl -X POST http://localhost:8000/v1/audio/speech \
2 -H "Content-Type: application/json" \
3 -d '{
4 "input": "${token:150}今天天气不错 [pause 0.5s] 就该出去晒晒太阳。",
5 "ref_audio": "https://huggingface.co/datasets/zhaochenyang20/seed-tts-eval-mini/resolve/main/en/prompt-wavs/common_voice_en_10119832.wav",
6 "language": "Chinese"
7 }' \
8 --output output_markup.wavUserMessage and AssistantMessage fields, generation hyperparameters, Pinyin/IPA preprocessing examples, and evaluation results, see the MOSS-TTS-Local-Transformer-v1.0.