Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,104 @@
|
|
1 |
-
---
|
2 |
-
license: cc-by-nc-4.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-4.0
|
3 |
+
---
|
4 |
+
|
5 |
+
# AudioX
|
6 |
+
|
7 |
+
## 🎧 AudioX: Diffusion Transformer for Anything-to-Audio Generation
|
8 |
+
|
9 |
+
[TL;DR]: AudioX is a unified Diffusion Transformer model for Anything-to-Audio and Music Generation, capable of generating high-quality general audio and music, offering flexible natural language control, and seamlessly processing various modalities including text, video, image, music, and audio.
|
10 |
+
|
11 |
+
### Links
|
12 |
+
- **[Paper](https://arxiv.org/abs/2503.10522)**: Explore the research behind AudioX.
|
13 |
+
- **[Project](https://zeyuet.github.io/AudioX/)**: Visit the official project page for more information and updates.
|
14 |
+
|
15 |
+
|
16 |
+
## Clone the repository
|
17 |
+
```bash
|
18 |
+
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/HKUSTAudio/AudioX
|
19 |
+
cd AudioX
|
20 |
+
|
21 |
+
conda create -n AudioX python=3.8.20
|
22 |
+
conda activate AudioX
|
23 |
+
pip install git+https://github.com/ZeyueT/AudioX.git
|
24 |
+
conda install -c conda-forge ffmpeg libsndfile
|
25 |
+
```
|
26 |
+
|
27 |
+
## Usage
|
28 |
+
|
29 |
+
```py
|
30 |
+
import torch
|
31 |
+
import torchaudio
|
32 |
+
from einops import rearrange
|
33 |
+
from stable_audio_tools import get_pretrained_model
|
34 |
+
from stable_audio_tools.inference.generation import generate_diffusion_cond
|
35 |
+
from stable_audio_tools.data.utils import read_video, merge_video_audio
|
36 |
+
from stable_audio_tools.data.utils import load_and_process_audio
|
37 |
+
import os
|
38 |
+
|
39 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
40 |
+
|
41 |
+
# Download model
|
42 |
+
model, model_config = get_pretrained_model("HKUSTAudio/AudioX")
|
43 |
+
sample_rate = model_config["sample_rate"]
|
44 |
+
sample_size = model_config["sample_size"]
|
45 |
+
target_fps = model_config["video_fps"]
|
46 |
+
seconds_start = 0
|
47 |
+
seconds_total = 10
|
48 |
+
|
49 |
+
model = model.to(device)
|
50 |
+
|
51 |
+
# for video-to-music generation
|
52 |
+
video_path = "video.mp4"
|
53 |
+
text_prompt = "Generate music for the video"
|
54 |
+
audio_path = None
|
55 |
+
|
56 |
+
video_tensor = read_video(video_path, seek_time=0, duration=seconds_total, target_fps=target_fps)
|
57 |
+
audio_tensor = load_and_process_audio(audio_path, sample_rate, seconds_start, seconds_total)
|
58 |
+
|
59 |
+
conditioning = [{
|
60 |
+
"video_prompt": [video_tensor.unsqueeze(0)],
|
61 |
+
"text_prompt": text_prompt,
|
62 |
+
"audio_prompt": audio_tensor.unsqueeze(0),
|
63 |
+
"seconds_start": seconds_start,
|
64 |
+
"seconds_total": seconds_total
|
65 |
+
}]
|
66 |
+
|
67 |
+
# Generate stereo audio
|
68 |
+
output = generate_diffusion_cond(
|
69 |
+
model,
|
70 |
+
steps=250,
|
71 |
+
cfg_scale=7,
|
72 |
+
conditioning=conditioning,
|
73 |
+
sample_size=sample_size,
|
74 |
+
sigma_min=0.3,
|
75 |
+
sigma_max=500,
|
76 |
+
sampler_type="dpmpp-3m-sde",
|
77 |
+
device=device
|
78 |
+
)
|
79 |
+
|
80 |
+
# Rearrange audio batch to a single sequence
|
81 |
+
output = rearrange(output, "b d n -> d (b n)")
|
82 |
+
|
83 |
+
# Peak normalize, clip, convert to int16, and save to file
|
84 |
+
output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
|
85 |
+
torchaudio.save("output.wav", output, sample_rate)
|
86 |
+
|
87 |
+
if video_path is not None and os.path.exists(video_path):
|
88 |
+
merge_video_audio(video_path, "output.wav", "output.mp4", 0, seconds_total)
|
89 |
+
|
90 |
+
```
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
## Citation
|
95 |
+
If you find our work useful, please consider citing:
|
96 |
+
|
97 |
+
```
|
98 |
+
@article{tian2025audiox,
|
99 |
+
title={AudioX: Diffusion Transformer for Anything-to-Audio Generation},
|
100 |
+
author={Tian, Zeyue and Jin, Yizhu and Liu, Zhaoyang and Yuan, Ruibin and Tan, Xu and Chen, Qifeng and Xue, Wei and Guo, Yike},
|
101 |
+
journal={arXiv preprint arXiv:2503.10522},
|
102 |
+
year={2025}
|
103 |
+
}
|
104 |
+
```
|