sg123321 commited on
Commit
5de0578
·
verified ·
1 Parent(s): c50d843

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from TTS.api import TTS
4
+ import torch
5
+ import spaces
6
+
7
+ # License accept
8
+ os.environ["COQUI_TOS_AGREED"] = "1"
9
+
10
+ # Model load (Wait for 2-3 mins first time)
11
+ device = "cuda" if torch.cuda.is_available() else "cpu"
12
+ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
13
+
14
+ @spaces.GPU(duration=60)
15
+ def clone_voice(text, language, speaker_audio):
16
+ output_path = "output.wav"
17
+ tts.tts_to_file(
18
+ text=text,
19
+ file_path=output_path,
20
+ speaker_wav=speaker_audio,
21
+ language=language
22
+ )
23
+ return output_path
24
+
25
+ iface = gr.Interface(
26
+ fn=clone_voice,
27
+ inputs=[
28
+ gr.Textbox(label="Text", value="Namaste, kaise hain aap?"),
29
+ gr.Dropdown(label="Language", choices=["hi", "en"], value="hi"),
30
+ gr.Audio(label="Reference Audio", type="filepath")
31
+ ],
32
+ outputs=gr.Audio(label="Cloned Voice")
33
+ )
34
+ iface.launch()