Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,26 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
from scipy.io.wavfile import read
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
!pip install torch torchaudio
|
| 2 |
+
!pip install nemo_toolkit[all]
|
|
|
|
| 3 |
|
| 4 |
+
import torch
|
| 5 |
+
import nemo
|
| 6 |
+
import nemo.collections.asr as nemo_asr
|
| 7 |
+
import nemo.collections.tts as nemo_tts
|
| 8 |
+
from scipy.io.wavfile import write
|
| 9 |
|
| 10 |
+
# Load pre-trained models
|
| 11 |
+
tacotron2 = nemo_tts.models.Tacotron2Model.from_pretrained("tts_en_tacotron2")
|
| 12 |
+
waveglow = nemo_tts.models.WaveGlowModel.from_pretrained("tts_waveglow_88m")
|
| 13 |
|
| 14 |
+
def clone_voice(text, audio_path):
|
| 15 |
+
# Generate spectrogram from text
|
| 16 |
+
parsed = tacotron2.parse(text)
|
| 17 |
+
spectrogram = tacotron2.generate_spectrogram(tokens=parsed)
|
| 18 |
|
| 19 |
+
# Generate audio from spectrogram
|
| 20 |
+
audio = waveglow.convert_spectrogram_to_audio(spec=spectrogram)
|
| 21 |
|
| 22 |
+
# Save the audio file
|
| 23 |
+
write(audio_path, 22050, audio.cpu().numpy())
|
| 24 |
+
|
| 25 |
+
# Example usage
|
| 26 |
+
clone_voice("Hello, this is a cloned voice.", "output.wav")
|