drewThomasson commited on
Commit
1323c15
·
verified ·
1 Parent(s): 23a59ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -60
app.py CHANGED
@@ -4,72 +4,54 @@ from TTS.api import TTS
4
  import os
5
  import subprocess
6
 
7
- def test_xtts():
8
- with gr.Progress() as progress:
9
- progress(0, desc="Running XttsV2 check...")
10
- # Check device availability
11
- device = "cuda" if torch.cuda.is_available() else "cpu"
12
-
13
- # Auto agree to XTTS terms
14
- os.environ["COQUI_TOS_AGREED"] = "1"
15
-
16
- # Download default voice file
17
- os.system('curl -L -o default_voice.wav https://github.com/DrewThomasson/ebook2audiobookXTTS/raw/main/default_voice.wav')
18
-
19
- # Initialize TTS
20
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
21
-
22
- # Generate audio
23
- output_file = "xtts_output.wav"
24
- tts.tts_to_file(text="Hello world!", speaker_wav="default_voice.wav", language="en", file_path=output_file)
25
-
26
- progress(1, desc="XttsV2 check completed")
27
- return output_file
28
-
29
- def test_styletts2():
30
- with gr.Progress() as progress:
31
- progress(0, desc="Running StyleTTS2 check...")
32
- # Import and download the voice file
33
- from styletts2 import tts
34
- os.system('curl -L -o default_voice.wav https://github.com/DrewThomasson/ebook2audiobookXTTS/raw/main/default_voice.wav')
35
-
36
- # Initialize and run inference
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
- with gr.Row():
60
- with gr.Column():
61
- xtts_button = gr.Button("Test XttsV2")
62
- xtts_output = gr.File(label="Download XttsV2 Output")
63
- with gr.Column():
64
- styletts2_button = gr.Button("Test StyleTTS2")
65
- styletts2_output = gr.File(label="Download StyleTTS2 Output")
66
- with gr.Column():
67
- piper_button = gr.Button("Test Piper-TTS")
68
- piper_output = gr.File(label="Download Piper Output")
69
 
70
- xtts_button.click(fn=test_xtts, outputs=xtts_output)
71
- styletts2_button.click(fn=test_styletts2, outputs=styletts2_output)
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()