Spaces:
Running on Zero
Running on Zero
File size: 2,579 Bytes
e791b3f | 1 2 3 4 5 6 7 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import gradio as gr
from supertonic import TTS
import os
# Initialize TTS - auto_download=True handles the HF model fetching automatically
tts = TTS(auto_download=True)
# List of available voices based on the repository structure
VOICES = ["M1", "M2", "M3", "M4", "M5", "F1", "F2", "F3", "F4", "F5"]
# List of supported languages (Top 10 shown, you can add all 31)
LANGUAGES = {
"English": "en", "Korean": "ko", "Japanese": "ja", "Spanish": "es",
"French": "fr", "German": "de", "Hindi": "hi", "Italian": "it",
"Portuguese": "pt", "Russian": "ru", "Vietnamese": "vi"
}
def generate_speech(text, voice, language_name):
lang_code = LANGUAGES[language_name]
# Get the voice style object
style = tts.get_voice_style(voice_name=voice)
# Synthesize
wav, duration = tts.synthesize(text, voice_style=style, lang=lang_code)
# Save to a temporary path for Gradio to pick up
output_path = "output.wav"
tts.save_audio(wav, output_path)
return output_path, f"Duration: {duration:.2f} seconds"
# Define the Gradio Interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🎙️ Supertonic 3 TTS (On-Device CPU)")
gr.Markdown("Lightning-fast multilingual TTS by Supertone. Running entirely on CPU via ONNX.")
with gr.Row():
with gr.Column():
input_text = gr.Textbox(
label="Input Text",
placeholder="Type something here...",
value="Hello! Supertonic 3 is now running on a Hugging Face CPU Space.",
lines=3
)
voice_opt = gr.Dropdown(choices=VOICES, value="M1", label="Voice Style")
lang_opt = gr.Dropdown(choices=list(LANGUAGES.keys()), value="English", label="Language")
btn = gr.Button("Generate Audio", variant="primary")
with gr.Column():
audio_output = gr.Audio(label="Synthesized Audio", type="filepath")
stats = gr.Label(label="Metadata")
gr.Examples(
examples=[
["The train delay was announced at 4:45 PM <breath> due to track maintenance.", "M1", "English"],
["こんにちは、スーパートーンの世界へようこそ。", "F1", "Japanese"],
["¡Hola! Este es un ejemplo de síntesis de voz en español.", "M2", "Spanish"]
],
inputs=[input_text, voice_opt, lang_opt]
)
btn.click(generate_speech, inputs=[input_text, voice_opt, lang_opt], outputs=[audio_output, stats])
if __name__ == "__main__":
demo.launch()
|