Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,36 @@
|
|
1 |
import os
|
2 |
os.environ["NUMBA_DISABLE_CACHE"] = "1"
|
3 |
import gradio as gr
|
4 |
-
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
)
|
16 |
-
return output_path
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
|
|
1 |
import os
|
2 |
os.environ["NUMBA_DISABLE_CACHE"] = "1"
|
3 |
import gradio as gr
|
4 |
+
import os
|
5 |
+
import torch
|
6 |
|
7 |
+
# Add openvoice path
|
8 |
+
import sys
|
9 |
+
sys.path.append("openvoice")
|
10 |
|
11 |
+
from openvoice.api import ToneColorConverter
|
12 |
+
from openvoice.inference import voice_conversion
|
13 |
+
|
14 |
+
# Set up paths
|
15 |
+
ckpt_converter = './checkpoints/converter'
|
16 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
17 |
|
18 |
+
converter = ToneColorConverter(f"{ckpt_converter}/config.json", device=device)
|
19 |
+
converter.load_ckpt(f"{ckpt_converter}/converter.ckpt")
|
20 |
+
|
21 |
+
def convert_voice(audio_file, text_prompt):
|
22 |
+
output_path = "./results/output.wav"
|
23 |
+
# You must clone reference audio using clone.sh or similar step in Dockerfile
|
24 |
+
voice_conversion(converter, audio_file.name, text_prompt, output_path, device)
|
25 |
+
return output_path
|
26 |
|
27 |
+
iface = gr.Interface(
|
28 |
+
fn=convert_voice,
|
29 |
+
inputs=[
|
30 |
+
gr.Audio(type="filepath", label="Input Voice (WAV)"),
|
31 |
+
gr.Textbox(label="Prompt (e.g., 'Speak in a cheerful tone')"),
|
32 |
+
],
|
33 |
+
outputs=gr.Audio(label="Converted Voice")
|
34 |
+
)
|
35 |
|
36 |
+
iface.launch()
|