drewThomasson
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,72 +4,54 @@ from TTS.api import TTS
|
|
4 |
import os
|
5 |
import subprocess
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
my_tts = tts.StyleTTS2()
|
38 |
-
output_file = "styletts2_output.wav"
|
39 |
-
my_tts.inference("Hello there, I am now a python package.", output_wav_file=output_file)
|
40 |
-
|
41 |
-
progress(1, desc="StyleTTS2 check completed")
|
42 |
-
return output_file
|
43 |
-
|
44 |
-
def test_piper():
|
45 |
-
with gr.Progress() as progress:
|
46 |
-
progress(0, desc="Running Piper-TTS check...")
|
47 |
-
# Run piper command and generate output
|
48 |
-
output_file = "piper_output.wav"
|
49 |
-
command = f'echo "Welcome to the world of speech synthesis!" | piper --model en_US-lessac-medium --output_file {output_file}'
|
50 |
-
subprocess.run(command, shell=True)
|
51 |
-
|
52 |
-
progress(1, desc="Piper-TTS check completed")
|
53 |
-
return output_file
|
54 |
|
55 |
# Create Gradio Interface
|
56 |
with gr.Blocks() as demo:
|
57 |
gr.Markdown("## Test TTS Models with Progress Bar")
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
piper_button.click(fn=test_piper, outputs=piper_output)
|
73 |
|
74 |
# Launch the app
|
75 |
demo.launch()
|
|
|
4 |
import os
|
5 |
import subprocess
|
6 |
|
7 |
+
def run_all_models(input_text, progress=gr.Progress()):
|
8 |
+
# Initialize output file paths
|
9 |
+
xtts_output = "xtts_output.wav"
|
10 |
+
styletts2_output = "styletts2_output.wav"
|
11 |
+
piper_output = "piper_output.wav"
|
12 |
+
|
13 |
+
# 1. Running XttsV2
|
14 |
+
progress(0, desc="Running XttsV2...")
|
15 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
17 |
+
os.system('curl -L -o default_voice.wav https://github.com/DrewThomasson/ebook2audiobookXTTS/raw/main/default_voice.wav')
|
18 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
19 |
+
tts.tts_to_file(text=input_text, speaker_wav="default_voice.wav", language="en", file_path=xtts_output)
|
20 |
+
progress(1/3, desc="XttsV2 completed")
|
21 |
+
|
22 |
+
# 2. Running StyleTTS2
|
23 |
+
progress(1/3, desc="Running StyleTTS2...")
|
24 |
+
from styletts2 import tts as style_tts
|
25 |
+
my_tts = style_tts.StyleTTS2()
|
26 |
+
my_tts.inference(input_text, output_wav_file=styletts2_output)
|
27 |
+
progress(2/3, desc="StyleTTS2 completed")
|
28 |
+
|
29 |
+
# 3. Running Piper-TTS
|
30 |
+
progress(2/3, desc="Running Piper-TTS...")
|
31 |
+
command = f'echo "{input_text}" | piper --model en_US-lessac-medium --output_file {piper_output}'
|
32 |
+
subprocess.run(command, shell=True)
|
33 |
+
progress(3/3, desc="Piper-TTS completed")
|
34 |
+
|
35 |
+
# Return the file paths for downloading
|
36 |
+
return xtts_output, styletts2_output, piper_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Create Gradio Interface
|
39 |
with gr.Blocks() as demo:
|
40 |
gr.Markdown("## Test TTS Models with Progress Bar")
|
41 |
|
42 |
+
# Input text box for user input
|
43 |
+
input_text = gr.Textbox(label="Input Text", placeholder="Enter the text you want all models to use", value="Hello world!")
|
44 |
+
|
45 |
+
# Download buttons for the outputs
|
46 |
+
xtts_output = gr.File(label="Download XttsV2 Output")
|
47 |
+
styletts2_output = gr.File(label="Download StyleTTS2 Output")
|
48 |
+
piper_output = gr.File(label="Download Piper Output")
|
49 |
+
|
50 |
+
# Button to run all models and show progress
|
51 |
+
run_button = gr.Button("Run All Models")
|
52 |
|
53 |
+
# Link button click to the run_all_models function
|
54 |
+
run_button.click(fn=run_all_models, inputs=input_text, outputs=[xtts_output, styletts2_output, piper_output])
|
|
|
55 |
|
56 |
# Launch the app
|
57 |
demo.launch()
|