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