ghostai1 commited on
Commit
2c7bd07
Β·
verified Β·
1 Parent(s): c4c3df6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -1,28 +1,24 @@
1
- # Simple Text-to-Speech | CPU-only HF Space
2
-
3
  import gradio as gr
4
- from transformers import pipeline
5
-
6
- # ── load once on startup (β‰ˆ120 MB, CPU-friendly) ─────────────────────
7
- tts = pipeline(
8
- "text-to-speech",
9
- model="facebook/fastspeech2-en-ljspeech",
10
- vocoder="facebook/hifigan-en-ljspeech",
11
- device=-1 # force CPU
12
- )
13
 
14
  def speak(text: str):
15
  if not text.strip():
16
  return None
17
- out = tts(text)
18
- return (out["sampling_rate"], out["audio"])
 
 
 
 
 
19
 
20
- with gr.Blocks(title="TTS Demo") as demo:
21
- gr.Markdown("# πŸ”Š Simple Text-to-Speech\nType text, click **Speak**.")
22
- txt = gr.Textbox(lines=3, placeholder="Enter English text here…")
23
  btn = gr.Button("Speak πŸ”ˆ", variant="primary")
24
- audio = gr.Audio(label="Output", type="numpy")
25
- btn.click(speak, txt, audio)
26
 
27
  if __name__ == "__main__":
28
  demo.launch(server_name="0.0.0.0")
 
1
+ import tempfile
2
+ from gtts import gTTS
3
  import gradio as gr
 
 
 
 
 
 
 
 
 
4
 
5
  def speak(text: str):
6
  if not text.strip():
7
  return None
8
+ # Generate speech via Google Translate TTS
9
+ tts = gTTS(text)
10
+ # Write to a temp file and return its path
11
+ tmp = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False)
12
+ tts.write_to_fp(tmp)
13
+ tmp.flush()
14
+ return tmp.name
15
 
16
+ with gr.Blocks(title="πŸ—£οΈ Simple TTS (gTTS)") as demo:
17
+ gr.Markdown("# πŸ—£οΈ Text-to-Speech\nType any text below and click **Speak**.")
18
+ inp = gr.Textbox(lines=3, placeholder="Enter text here...")
19
  btn = gr.Button("Speak πŸ”ˆ", variant="primary")
20
+ out = gr.Audio(label="Output audio", type="filepath")
21
+ btn.click(speak, inp, out)
22
 
23
  if __name__ == "__main__":
24
  demo.launch(server_name="0.0.0.0")