SohomToom commited on
Commit
0c20337
·
verified ·
1 Parent(s): e45ee80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -1,29 +1,36 @@
1
  import os
2
  os.environ["NUMBA_DISABLE_CACHE"] = "1"
3
  import gradio as gr
4
- from openvoice import OpenVoice
 
5
 
6
- # Load OpenVoice model (adjust to your setup)
7
- model = OpenVoice(language="en")
 
8
 
9
- def clone_and_speak(audio, text):
10
- output_path = "output.wav"
11
- model.clone_voice(
12
- source_audio_path=audio.name,
13
- target_text=text,
14
- output_path=output_path
15
- )
16
- return output_path
17
 
18
- with gr.Blocks() as demo:
19
- gr.Markdown("# OpenVoice TTS - Hugging Face Space")
20
- with gr.Row():
21
- audio_input = gr.Audio(label="Upload voice to clone", type="file")
22
- text_input = gr.Textbox(label="Enter text to synthesize")
23
- with gr.Row():
24
- generate_btn = gr.Button("Generate Audio")
25
- audio_output = gr.Audio(label="Synthesized Output", type="filepath")
26
 
27
- generate_btn.click(fn=clone_and_speak, inputs=[audio_input, text_input], outputs=audio_output)
 
 
 
 
 
 
 
28
 
29
- demo.launch()
 
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()