HKUST-Audio
commited on
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Getting Started with XCodec2 on Hugging Face
|
2 |
+
|
3 |
+
To use `xcodec2`, ensure you have it installed. You can install it using the following command:
|
4 |
+
|
5 |
+
```bash
|
6 |
+
conda create -n xcodec2 python=3.9
|
7 |
+
conda activate xcodec2
|
8 |
+
pip install xcodec2
|
9 |
+
```
|
10 |
+
Then,
|
11 |
+
```python
|
12 |
+
import torch
|
13 |
+
import soundfile as sf
|
14 |
+
from transformers import AutoConfig
|
15 |
+
|
16 |
+
|
17 |
+
from xcodec2.modeling_xcodec2 import XCodec2Model
|
18 |
+
|
19 |
+
model_path = "HKUST-Audio/xcodec2"
|
20 |
+
|
21 |
+
model = XCodec2Model.from_pretrained(model_path)
|
22 |
+
model.eval().cuda()
|
23 |
+
|
24 |
+
|
25 |
+
wav, sr = sf.read("test.wav")
|
26 |
+
wav_tensor = torch.from_numpy(wav).float().unsqueeze(0)
|
27 |
+
|
28 |
+
|
29 |
+
with torch.no_grad():
|
30 |
+
|
31 |
+
vq_code = model.encode_code(input_waveform=wav_tensor)
|
32 |
+
print("Code:", vq_code )
|
33 |
+
|
34 |
+
recon_wav = model.decode_code(vq_code).cpu()
|
35 |
+
|
36 |
+
|
37 |
+
sf.write("reconstructed.wav", recon_wav[0, 0, :].numpy(), sr)
|
38 |
+
print("Done! Check reconstructed.wav")
|
39 |
+
```
|