meraj12 commited on
Commit
87cbc4f
·
verified ·
1 Parent(s): 07c81dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -1,20 +1,26 @@
1
- import streamlit as st
2
- import os
3
- from scipy.io.wavfile import read
4
 
5
- st.title("Voice Cloning Application")
 
 
 
 
6
 
7
- uploaded_file = st.file_uploader("Upload an audio file", type=["wav"])
8
- text_input = st.text_input("Enter the text you want to clone")
 
9
 
10
- if uploaded_file is not None and text_input:
11
- # Save the uploaded file
12
- with open("uploaded_audio.wav", "wb") as f:
13
- f.write(uploaded_file.getbuffer())
14
 
15
- # Clone the voice
16
- clone_voice(text_input, "cloned_voice.wav")
17
 
18
- # Play the original and cloned audio
19
- st.audio("uploaded_audio.wav", format='audio/wav')
20
- st.audio("cloned_voice.wav", format='audio/wav')
 
 
 
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")