feat: Supertonic 3 TTS demo locale
- Demo Gradio con interfaccia web (B) - Server HTTP con API nativa e OpenAI-compatibile (C) - 31 lingue, italiano incluso - 99M parametri, CPU-only, ONNX Runtime
This commit is contained in:
commit
770843f9c0
5 files changed
+216
No files matched your search
@@ -0,0 +1,9 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
outputs/
|
||||
*.wav
|
||||
*.mp3
|
||||
.env
|
||||
.DS_Store
|
||||
.firecrawl/
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,70 @@
|
||||
# Supertonic 3 — Demo Locale
|
||||
|
||||
Demo locale di **Supertonic 3**, un motore TTS on-device da ~99M parametri con supporto a **31 lingue** (italiano incluso). Gira su **CPU**, senza GPU.
|
||||
|
||||
## Servizi
|
||||
|
||||
| Servizio | Porta | Descrizione |
|
||||
|---|---|---|
|
||||
| Demo Gradio | `0.0.0.0:7860` | Interfaccia web per test rapidi |
|
||||
| Server HTTP | `0.0.0.0:7788` | API REST + endpoint OpenAI-compatibile |
|
||||
|
||||
## Avvio rapido
|
||||
|
||||
```bash
|
||||
source .venv/bin/activate
|
||||
ORT_DISABLE_CPU_THREAD_AFFINITY=1
|
||||
|
||||
# Demo Gradio (B)
|
||||
python app.py
|
||||
|
||||
# Server HTTP (C)
|
||||
supertonic serve --host 0.0.0.0 --port 7788
|
||||
```
|
||||
|
||||
## Screenshot
|
||||
|
||||
Apri http://localhost:7860 per l'interfaccia Gradio o http://localhost:7788/docs per la documentazione API.
|
||||
|
||||
## API HTTP
|
||||
|
||||
**Endpoint OpenAI-compatibile:**
|
||||
```bash
|
||||
curl -X POST http://localhost:7788/v1/audio/speech \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "supertonic-3", "input": "Ciao mondo!", "voice": "M1"}' \
|
||||
-o output.wav
|
||||
```
|
||||
|
||||
**Endpoint nativo:**
|
||||
```bash
|
||||
curl -X POST http://localhost:7788/v1/tts \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"text": "Ciao mondo!", "lang": "it", "voice_style": "M1"}' \
|
||||
-o output.wav
|
||||
```
|
||||
|
||||
## Lingue supportate (31)
|
||||
|
||||
Arabo, Bulgaro, Croato, Ceco, Danese, Olandese, Inglese, Estone, Finlandese, Francese, Tedesco, Greco, Hindi, Ungherese, Indonesiano, **Italiano**, Giapponese, Coreano, Lettone, Lituano, Polacco, Portoghese, Rumeno, Russo, Slovacco, Sloveno, Spagnolo, Svedese, Turco, Ucraino, Vietnamita
|
||||
|
||||
Usa `lang="na"` per modalità language-agnostic.
|
||||
|
||||
## Voci preset
|
||||
|
||||
Maschili: M1–M5 · Femminili: F1–F5
|
||||
|
||||
## Installazione
|
||||
|
||||
```bash
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install supertonic gradio
|
||||
# Per il server HTTP:
|
||||
pip install 'supertonic[serve]'
|
||||
```
|
||||
|
||||
## Crediti
|
||||
|
||||
- Modello: [Supertone Inc.](https://github.com/supertone-inc/supertonic) (MIT + OpenRAIL-M)
|
||||
- Demo originale: [Francesco Gruner](https://francescogruner.it/supertonic-tts-voce-ai-italiano-windows/)
|
||||
@@ -0,0 +1,87 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import gradio as gr
|
||||
from supertonic import TTS
|
||||
|
||||
OUTPUT_DIR = "outputs"
|
||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||
|
||||
# The first run downloads the Supertonic model assets automatically.
|
||||
tts = TTS(auto_download=True)
|
||||
|
||||
SUPPORTED_LANGUAGES = {
|
||||
"Italiano": "it",
|
||||
"Inglese": "en",
|
||||
"Spagnolo": "es",
|
||||
"Francese": "fr",
|
||||
"Tedesco": "de",
|
||||
"Portoghese": "pt",
|
||||
}
|
||||
|
||||
VOICES = ["M1", "M2", "M3", "M4", "M5", "F1", "F2", "F3", "F4", "F5"]
|
||||
|
||||
|
||||
def generate_audio(text: str, language_label: str, voice: str):
|
||||
"""Generate a local WAV file with Supertonic TTS."""
|
||||
if not text or not text.strip():
|
||||
return None, "Inserisci un testo prima di generare l'audio."
|
||||
|
||||
lang = SUPPORTED_LANGUAGES.get(language_label, "it")
|
||||
style = tts.get_voice_style(voice)
|
||||
|
||||
wav, _duration = tts.synthesize(
|
||||
text.strip(),
|
||||
voice_style=style,
|
||||
lang=lang,
|
||||
)
|
||||
|
||||
output_path = os.path.join(OUTPUT_DIR, f"supertonic_{uuid.uuid4().hex[:8]}.wav")
|
||||
tts.save_audio(wav, output_path)
|
||||
|
||||
return output_path, f"Audio generato correttamente: {output_path}"
|
||||
|
||||
|
||||
with gr.Blocks(title="Supertonic Local Demo") as demo:
|
||||
gr.Markdown(
|
||||
"""
|
||||
# Supertonic Local Demo
|
||||
|
||||
Mini pannello locale per generare audio con Supertonic TTS.
|
||||
|
||||
Scrivi un testo, scegli lingua e voce, poi genera un file WAV direttamente sul tuo PC.
|
||||
"""
|
||||
)
|
||||
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
text_input = gr.Textbox(
|
||||
label="Testo",
|
||||
lines=8,
|
||||
value="Ciao, questo è un test vocale in italiano generato localmente con Supertonic.",
|
||||
)
|
||||
language_input = gr.Dropdown(
|
||||
choices=list(SUPPORTED_LANGUAGES.keys()),
|
||||
value="Italiano",
|
||||
label="Lingua",
|
||||
)
|
||||
voice_input = gr.Dropdown(
|
||||
choices=VOICES,
|
||||
value="M1",
|
||||
label="Voce",
|
||||
)
|
||||
generate_button = gr.Button("Genera audio")
|
||||
|
||||
with gr.Column():
|
||||
audio_output = gr.Audio(label="Audio generato", type="filepath")
|
||||
status_output = gr.Textbox(label="Stato")
|
||||
|
||||
generate_button.click(
|
||||
fn=generate_audio,
|
||||
inputs=[text_input, language_input, voice_input],
|
||||
outputs=[audio_output, status_output],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.launch(server_name="0.0.0.0")
|
||||
@@ -0,0 +1,2 @@
|
||||
supertonic
|
||||
gradio
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$DIR"
|
||||
|
||||
# Activate virtual environment
|
||||
source .venv/bin/activate
|
||||
|
||||
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Supertonic 3 — Avvio Servizi ║"
|
||||
echo "╠══════════════════════════════════════════════════════════════╣"
|
||||
echo "║ ║"
|
||||
echo "║ [B] Demo Gradio: http://127.0.0.1:7860 ║"
|
||||
echo "║ [C] Server HTTP: http://127.0.0.1:7788/docs ║"
|
||||
echo "║ ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
|
||||
# Export vars to suppress ONNX affinity warnings (harmless in containers)
|
||||
export ORT_DISABLE_CPU_THREAD_AFFINITY=1
|
||||
|
||||
# Start HTTP server in background (C)
|
||||
echo "→ Avvio server HTTP (supertonic serve) sulla porta 7788..."
|
||||
supertonic serve --host 127.0.0.1 --port 7788 &
|
||||
HTTP_PID=$!
|
||||
|
||||
# Start Gradio demo in background (B)
|
||||
echo "→ Avvio demo Gradio sulla porta 7860..."
|
||||
python app.py &
|
||||
GRADIO_PID=$!
|
||||
|
||||
echo ""
|
||||
echo "Premi Ctrl+C per fermare entrambi i servizi."
|
||||
echo ""
|
||||
|
||||
# Trap to kill both on exit
|
||||
cleanup() {
|
||||
echo ""
|
||||
echo "→ Fermo servizi..."
|
||||
kill "$HTTP_PID" "$GRADIO_PID" 2>/dev/null
|
||||
wait
|
||||
echo "✓ Servizi fermati."
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
# Wait for both
|
||||
wait
|
||||
Reference in new issue
Block a user