qqwjq1981 commited on
Commit
e3e1200
Β·
verified Β·
1 Parent(s): e570cc2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from TTS.api import TTS
4
+ import tempfile
5
+
6
+ # Load XTTS model
7
+ tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
8
+
9
+ def clone_voice(text, speaker_wav):
10
+ if speaker_wav is None:
11
+ return None, "Please upload a reference audio file."
12
+
13
+ # Save uploaded audio
14
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
15
+ tmp.write(speaker_wav.read())
16
+ speaker_path = tmp.name
17
+
18
+ output_path = "cloned_output.wav"
19
+
20
+ # Generate audio using XTTS
21
+ tts.tts_to_file(
22
+ text=text,
23
+ speaker_wav=speaker_path,
24
+ language="zh",
25
+ file_path=output_path
26
+ )
27
+
28
+ return output_path, "Voice cloning completed successfully."
29
+
30
+ # Gradio UI
31
+ demo = gr.Interface(
32
+ fn=clone_voice,
33
+ inputs=[
34
+ gr.Textbox(label="Enter Chinese Text"),
35
+ gr.Audio(label="Upload Speaker Audio (.wav)", type="file")
36
+ ],
37
+ outputs=[
38
+ gr.Audio(label="Cloned Output Audio"),
39
+ gr.Textbox(label="Status")
40
+ ],
41
+ title="XTTS Voice Cloning Demo",
42
+ description="Upload reference audio and enter Chinese text to generate speech in cloned voice."
43
+ )
44
+
45
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ TTS
2
+ gradio