speechbrainteam commited on
Commit
810cc65
1 Parent(s): 6547910

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -0
README.md CHANGED
@@ -46,6 +46,53 @@ mel_specs = torch.rand(2, 80,298)
46
  waveforms = hifi_gan.decode_batch(mel_specs)
47
  ```
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ### Inference on GPU
50
  To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
51
 
 
46
  waveforms = hifi_gan.decode_batch(mel_specs)
47
  ```
48
 
49
+ ```python
50
+ import torchaudio
51
+ from speechbrain.pretrained import HIFIGAN
52
+ from speechbrain.lobes.models.FastSpeech2 import mel_spectogram
53
+
54
+ # Load a pretrained HIFIGAN Vocoder
55
+ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-16kHz", savedir="tmpdir")
56
+
57
+ # Load an audio file (an example file can be found in this repository)
58
+ # Ensure that the audio signal is sampled at 16000 Hz; refer to the provided link for a 22050 Hz Vocoder.
59
+ #signal, rate = torchaudio.load('speechbrain/tts-hifigan-libritts-16kHz/example_16kHz.wav')
60
+ signal, rate = torchaudio.load('/home/mirco/Downloads/example_16kHz.wav')
61
+
62
+ # Ensure the audio is sigle channel
63
+ signal = signal[0].squeeze()
64
+
65
+ torchaudio.save('waveform.wav', signal.unsqueeze(0), 16000)
66
+
67
+ # Compute the mel spectrogram.
68
+ # IMPORTANT: Use these specific parameters to match the Vocoder's training settings for optimal results.
69
+ spectrogram, _ = mel_spectogram(
70
+ audio=signal.squeeze(),
71
+ sample_rate=16000,
72
+ hop_length=256,
73
+ win_length=1024,
74
+ n_mels=80,
75
+ n_fft=1024,
76
+ f_min=0.0,
77
+ f_max=8000.0,
78
+ power=1,
79
+ normalized=False,
80
+ min_max_energy_norm=True,
81
+ norm="slaney",
82
+ mel_scale="slaney",
83
+ compression=True
84
+ )
85
+
86
+ # Convert the spectrogram to waveform
87
+ waveforms = hifi_gan.decode_batch(spectrogram)
88
+
89
+ # Save the reconstructed audio as a waveform
90
+ torchaudio.save('waveform_reconstructed.wav', waveforms.squeeze(1), 16000)
91
+
92
+ # If everything is set up correctly, the original and reconstructed audio should be nearly indistinguishable.
93
+
94
+ ```
95
+
96
  ### Inference on GPU
97
  To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
98