Update README.md
Browse files
README.md
CHANGED
@@ -79,25 +79,25 @@ pip install neucodec
|
|
79 |
Then, to use in python:
|
80 |
|
81 |
```python
|
|
|
82 |
import torch
|
83 |
-
import
|
84 |
-
from
|
85 |
from neucodec import NeuCodec
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
model = NeuCodec.from_pretrained(model_path)
|
90 |
model.eval().cuda()
|
91 |
|
92 |
-
|
93 |
-
|
|
|
94 |
|
95 |
with torch.no_grad():
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
99 |
|
100 |
-
|
101 |
sf.write("reconstructed.wav", recon_wav[0, 0, :].numpy(), sr)
|
102 |
```
|
103 |
|
|
|
79 |
Then, to use in python:
|
80 |
|
81 |
```python
|
82 |
+
import librosa
|
83 |
import torch
|
84 |
+
import torchaudio
|
85 |
+
from torchaudio import transforms as T
|
86 |
from neucodec import NeuCodec
|
87 |
|
88 |
+
model = NeuCodec.from_pretrained("neuphonic/neucodec")
|
|
|
|
|
89 |
model.eval().cuda()
|
90 |
|
91 |
+
y, sr = torchaudio.load(librosa.ex("libri1"))
|
92 |
+
if sr != 16_000:
|
93 |
+
y = T.Resample(sr, 16_000)(y)[None, ...] # (B, 1, T_16)
|
94 |
|
95 |
with torch.no_grad():
|
96 |
+
fsq_codes = model.encode_code(y)
|
97 |
+
# fsq_codes = model.encode_code(librosa.ex("libri1")) # or directly pass your filepath!
|
98 |
+
print(f"Codes shape: {fsq_codes.shape}")
|
99 |
+
recon = model.decode_code(fsq_codes).cpu() # (B, 1, T_24)
|
100 |
|
|
|
101 |
sf.write("reconstructed.wav", recon_wav[0, 0, :].numpy(), sr)
|
102 |
```
|
103 |
|