Zeyue7 nielsr HF Staff commited on
Commit
2db0852
·
1 Parent(s): c359dce

Update model card with paper info, links and sample usage (#1)

Browse files

- Update model card with paper info, links and sample usage (9405350ac6d354df3abe67381cd0610c9c127242)


Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +116 -2
README.md CHANGED
@@ -1,6 +1,120 @@
1
  ---
2
- license: cc-by-nc-4.0
3
  base_model:
4
  - HKUSTAudio/AudioX
 
5
  pipeline_tag: text-to-audio
6
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
 
2
  base_model:
3
  - HKUSTAudio/AudioX
4
+ license: cc-by-nc-4.0
5
  pipeline_tag: text-to-audio
6
+ tags:
7
+ - audio-generation
8
+ - music-generation
9
+ ---
10
+
11
+ # AudioX: A Unified Framework for Anything-to-Audio Generation
12
+
13
+ AudioX is a unified framework for generating audio and music from diverse multimodal control signals, including text, video, and audio. It features a Multimodal Adaptive Fusion (MAF) module to effectively align and fuse these inputs.
14
+
15
+ - **Paper:** [AudioX: A Unified Framework for Anything-to-Audio Generation](https://huggingface.co/papers/2503.10522)
16
+ - **Project Page:** [https://zeyuet.github.io/AudioX/](https://zeyuet.github.io/AudioX/)
17
+ - **Repository:** [https://github.com/ZeyueT/AudioX](https://github.com/ZeyueT/AudioX)
18
+ - **Demo:** [Hugging Face Spaces](https://huggingface.co/spaces/Zeyue7/AudioX)
19
+
20
+ ## Installation
21
+
22
+ To use AudioX, first install the required dependencies and the package from the official repository:
23
+
24
+ ```bash
25
+ # Clone the repository
26
+ git clone https://github.com/ZeyueT/AudioX.git
27
+ cd AudioX
28
+
29
+ # Install dependencies
30
+ pip install git+https://github.com/ZeyueT/AudioX.git
31
+ conda install -c conda-forge ffmpeg libsndfile
32
+ ```
33
+
34
+ ## Sample Usage
35
+
36
+ Below is an example of how to perform Video-to-Music generation programmatically:
37
+
38
+ ```python
39
+ import torch
40
+ import torchaudio
41
+ from einops import rearrange
42
+ from audiox import get_pretrained_model
43
+ from audiox.inference.generation import generate_diffusion_cond
44
+ from audiox.data.utils import read_video, merge_video_audio, load_and_process_audio, encode_video_with_synchformer
45
+ import os
46
+
47
+ device = "cuda" if torch.cuda.is_available() else "cpu"
48
+
49
+ # Load pretrained model
50
+ # Choose one: "HKUSTAudio/AudioX", "HKUSTAudio/AudioX-MAF", or "HKUSTAudio/AudioX-MAF-MMDiT"
51
+ model_name = "HKUSTAudio/AudioX"
52
+ model, model_config = get_pretrained_model(model_name)
53
+ sample_rate = model_config["sample_rate"]
54
+ sample_size = model_config["sample_size"]
55
+ target_fps = model_config["video_fps"]
56
+ seconds_start = 0
57
+ seconds_total = 10
58
+
59
+ model = model.to(device)
60
+
61
+ # Example: Video-to-Music generation
62
+ video_path = "example/V2M_sample-1.mp4"
63
+ text_prompt = "Generate music for the video"
64
+ audio_path = None
65
+
66
+ # Prepare inputs
67
+ video_tensor = read_video(video_path, seek_time=seconds_start, duration=seconds_total, target_fps=target_fps)
68
+ if audio_path:
69
+ audio_tensor = load_and_process_audio(audio_path, sample_rate, seconds_start, seconds_total)
70
+ else:
71
+ # Use zero tensor when no audio is provided
72
+ audio_tensor = torch.zeros((2, int(sample_rate * seconds_total)))
73
+
74
+ # For AudioX-MAF and AudioX-MAF-MMDiT: encode video with synchformer
75
+ video_sync_frames = None
76
+ if "MAF" in model_name:
77
+ video_sync_frames = encode_video_with_synchformer(
78
+ video_path, model_name, seconds_start, seconds_total, device
79
+ )
80
+
81
+ # Create conditioning
82
+ conditioning = [{
83
+ "video_prompt": {"video_tensors": video_tensor.unsqueeze(0), "video_sync_frames": video_sync_frames},
84
+ "text_prompt": text_prompt,
85
+ "audio_prompt": audio_tensor.unsqueeze(0),
86
+ "seconds_start": seconds_start,
87
+ "seconds_total": seconds_total
88
+ }]
89
+
90
+ # Generate audio
91
+ output = generate_diffusion_cond(
92
+ model,
93
+ steps=250,
94
+ cfg_scale=7,
95
+ conditioning=conditioning,
96
+ sample_size=sample_size,
97
+ sigma_min=0.3,
98
+ sigma_max=500,
99
+ sampler_type="dpmpp-3m-sde",
100
+ device=device
101
+ )
102
+
103
+ # Post-process and save audio
104
+ output = rearrange(output, "b d n -> d (b n)")
105
+ output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
106
+ torchaudio.save("output.wav", output, sample_rate)
107
+ ```
108
+
109
+ ## Citation
110
+
111
+ If you find AudioX useful in your research, please consider citing the following:
112
+
113
+ ```bibtex
114
+ @article{tian2025audiox,
115
+ title={AudioX: Diffusion Transformer for Anything-to-Audio Generation},
116
+ author={Tian, Zeyue and Jin, Yizhu and Liu, Zhaoyang and Yuan, Ruibin and Tan, Xu and Chen, Qifeng and Xue, Wei and Guo, Yike},
117
+ journal={arXiv preprint arXiv:2503.10522},
118
+ year={2025}
119
+ }
120
+ ```