Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,42 @@
|
|
1 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Run the setup.py install command
|
4 |
try:
|
5 |
subprocess.run(['python', 'setup.py', 'install', '--user'], check=True)
|
6 |
-
|
7 |
except subprocess.CalledProcessError as e:
|
8 |
-
|
9 |
-
|
10 |
-
import gradio as gr
|
11 |
-
import torch
|
12 |
-
from TTS.api import TTS
|
13 |
|
14 |
# Get device
|
15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
16 |
|
17 |
# Init TTS
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
def voice_clone(text: str, speaker_wav: str, language: str):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
|
26 |
iface = gr.Interface(fn=voice_clone,
|
27 |
inputs=[gr.Textbox(label="Text", info="One or two sentences at a time is better", max_lines=3), gr.Audio(type="filepath", label="Voice spectrogram"), gr.Radio(label="language", info="Select an output language for the synthesised speech", choices=["en", "zh-cn", "ja", "de", "fr", "it", "pt", "pl", "tr", "ko", "nl", "cs", "ar", "es", "hu", "ru"], value="en")],
|
28 |
outputs=gr.Audio(type="filepath", label="Synthesised spectrogram"),
|
29 |
title="Voice Cloning")
|
30 |
|
31 |
-
iface.launch
|
|
|
1 |
import subprocess
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from TTS.api import TTS
|
5 |
+
|
6 |
+
# Setup detailed logging
|
7 |
+
import logging
|
8 |
+
logging.basicConfig(level=logging.DEBUG)
|
9 |
|
10 |
# Run the setup.py install command
|
11 |
try:
|
12 |
subprocess.run(['python', 'setup.py', 'install', '--user'], check=True)
|
13 |
+
logging.info("Installation successful.")
|
14 |
except subprocess.CalledProcessError as e:
|
15 |
+
logging.error(f"Installation failed with error: {e}")
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Get device
|
18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
+
logging.debug(f"Using device: {device}")
|
20 |
|
21 |
# Init TTS
|
22 |
+
try:
|
23 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
24 |
+
except Exception as e:
|
25 |
+
logging.error(f"Failed to initialize TTS: {e}")
|
26 |
|
27 |
def voice_clone(text: str, speaker_wav: str, language: str):
|
28 |
+
try:
|
29 |
+
# Run TTS
|
30 |
+
logging.info(f"Processing with speaker wav: {speaker_wav}")
|
31 |
+
tts.tts_to_file(text=text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
|
32 |
+
return "output.wav"
|
33 |
+
except Exception as e:
|
34 |
+
logging.error(f"Failed to process TTS: {e}")
|
35 |
+
return None
|
36 |
|
37 |
iface = gr.Interface(fn=voice_clone,
|
38 |
inputs=[gr.Textbox(label="Text", info="One or two sentences at a time is better", max_lines=3), gr.Audio(type="filepath", label="Voice spectrogram"), gr.Radio(label="language", info="Select an output language for the synthesised speech", choices=["en", "zh-cn", "ja", "de", "fr", "it", "pt", "pl", "tr", "ko", "nl", "cs", "ar", "es", "hu", "ru"], value="en")],
|
39 |
outputs=gr.Audio(type="filepath", label="Synthesised spectrogram"),
|
40 |
title="Voice Cloning")
|
41 |
|
42 |
+
iface.launch()
|