NeMo
rlangman commited on
Commit
c788c3f
·
verified ·
1 Parent(s): d590c0e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -6
README.md CHANGED
@@ -59,11 +59,11 @@ import torch
59
  import soundfile as sf
60
  from nemo.collections.tts.models import AudioCodecModel
61
 
62
- codec_path = ??? # set here the model .nemo checkpoint path
63
  path_to_input_audio = ??? # path of the input audio
64
  path_to_output_audio = ??? # path of the reconstructed output audio
65
 
66
- nemo_codec_model = AudioCodecModel.restore_from(restore_path=codec_path, map_location="cpu").eval()
67
 
68
  # get discrete tokens from audio
69
  audio, _ = librosa.load(path_to_input_audio, sr=nemo_codec_model.sample_rate)
@@ -72,10 +72,11 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
72
  audio_tensor = torch.from_numpy(audio).unsqueeze(dim=0).to(device)
73
  audio_len = torch.tensor([audio_tensor[0].shape[0]]).to(device)
74
 
75
- encoded_tokens, encoded_len = nemo_codec_model.encode(audio=audio_tensor, audio_len=audio_len)
76
-
77
- # Reconstruct audio from tokens
78
- reconstructed_audio, _ = nemo_codec_model.decode(tokens=encoded_tokens, tokens_len=encoded_len)
 
79
 
80
  # save reconstructed audio
81
  output_audio = reconstructed_audio.cpu().numpy().squeeze()
 
59
  import soundfile as sf
60
  from nemo.collections.tts.models import AudioCodecModel
61
 
62
+ model_name = "nvidia/audio-codec-44khz"
63
  path_to_input_audio = ??? # path of the input audio
64
  path_to_output_audio = ??? # path of the reconstructed output audio
65
 
66
+ nemo_codec_model = AudioCodecModel.from_pretrained(model_name).eval()
67
 
68
  # get discrete tokens from audio
69
  audio, _ = librosa.load(path_to_input_audio, sr=nemo_codec_model.sample_rate)
 
72
  audio_tensor = torch.from_numpy(audio).unsqueeze(dim=0).to(device)
73
  audio_len = torch.tensor([audio_tensor[0].shape[0]]).to(device)
74
 
75
+ with torch.no_grad():
76
+ encoded_tokens, encoded_len = nemo_codec_model.encode(audio=audio_tensor, audio_len=audio_len)
77
+
78
+ # Reconstruct audio from tokens
79
+ reconstructed_audio, _ = nemo_codec_model.decode(tokens=encoded_tokens, tokens_len=encoded_len)
80
 
81
  # save reconstructed audio
82
  output_audio = reconstructed_audio.cpu().numpy().squeeze()