arjunbroepic commited on
Commit
98e26c7
·
verified ·
1 Parent(s): e791b3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -37
app.py CHANGED
@@ -2,66 +2,50 @@ import gradio as gr
2
  from supertonic import TTS
3
  import os
4
 
5
- # Initialize TTS - auto_download=True handles the HF model fetching automatically
6
  tts = TTS(auto_download=True)
7
 
8
- # List of available voices based on the repository structure
9
  VOICES = ["M1", "M2", "M3", "M4", "M5", "F1", "F2", "F3", "F4", "F5"]
10
-
11
- # List of supported languages (Top 10 shown, you can add all 31)
12
  LANGUAGES = {
13
  "English": "en", "Korean": "ko", "Japanese": "ja", "Spanish": "es",
14
- "French": "fr", "German": "de", "Hindi": "hi", "Italian": "it",
15
- "Portuguese": "pt", "Russian": "ru", "Vietnamese": "vi"
16
  }
17
 
18
  def generate_speech(text, voice, language_name):
19
  lang_code = LANGUAGES[language_name]
20
-
21
- # Get the voice style object
22
  style = tts.get_voice_style(voice_name=voice)
23
-
24
- # Synthesize
25
  wav, duration = tts.synthesize(text, voice_style=style, lang=lang_code)
26
 
27
- # Save to a temporary path for Gradio to pick up
28
  output_path = "output.wav"
29
  tts.save_audio(wav, output_path)
30
-
31
- return output_path, f"Duration: {duration:.2f} seconds"
32
 
33
- # Define the Gradio Interface
34
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
35
- gr.Markdown("# 🎙️ Supertonic 3 TTS (On-Device CPU)")
36
- gr.Markdown("Lightning-fast multilingual TTS by Supertone. Running entirely on CPU via ONNX.")
37
 
38
  with gr.Row():
39
- with gr.Column():
40
  input_text = gr.Textbox(
41
  label="Input Text",
42
- placeholder="Type something here...",
43
- value="Hello! Supertonic 3 is now running on a Hugging Face CPU Space.",
44
  lines=3
45
  )
46
- voice_opt = gr.Dropdown(choices=VOICES, value="M1", label="Voice Style")
47
- lang_opt = gr.Dropdown(choices=list(LANGUAGES.keys()), value="English", label="Language")
48
- btn = gr.Button("Generate Audio", variant="primary")
 
49
 
50
- with gr.Column():
51
- audio_output = gr.Audio(label="Synthesized Audio", type="filepath")
52
- stats = gr.Label(label="Metadata")
53
-
54
- gr.Examples(
55
- examples=[
56
- ["The train delay was announced at 4:45 PM <breath> due to track maintenance.", "M1", "English"],
57
- ["こんにちは、スーパートーンの世界へようこそ。", "F1", "Japanese"],
58
- ["¡Hola! Este es un ejemplo de síntesis de voz en español.", "M2", "Spanish"]
59
- ],
60
- inputs=[input_text, voice_opt, lang_opt]
61
  )
62
 
63
- btn.click(generate_speech, inputs=[input_text, voice_opt, lang_opt], outputs=[audio_output, stats])
64
-
65
  if __name__ == "__main__":
66
  demo.launch()
67
-
 
2
  from supertonic import TTS
3
  import os
4
 
5
+ # Initialize TTS
6
  tts = TTS(auto_download=True)
7
 
 
8
  VOICES = ["M1", "M2", "M3", "M4", "M5", "F1", "F2", "F3", "F4", "F5"]
 
 
9
  LANGUAGES = {
10
  "English": "en", "Korean": "ko", "Japanese": "ja", "Spanish": "es",
11
+ "French": "fr", "German": "de", "Hindi": "hi", "Italian": "it"
 
12
  }
13
 
14
  def generate_speech(text, voice, language_name):
15
  lang_code = LANGUAGES[language_name]
 
 
16
  style = tts.get_voice_style(voice_name=voice)
 
 
17
  wav, duration = tts.synthesize(text, voice_style=style, lang=lang_code)
18
 
 
19
  output_path = "output.wav"
20
  tts.save_audio(wav, output_path)
21
+ return output_path, f"Duration: {duration:.2f}s"
 
22
 
23
+ # Gradio 6 focuses on cleaner layout and updated theme handling
24
+ with gr.Blocks(theme='soft', title="Supertonic 3 TTS") as demo:
25
+ gr.Markdown("## 🎙️ Supertonic 3 TTS (Secure & Optimized)")
 
26
 
27
  with gr.Row():
28
+ with gr.Column(scale=1):
29
  input_text = gr.Textbox(
30
  label="Input Text",
31
+ placeholder="Type here...",
32
+ value="Hello! I am now running on a secure version of Gradio.",
33
  lines=3
34
  )
35
+ with gr.Row():
36
+ voice_opt = gr.Dropdown(choices=VOICES, value="M1", label="Voice")
37
+ lang_opt = gr.Dropdown(choices=list(LANGUAGES.keys()), value="English", label="Language")
38
+ btn = gr.Button("Generate", variant="primary")
39
 
40
+ with gr.Column(scale=1):
41
+ audio_output = gr.Audio(label="Result", type="filepath")
42
+ stats = gr.Textbox(label="Metadata", interactive=False)
43
+
44
+ btn.click(
45
+ fn=generate_speech,
46
+ inputs=[input_text, voice_opt, lang_opt],
47
+ outputs=[audio_output, stats]
 
 
 
48
  )
49
 
 
 
50
  if __name__ == "__main__":
51
  demo.launch()