Text-to-Audio
Transformers
Safetensors
English
dasheng_audiogen
feature-extraction
audio-generation
text-to-speech
text-to-music
sound-effects
diffusion
custom_code
Run this model with HF Jobs
Run mispeech/Dasheng-AudioGen on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/mispeech/Dasheng-AudioGen. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/mispeech/Dasheng-AudioGen on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use mispeech/Dasheng-AudioGen with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mispeech/Dasheng-AudioGen with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-audio", model="mispeech/Dasheng-AudioGen", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Jiahao mei commited on
Upload folder using huggingface_hub
Browse filesFiles changed (3)
- README.md+47-27
- README_zh.md+60-29
- modeling_dasheng_audiogen.py+18-11
51 unmodified lines5253545556575859601 unmodified line6263646566676869707172737475766 unmodified lines83848586878889909192939495969798998 unmodified lines10810911011111211311411511611711811912012112212312412512612712812913013113213313451 unmodified lines> Tested with Python 3.10, torch 2.8.0+cu128, transformers 4.57. Not compatible with transformers 5.x.## Quick Start### Basic Usage```pythonimport torchaudio1 unmodified linemodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()audio = model.generate("A dog barking in a park")torchaudio.save("output.wav", audio.cpu(), 16000)```### Aspect-wise PromptUse `compose_prompt` to describe different audio aspects separately:```pythonprompt = model.compose_prompt(caption="A gritty detective narrating over the sound of heavy rain and a melancholic solo jazz saxophone.",speech="gritty deep male voice",6 unmodified linestorchaudio.save("output.wav", audio.cpu(), 16000)```You can also pass a pre-formatted string with tags directly:```pythonaudio = model.generate("<|caption|> A helicopter passing overhead. <|sfx|> Rhythmic helicopter blade sounds. <|env|> Open sky ambience.")```### Batch Inference```pythonprompts = [model.compose_prompt(caption="A cat meowing softly.", sfx="Soft cat meow."),model.compose_prompt(caption="Thunder rolling in the distance.", env="Stormy night ambience."),8 unmodified lines### Generation Parameters```pythonaudio = model.generate(prompts="A dog barking in a park",num_steps=25, # number of denoising steps (default: 25)guidance_scale=5.0, # classifier-free guidance scale (default: 5.0)sway_sampling_coef=-1.0, # sway sampling coefficient (default: -1.0, 0 for linear))```## Prompt FormatDasheng-AudioGen uses structured tags to describe different audio aspects:| Tag | Description ||-----|-------------|| `<\|caption\|>` | Overall audio scene description || `<\|speech\|>` | Speaker identity and speaking style || `<\|asr\|>` | Spoken transcript / dialogue || `<\|sfx\|>` | Sound effects || `<\|music\|>` | Background music || `<\|env\|>` | Environmental ambience |## AcknowledgmentsDasheng-AudioGen was developed with contributions from **XIAOMI LLM PLUS** and **SJTU X-LANCE**.51 unmodified lines5253545556575859606162636465666768697071727374757677787980811 unmodified line8384858687886 unmodified lines95969798991001011021031041051061071081091101111121131141151161171181191201211221231241258 unmodified lines13413513613713813914014114214314414514614714814915015115215315451 unmodified lines> Tested with Python 3.10, torch 2.8.0+cu128, transformers 4.57. Not compatible with transformers 5.x.## Prompt FormatDasheng-AudioGen uses structured tags to describe different audio aspects. A valid prompt **must start with the `<|caption|>` tag**, which provides the overall scene description. Other tags are optional and can be included as needed.| Tag | Description | Required ||-----|-------------|:--------:|| `<\|caption\|>` | Overall audio scene description | Yes || `<\|speech\|>` | Speaker identity and speaking style | No || `<\|asr\|>` | Spoken transcript / dialogue | No || `<\|sfx\|>` | Sound effects | No || `<\|music\|>` | Background music | No || `<\|env\|>` | Environmental ambience | No |**Rules:**- The prompt must begin with `<|caption|>` — prompts without it will be rejected.- Only include tags that are relevant; omit tags with no content (e.g., skip `<|music|>` if there is no music).> **Multilingual note:** When using the multilingual model, all descriptive tags (`caption`, `speech`, `sfx`, `music`, `env`) should be in **English**. Only the `<|asr|>` field (the actual speech content to synthesize) uses the target language.## Quick Start### Usage 1: Aspect-wise CompositionPass each aspect as a named argument. The `caption` field is required; all other fields are optional.```pythonimport torchaudio1 unmodified linemodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompt = model.compose_prompt(caption="A gritty detective narrating over the sound of heavy rain and a melancholic solo jazz saxophone.",speech="gritty deep male voice",6 unmodified linestorchaudio.save("output.wav", audio.cpu(), 16000)```### Usage 2: Pre-formatted Prompt StringPass a complete tagged string via the `prompt` parameter. The string must start with `<|caption|>`.```pythonimport torchaudiofrom transformers import AutoModelmodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompt = model.compose_prompt(prompt="<|caption|> A gritty detective narrating over the sound of heavy rain and a melancholic solo jazz saxophone. <|speech|> gritty deep male voice <|asr|> The city never sleeps, but it sure knows how to cry. <|sfx|> heavy rain hitting pavement <|music|> melancholic solo saxophone <|env|> distant urban ambience")audio = model.generate(prompt)torchaudio.save("output.wav", audio.cpu(), 16000)```### Batch Inference```pythonimport torchaudiofrom transformers import AutoModelmodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompts = [model.compose_prompt(caption="A cat meowing softly.", sfx="Soft cat meow."),model.compose_prompt(caption="Thunder rolling in the distance.", env="Stormy night ambience."),8 unmodified lines### Generation Parameters```pythonimport torchaudiofrom transformers import AutoModelmodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompt = model.compose_prompt(caption="A dog barking in a park")audio = model.generate(prompts=prompt,num_steps=25, # number of denoising steps (default: 25)guidance_scale=5.0, # classifier-free guidance scale (default: 5.0)sway_sampling_coef=-1.0, # sway sampling coefficient (default: -1.0, 0 for linear))torchaudio.save("output.wav", audio.cpu(), 16000)```## AcknowledgmentsDasheng-AudioGen was developed with contributions from **XIAOMI LLM PLUS** and **SJTU X-LANCE**.
3 unmodified lines45678910111213149 unmodified lines2425262728293031321 unmodified line3435363738394041424344454647486 unmodified lines55565758596061626364656667686970718 unmodified lines80818283848586878889909192939495969798991001011021031041051061071083 unmodified lines[](https://huggingface.co/mispeech/Dasheng-AudioGen)[](https://huggingface.co/spaces/mispeech/Dasheng-AudioGen)[](https://nieeim.github.io/Dasheng-AudioGen-Web/)[**English**](./README.md) | [**中文**](./README_zh.md)**Dasheng-AudioGen** 是一个统一的音频生成模型,能够根据文本描述同时合成**语音、音乐、音效和环境声**。## 模型| 模型 | HuggingFace | 文本编码器 | 语言支持 |9 unmodified lines> 已在 Python 3.10、torch 2.8.0+cu128、transformers 4.57 上测试通过。已知不兼容 transformers 5.x。## 快速开始### 基本用法```pythonimport torchaudio1 unmodified linemodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()audio = model.generate("A dog barking in a park")torchaudio.save("output.wav", audio.cpu(), 16000)```### 分项 Prompt使用 `compose_prompt` 分别描述不同的音频维度:```pythonprompt = model.compose_prompt(caption="A gritty detective narrating over the sound of heavy rain and a melancholic solo jazz saxophone.",speech="gritty deep male voice",6 unmodified linestorchaudio.save("output.wav", audio.cpu(), 16000)```也可以直接传入包含标签的完整字符串:```pythonaudio = model.generate("<|caption|> A helicopter passing overhead. <|sfx|> Rhythmic helicopter blade sounds. <|env|> Open sky ambience.")```### 批量推理```pythonprompts = [model.compose_prompt(caption="A cat meowing softly.", sfx="Soft cat meow."),model.compose_prompt(caption="Thunder rolling in the distance.", env="Stormy night ambience."),8 unmodified lines### 生成参数```pythonaudio = model.generate(prompts="A dog barking in a park",num_steps=25, # 去噪步数(默认:25)guidance_scale=5.0, # 无分类器引导强度(默认:5.0)sway_sampling_coef=-1.0, # sway 采样系数(默认:-1.0,设为 0 使用线性调度))```## Prompt 格式Dasheng-AudioGen 使用结构化标签来描述不同的音频维度:| 标签 | 描述 ||------|------|| `<\|caption\|>` | 整体音频场景描述 || `<\|speech\|>` | 说话人身份和说话风格 || `<\|asr\|>` | 语音转写内容 / 对话文本 || `<\|sfx\|>` | 音效 || `<\|music\|>` | 背景音乐 || `<\|env\|>` | 环境音 |> **多语言 prompt 规范:** 使用多语言模型时,所有描述性标签(`caption`、`speech`、`sfx`、`music`、`env`)应使用**英文**填写,仅 `<|asr|>` 字段(实际要合成的语音内容)使用目标语言。## 致谢Dasheng-AudioGen 由**小米 LLM PLUS** 和 **上海交通大学 X-LANCE** 联合开发。3 unmodified lines4567891011121314151617181920212223242526279 unmodified lines3738394041424344454647484950515253545556575859606162636465661 unmodified line6869707172736 unmodified lines80818283848586878889909192939495969798991001011021031041051061071081091108 unmodified lines1191201211221231241251261271281291301311321331341351361371381393 unmodified lines[](https://huggingface.co/mispeech/Dasheng-AudioGen)[](https://huggingface.co/spaces/mispeech/Dasheng-AudioGen)[](https://nieeim.github.io/Dasheng-AudioGen-Web/)[](https://colab.research.google.com/#fileId=https://huggingface.co/mispeech/Dasheng-AudioGen/resolve/main/notebook.ipynb)[**English**](./README.md) | [**中文**](./README_zh.md)**Dasheng-AudioGen** 是一个统一的音频生成模型,能够根据文本描述同时合成**语音、音乐、音效和环境声**。<p align="center"><videosrc="https://github.com/user-attachments/assets/497f5688-8731-4830-8ee7-b9cf4234d900"controlsautoplaymutedloopplaysinlinewidth="85%"></video></p>## 模型| 模型 | HuggingFace | 文本编码器 | 语言支持 |9 unmodified lines> 已在 Python 3.10、torch 2.8.0+cu128、transformers 4.57 上测试通过。已知不兼容 transformers 5.x。## Prompt 格式Dasheng-AudioGen 使用结构化标签来描述不同的音频维度。有效的 prompt **必须以 `<|caption|>` 标签开头**,用于描述整体音频场景。其他标签为可选项,按需使用。| 标签 | 描述 | 是否必需 ||------|------|:--------:|| `<\|caption\|>` | 整体音频场景描述 | 是 || `<\|speech\|>` | 说话人身份和说话风格 | 否 || `<\|asr\|>` | 语音转写内容 / 对话文本 | 否 || `<\|sfx\|>` | 音效 | 否 || `<\|music\|>` | 背景音乐 | 否 || `<\|env\|>` | 环境音 | 否 |**规则:**- Prompt 必须以 `<|caption|>` 开头,否则会报错。- 仅包含有实际内容的标签;没有对应内容的标签请省略(例如没有音乐则不传 `<|music|>`)。> **多语言 prompt 规范:** 使用多语言模型时,所有描述性标签(`caption`、`speech`、`sfx`、`music`、`env`)应使用**英文**填写,仅 `<|asr|>` 字段(实际要合成的语音内容)使用目标语言。## 快速开始### 用法一:分维度组装通过命名参数分别传入各个维度的描述。`caption` 为必填项,其他字段可选。```pythonimport torchaudio1 unmodified linemodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompt = model.compose_prompt(caption="A gritty detective narrating over the sound of heavy rain and a melancholic solo jazz saxophone.",speech="gritty deep male voice",6 unmodified linestorchaudio.save("output.wav", audio.cpu(), 16000)```### 用法二:传入完整 Prompt 字符串通过 `prompt` 参数传入预格式化的标签字符串,该字符串必须以 `<|caption|>` 开头。```pythonimport torchaudiofrom transformers import AutoModelmodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompt = model.compose_prompt(prompt="<|caption|> A gritty detective narrating over the sound of heavy rain and a melancholic solo jazz saxophone. <|speech|> gritty deep male voice <|asr|> The city never sleeps, but it sure knows how to cry. <|sfx|> heavy rain hitting pavement <|music|> melancholic solo saxophone <|env|> distant urban ambience")audio = model.generate(prompt)torchaudio.save("output.wav", audio.cpu(), 16000)```### 批量推理```pythonimport torchaudiofrom transformers import AutoModelmodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompts = [model.compose_prompt(caption="A cat meowing softly.", sfx="Soft cat meow."),model.compose_prompt(caption="Thunder rolling in the distance.", env="Stormy night ambience."),8 unmodified lines### 生成参数```pythonimport torchaudiofrom transformers import AutoModelmodel = AutoModel.from_pretrained("mispeech/Dasheng-AudioGen", trust_remote_code=True).cuda()prompt = model.compose_prompt(caption="A dog barking in a park")audio = model.generate(prompts=prompt,num_steps=25, # 去噪步数(默认:25)guidance_scale=5.0, # 无分类器引导强度(默认:5.0)sway_sampling_coef=-1.0, # sway 采样系数(默认:-1.0,设为 0 使用线性调度))torchaudio.save("output.wav", audio.cpu(), 16000)```## 致谢Dasheng-AudioGen 由**小米 LLM PLUS** 和 **上海交通大学 X-LANCE** 联合开发。
29 unmodified lines303132333435361 unmodified line383940414243444546476 unmodified lines54555657585960616263167 unmodified lines2312322332342352362372 unmodified lines24024124224324424524629 unmodified linesdef compose_prompt(content: str | None = None,caption: str | None = None,speech: str | None = None,asr: str | None = None,1 unmodified linemusic: str | None = None,env: str | None = None,) -> str:if content is not None:content = str(content).strip()if content:return contentvalues = {"caption": caption, "speech": speech, "asr": asr,6 unmodified linesvalue = str(value).strip()if value:chunks.append(f"{tag} {value}")if not chunks:raise ValueError("No prompt content provided. Pass `content` or at least one aspect field.")return " ".join(chunks)167 unmodified lines@staticmethoddef compose_prompt(content: str | None = None,caption: str | None = None,speech: str | None = None,asr: str | None = None,2 unmodified linesenv: str | None = None,) -> str:return compose_prompt(content=content, caption=caption, speech=speech,asr=asr, sfx=sfx, music=music, env=env,)29 unmodified lines303132333435361 unmodified line3839404142434445464748495051525354555657586 unmodified lines656667686970167 unmodified lines2382392402412422432442 unmodified lines24724824925025125225329 unmodified linesdef compose_prompt(prompt: str | None = None,caption: str | None = None,speech: str | None = None,asr: str | None = None,1 unmodified linemusic: str | None = None,env: str | None = None,) -> str:if prompt is not None:prompt = str(prompt).strip()if not prompt:raise ValueError("The `prompt` string is empty.")if not prompt.startswith("<|caption|>"):raise ValueError("The `prompt` string must start with the <|caption|> tag. "f"Got: {prompt[:50]!r}...")return promptif caption is None or not str(caption).strip():raise ValueError("The `caption` field is required and cannot be empty.")values = {"caption": caption, "speech": speech, "asr": asr,6 unmodified linesvalue = str(value).strip()if value:chunks.append(f"{tag} {value}")return " ".join(chunks)167 unmodified lines@staticmethoddef compose_prompt(prompt: str | None = None,caption: str | None = None,speech: str | None = None,asr: str | None = None,2 unmodified linesenv: str | None = None,) -> str:return compose_prompt(prompt=prompt, caption=caption, speech=speech,asr=asr, sfx=sfx, music=music, env=env,)
README.md+47-27
README_zh.md+60-29
modeling_dasheng_audiogen.py+18-11