harryjulian commited on
Commit
155ed89
·
verified ·
1 Parent(s): 622e1b9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +11 -11
README.md CHANGED
@@ -79,25 +79,25 @@ pip install neucodec
79
  Then, to use in python:
80
 
81
  ```python
 
82
  import torch
83
- import soundfile as sf
84
- from transformers import AutoConfig
85
  from neucodec import NeuCodec
86
 
87
- model_path = "Neuphonic/neucodec"
88
-
89
- model = NeuCodec.from_pretrained(model_path)
90
  model.eval().cuda()
91
 
92
- wav, sr = sf.read("test.wav")
93
- wav_tensor = torch.from_numpy(wav).float().unsqueeze(0) # Shape: (1, T)
 
94
 
95
  with torch.no_grad():
96
- vq_code = model.encode_code(input_waveform=wav_tensor)
97
- print("Codes: ", vq_code)
98
- recon_wav = model.decode_code(vq_code).cpu() # Shape: (1, 1, T')
 
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