Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
3 |
import soundfile as sf
|
4 |
from TTS.api import TTS
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
MODEL_NAME = "tts_models/en/
|
8 |
tts = TTS(model_name=MODEL_NAME, progress_bar=True, gpu=False)
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
f.write(uploaded_file.read())
|
37 |
-
input_audio_path = "input_audio.wav"
|
38 |
-
|
39 |
-
# Step 3: Clone voice and synthesize speech
|
40 |
-
if st.button("Clone Voice"):
|
41 |
-
if uploaded_file and text_input:
|
42 |
-
# Process the input audio
|
43 |
-
audio, sr = preprocess_audio(input_audio_path)
|
44 |
-
sf.write("processed_audio.wav", audio, sr)
|
45 |
-
|
46 |
-
# Clone the voice and synthesize speech
|
47 |
try:
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
52 |
st.audio(output_path, format="audio/wav")
|
53 |
-
st.
|
54 |
except Exception as e:
|
55 |
-
st.error(f"Error
|
56 |
-
|
57 |
-
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import os
|
4 |
import soundfile as sf
|
5 |
from TTS.api import TTS
|
6 |
+
import torch
|
7 |
+
from io import BytesIO
|
8 |
|
9 |
+
# Set up the model for text-to-speech (TTS)
|
10 |
+
MODEL_NAME = "tts_models/en/ljspeech/tacotron2-DDC" # Example TTS model; adjust as needed
|
11 |
tts = TTS(model_name=MODEL_NAME, progress_bar=True, gpu=False)
|
12 |
|
13 |
+
# Function to load audio file
|
14 |
+
def load_audio(file):
|
15 |
+
audio_data, sample_rate = sf.read(file)
|
16 |
+
return audio_data, sample_rate
|
17 |
+
|
18 |
+
# Function to save the generated audio to a file
|
19 |
+
def save_audio(output_audio, sample_rate):
|
20 |
+
output_path = "output_cloned_voice.wav"
|
21 |
+
sf.write(output_path, output_audio, sample_rate)
|
22 |
+
return output_path
|
23 |
+
|
24 |
+
# Streamlit app
|
25 |
+
def main():
|
26 |
+
st.title("Voice Cloning Tool")
|
27 |
+
st.markdown("Upload a voice input, and get the cloned voice output.")
|
28 |
+
|
29 |
+
# File upload
|
30 |
+
audio_file = st.file_uploader("Upload your audio file", type=["wav", "mp3"])
|
31 |
+
|
32 |
+
if audio_file is not None:
|
33 |
+
st.audio(audio_file, format="audio/wav")
|
34 |
+
|
35 |
+
# Load audio file
|
36 |
+
audio_data, sample_rate = load_audio(audio_file)
|
37 |
+
|
38 |
+
# Perform voice cloning (This assumes your TTS model supports some form of input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
try:
|
40 |
+
st.text("Processing your input...")
|
41 |
+
output_audio = tts.tts(audio_data) # Pass the audio to your TTS model for cloning
|
42 |
+
output_path = save_audio(output_audio, sample_rate)
|
43 |
+
|
44 |
+
# Provide download link
|
45 |
st.audio(output_path, format="audio/wav")
|
46 |
+
st.markdown(f"[Download Cloned Voice](/{output_path})")
|
47 |
except Exception as e:
|
48 |
+
st.error(f"Error processing audio: {e}")
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
main()
|