Spaces:
Build error
Build error
| !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") |