drewThomasson commited on
Commit
068b7da
·
verified ·
1 Parent(s): 75d1fbc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from TTS.api import TTS
4
+ import os
5
+
6
+ # Get device
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+
9
+ # Initialize TTS model
10
+ tts = TTS(model_name="voice_conversion_models/multilingual/vctk/freevc24", progress_bar=False).to(device)
11
+
12
+ def voice_conversion(input_audio, target_voice):
13
+ output_path = "output.wav"
14
+ # Perform voice conversion
15
+ tts.voice_conversion_to_file(source_wav=input_audio, target_wav=target_voice, file_path=output_path)
16
+ return output_path
17
+
18
+ # Get examples from Examples folder
19
+ examples_folder = "Examples/"
20
+ example_files = [f for f in os.listdir(examples_folder) if f.endswith(".wav")]
21
+
22
+ # Define Gradio Interface
23
+ with gr.Blocks() as demo:
24
+ gr.Markdown("## Voice Conversion using Coqui TTS")
25
+
26
+ with gr.Row():
27
+ input_audio = gr.Audio(source="microphone", label="Record or Upload Your Voice", type="filepath")
28
+ target_voice = gr.Dropdown(choices=example_files, label="Select Target Voice from Examples",
29
+ value=example_files[0], info="Located in Examples/ folder")
30
+
31
+ convert_button = gr.Button("Convert Voice")
32
+ output_audio = gr.Audio(label="Converted Voice", type="filepath")
33
+
34
+ with gr.Progress() as progress:
35
+ convert_button.click(voice_conversion, inputs=[input_audio, target_voice], outputs=output_audio,
36
+ progress=progress)
37
+
38
+ # Launch with public=True for public URL access and share link
39
+ demo.launch(share=True)