Doubleupai commited on
Commit
2e0b69b
·
verified ·
1 Parent(s): 1d48ea1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from TTS.api import TTS
3
+
4
+ # Load a pre-trained TTS model
5
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
6
+
7
+ def clone_voice(text, audio_file):
8
+ # Convert the input audio to a format that the model can use
9
+ # This step is simplified; in a real-world scenario, you might need to preprocess the audio
10
+ wav, sr = tts.load_audio(audio_file)
11
+
12
+ # Clone the voice using the input audio as a reference
13
+ # This is a simplified example; in a real-world scenario, you might use a more complex cloning process
14
+ cloned_wav = tts.tts(text, speaker_wav=wav, language="en")
15
+
16
+ # Save the cloned audio to a file
17
+ output_file = "cloned_voice.wav"
18
+ tts.save_wav(cloned_wav, output_file)
19
+
20
+ return output_file
21
+
22
+ # Create the Gradio interface
23
+ iface = gr.Interface(
24
+ fn=clone_voice,
25
+ inputs=[
26
+ gr.Textbox(label="Text to Clone"),
27
+ gr.Audio(label="Reference Audio", type="filepath")
28
+ ],
29
+ outputs=gr.Audio(label="Cloned Voice"),
30
+ title="Voice Cloning",
31
+ description="Upload a reference audio and input text to clone the voice."
32
+ )
33
+
34
+ # Launch the interface
35
+ iface.launch()