Update README.md
Browse files
README.md
CHANGED
|
@@ -2,4 +2,34 @@
|
|
| 2 |
license: apache-2.0
|
| 3 |
base_model:
|
| 4 |
- neuphonic/neucodec
|
| 5 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
base_model:
|
| 4 |
- neuphonic/neucodec
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
# NeuCodec Onnx Decoder
|
| 8 |
+
|
| 9 |
+
This is an onnx-compiled version of the decoder of [NeuCodec](https://huggingface.co/neuphonic/neucodec).
|
| 10 |
+
It's main use case is providing a low footprint decoder for on-device TTS.
|
| 11 |
+
|
| 12 |
+
## Usage
|
| 13 |
+
```python
|
| 14 |
+
import librosa
|
| 15 |
+
import torch
|
| 16 |
+
import torchaudio
|
| 17 |
+
from torchaudio import transforms as T
|
| 18 |
+
from neucodec import NeuCodec, NeuCodecOnnxDecoder
|
| 19 |
+
|
| 20 |
+
model = NeuCodec.from_pretrained("neuphonic/neucodec")
|
| 21 |
+
model.eval()
|
| 22 |
+
compiled_model = NeuCodecOnnxDecoder.from_pretrained("neuphonic/neucodec-onnx-decoder")
|
| 23 |
+
|
| 24 |
+
y, sr = torchaudio.load(librosa.ex("libri1"))
|
| 25 |
+
if sr != 16_000:
|
| 26 |
+
y = T.Resample(sr, 16_000)(y)[None, ...] # (B, 1, T_16)
|
| 27 |
+
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
fsq_codes = model.encode_code(y)
|
| 30 |
+
# fsq_codes = model.encode_code(librosa.ex("libri1")) # or directly pass your filepath!
|
| 31 |
+
print(f"Codes shape: {fsq_codes.shape}")
|
| 32 |
+
recon = compiled_model.decode_code(fsq_codes).cpu() # (B, 1, T_24)
|
| 33 |
+
|
| 34 |
+
torchaudio.save("reconstructed.wav", recon[0, :, :], 24_000)
|
| 35 |
+
```
|