Prof-Hunter commited on
Commit
7618db9
·
verified ·
1 Parent(s): e4b83c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -50
app.py CHANGED
@@ -2,29 +2,8 @@ import gradio as gr
2
  import edge_tts
3
  import asyncio
4
  import tempfile
5
-
6
- import torch
7
- import soundfile as sf
8
-
9
- from melo import TTS
10
-
11
-
12
- # -----------------------------
13
- # Load MeloTTS
14
- # -----------------------------
15
-
16
- print("Loading MeloTTS...")
17
-
18
- device = "cuda" if torch.cuda.is_available() else "cpu"
19
-
20
- melo_tts = TTS(
21
- language="EN",
22
- device=device
23
- )
24
-
25
- speaker_ids = list(melo_tts.hps.data.spk2id.keys())
26
-
27
- print("MeloTTS loaded on:", device)
28
 
29
 
30
  # -----------------------------
@@ -37,6 +16,7 @@ async def get_voices():
37
 
38
  return {
39
  f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v["ShortName"]
 
40
  for v in voices
41
  }
42
 
@@ -77,18 +57,14 @@ async def edge_tts_engine(text, voice, rate, pitch):
77
 
78
 
79
  # -----------------------------
80
- # MeloTTS
81
  # -----------------------------
82
 
83
- def melo_tts_engine(text, rate):
84
 
85
  if not text.strip():
86
  return None, "Please enter text."
87
 
88
- speed = 1.0 + rate / 100
89
-
90
- speaker = speaker_ids[0]
91
-
92
  with tempfile.NamedTemporaryFile(
93
  delete=False,
94
  suffix=".wav"
@@ -96,12 +72,15 @@ def melo_tts_engine(text, rate):
96
 
97
  path = tmp.name
98
 
99
- melo_tts.tts_to_file(
100
- text=text,
101
- speaker_id=speaker,
102
- file_path=path,
103
- speed=speed,
104
- )
 
 
 
105
 
106
  return path, None
107
 
@@ -118,12 +97,9 @@ async def unified_tts(
118
  engine,
119
  ):
120
 
121
- if engine == "Melo (Open Source)":
122
 
123
- return melo_tts_engine(
124
- text,
125
- rate,
126
- )
127
 
128
  else:
129
 
@@ -148,7 +124,7 @@ async def create_demo():
148
  gr.Markdown("""
149
  # 🎙️ AI Text-to-Speech Lab (HF Free)
150
 
151
- **MeloTTS (Open Source) vs Edge (Cloud)**
152
  """)
153
 
154
  text_input = gr.Textbox(
@@ -157,8 +133,8 @@ async def create_demo():
157
  )
158
 
159
  engine_radio = gr.Radio(
160
- ["Melo (Open Source)", "Edge (Cloud)"],
161
- value="Melo (Open Source)",
162
  label="Engine",
163
  )
164
 
@@ -167,12 +143,6 @@ async def create_demo():
167
  label="Edge Voice",
168
  )
169
 
170
- rate_slider = gr.Slider(
171
- -40, 40, 0,
172
- step=1,
173
- label="Speed",
174
- )
175
-
176
  generate_btn = gr.Button("Generate", variant="primary")
177
 
178
  audio_output = gr.Audio()
@@ -184,7 +154,7 @@ async def create_demo():
184
  inputs=[
185
  text_input,
186
  voice_dropdown,
187
- rate_slider,
188
  None,
189
  engine_radio,
190
  ],
 
2
  import edge_tts
3
  import asyncio
4
  import tempfile
5
+ import subprocess
6
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
 
9
  # -----------------------------
 
16
 
17
  return {
18
  f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v["ShortName"]
19
+ for v["ShortName"]
20
  for v in voices
21
  }
22
 
 
57
 
58
 
59
  # -----------------------------
60
+ # Mimic3 TTS
61
  # -----------------------------
62
 
63
+ def mimic3_tts_engine(text):
64
 
65
  if not text.strip():
66
  return None, "Please enter text."
67
 
 
 
 
 
68
  with tempfile.NamedTemporaryFile(
69
  delete=False,
70
  suffix=".wav"
 
72
 
73
  path = tmp.name
74
 
75
+ # Run Mimic3 CLI
76
+ cmd = [
77
+ "mimic3",
78
+ "--voice", "en_US/vctk_low",
79
+ text,
80
+ "--output-file", path,
81
+ ]
82
+
83
+ subprocess.run(cmd, check=True)
84
 
85
  return path, None
86
 
 
97
  engine,
98
  ):
99
 
100
+ if engine == "Mimic3 (Open Source)":
101
 
102
+ return mimic3_tts_engine(text)
 
 
 
103
 
104
  else:
105
 
 
124
  gr.Markdown("""
125
  # 🎙️ AI Text-to-Speech Lab (HF Free)
126
 
127
+ **Mimic3 (Open Source) vs Edge (Cloud)**
128
  """)
129
 
130
  text_input = gr.Textbox(
 
133
  )
134
 
135
  engine_radio = gr.Radio(
136
+ ["Mimic3 (Open Source)", "Edge (Cloud)"],
137
+ value="Mimic3 (Open Source)",
138
  label="Engine",
139
  )
140
 
 
143
  label="Edge Voice",
144
  )
145
 
 
 
 
 
 
 
146
  generate_btn = gr.Button("Generate", variant="primary")
147
 
148
  audio_output = gr.Audio()
 
154
  inputs=[
155
  text_input,
156
  voice_dropdown,
157
+ None,
158
  None,
159
  engine_radio,
160
  ],