Spaces:
Running
Running
Commit ·
700c192
0
Parent(s):
Initial commit
Browse files- .gitignore +3 -0
- README.md +56 -0
- index.html +40 -0
- pyproject.toml +30 -0
- reachy_pocket_tts_demo/__init__.py +0 -0
- reachy_pocket_tts_demo/main.py +212 -0
- reachy_pocket_tts_demo/speech_tapper.py +252 -0
- reachy_pocket_tts_demo/static/index.html +51 -0
- reachy_pocket_tts_demo/static/main.js +119 -0
- reachy_pocket_tts_demo/static/style.css +156 -0
- reachy_pocket_tts_demo/tts.py +92 -0
- style.css +411 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.egg-info/
|
| 3 |
+
build/
|
README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Reachy Pocket TTS Demo
|
| 3 |
+
emoji: 🗣️
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: static
|
| 7 |
+
pinned: false
|
| 8 |
+
short_description: Text-to-speech with head wobble using pocket-tts
|
| 9 |
+
tags:
|
| 10 |
+
- reachy_mini
|
| 11 |
+
- reachy_mini_python_app
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Pocket TTS Demo
|
| 15 |
+
|
| 16 |
+
A Reachy Mini app that uses [pocket-tts](https://github.com/kyutai-labs/pocket-tts) for local text-to-speech with audio-reactive head wobble animation.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- **Local TTS inference** using pocket-tts (no cloud API required)
|
| 21 |
+
- **Audio-reactive head wobble** synchronized with speech
|
| 22 |
+
- **Performance metrics** display (inference time, real-time factor)
|
| 23 |
+
- **Web UI** for text input
|
| 24 |
+
|
| 25 |
+
## Installation
|
| 26 |
+
|
| 27 |
+
```bash
|
| 28 |
+
pip install -e .
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
Or with uv:
|
| 32 |
+
```bash
|
| 33 |
+
uv pip install -e .
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
Run the app:
|
| 39 |
+
```bash
|
| 40 |
+
python -m reachy_pocket_tts_demo.main
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Then open `http://localhost:8042` in your browser to access the web UI.
|
| 44 |
+
|
| 45 |
+
## How it Works
|
| 46 |
+
|
| 47 |
+
1. Enter text in the web interface
|
| 48 |
+
2. pocket-tts generates audio locally
|
| 49 |
+
3. Audio plays through the robot's speaker
|
| 50 |
+
4. Head wobbles reactively based on audio amplitude (using VAD and loudness detection)
|
| 51 |
+
|
| 52 |
+
## Performance
|
| 53 |
+
|
| 54 |
+
pocket-tts runs on CPU. Performance varies by hardware:
|
| 55 |
+
- MacBook Air M4: ~6x real-time
|
| 56 |
+
- Raspberry Pi CM4: TBD (this app is designed to test this)
|
index.html
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html>
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="utf-8" />
|
| 6 |
+
<meta name="viewport" content="width=device-width" />
|
| 7 |
+
<title> Reachy Pocket Tts Demo </title>
|
| 8 |
+
<link rel="stylesheet" href="style.css" />
|
| 9 |
+
</head>
|
| 10 |
+
|
| 11 |
+
<body>
|
| 12 |
+
<div class="hero">
|
| 13 |
+
<div class="hero-content">
|
| 14 |
+
<div class="app-icon">🤖⚡</div>
|
| 15 |
+
<h1> Reachy Pocket Tts Demo </h1>
|
| 16 |
+
<p class="tagline">Enter your tagline here</p>
|
| 17 |
+
</div>
|
| 18 |
+
</div>
|
| 19 |
+
|
| 20 |
+
<div class="container">
|
| 21 |
+
<div class="main-card">
|
| 22 |
+
<div class="app-preview">
|
| 23 |
+
<div class="preview-image">
|
| 24 |
+
<div class="camera-feed">🛠️</div>
|
| 25 |
+
</div>
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
|
| 30 |
+
<div class="footer">
|
| 31 |
+
<p>
|
| 32 |
+
🤖 Reachy Pocket Tts Demo •
|
| 33 |
+
<a href="https://github.com/pollen-robotics" target="_blank">Pollen Robotics</a> •
|
| 34 |
+
<a href="https://huggingface.co/spaces/pollen-robotics/reachy-mini-landing-page#apps" target="_blank">Browse More
|
| 35 |
+
Apps</a>
|
| 36 |
+
</p>
|
| 37 |
+
</div>
|
| 38 |
+
</body>
|
| 39 |
+
|
| 40 |
+
</html>
|
pyproject.toml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["setuptools>=61.0"]
|
| 3 |
+
build-backend = "setuptools.build_meta"
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
[project]
|
| 7 |
+
name = "reachy_pocket_tts_demo"
|
| 8 |
+
version = "0.1.0"
|
| 9 |
+
description = "Text-to-speech demo using pocket-tts with head wobble animation"
|
| 10 |
+
readme = "README.md"
|
| 11 |
+
requires-python = ">=3.10"
|
| 12 |
+
dependencies = [
|
| 13 |
+
"reachy-mini",
|
| 14 |
+
"pocket-tts",
|
| 15 |
+
"sounddevice",
|
| 16 |
+
]
|
| 17 |
+
keywords = ["reachy-mini-app"]
|
| 18 |
+
|
| 19 |
+
[project.entry-points."reachy_mini_apps"]
|
| 20 |
+
reachy_pocket_tts_demo = "reachy_pocket_tts_demo.main:ReachyPocketTtsDemo"
|
| 21 |
+
|
| 22 |
+
[tool.setuptools]
|
| 23 |
+
package-dir = { "" = "." }
|
| 24 |
+
include-package-data = true
|
| 25 |
+
|
| 26 |
+
[tool.setuptools.packages.find]
|
| 27 |
+
where = ["."]
|
| 28 |
+
|
| 29 |
+
[tool.setuptools.package-data]
|
| 30 |
+
reachy_pocket_tts_demo = ["**/*"] # Also include all non-.py files
|
reachy_pocket_tts_demo/__init__.py
ADDED
|
File without changes
|
reachy_pocket_tts_demo/main.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pocket TTS Demo - Text-to-speech with head wobble animation.
|
| 2 |
+
|
| 3 |
+
This app demonstrates using pocket-tts for local TTS inference
|
| 4 |
+
with audio-reactive head movement on Reachy Mini.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
import logging
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import sounddevice as sd
|
| 13 |
+
from pydantic import BaseModel
|
| 14 |
+
|
| 15 |
+
from reachy_mini import ReachyMini, ReachyMiniApp
|
| 16 |
+
from reachy_mini.utils import create_head_pose
|
| 17 |
+
|
| 18 |
+
from .tts import TTSEngine, TTSMetrics
|
| 19 |
+
from .speech_tapper import SwayRollRT, HOP_MS
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class SpeakRequest(BaseModel):
|
| 25 |
+
text: str
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class StatusResponse(BaseModel):
|
| 29 |
+
status: str
|
| 30 |
+
model_loaded: bool
|
| 31 |
+
model_load_time: float
|
| 32 |
+
voice_load_time: float
|
| 33 |
+
last_inference_time: float
|
| 34 |
+
last_audio_duration: float
|
| 35 |
+
last_realtime_factor: float
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class ReachyPocketTtsDemo(ReachyMiniApp):
|
| 39 |
+
custom_app_url: str | None = "http://0.0.0.0:8042"
|
| 40 |
+
request_media_backend: str | None = None
|
| 41 |
+
|
| 42 |
+
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 43 |
+
# State
|
| 44 |
+
tts_engine = TTSEngine(voice="jean")
|
| 45 |
+
sway = SwayRollRT()
|
| 46 |
+
|
| 47 |
+
current_status = "loading"
|
| 48 |
+
is_speaking = False
|
| 49 |
+
speech_offsets = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
|
| 50 |
+
speech_offsets_lock = threading.Lock()
|
| 51 |
+
speak_queue: list[str] = []
|
| 52 |
+
speak_queue_lock = threading.Lock()
|
| 53 |
+
|
| 54 |
+
# Load TTS model in background
|
| 55 |
+
def load_model():
|
| 56 |
+
nonlocal current_status
|
| 57 |
+
try:
|
| 58 |
+
tts_engine.load()
|
| 59 |
+
current_status = "ready"
|
| 60 |
+
logger.info("TTS model ready")
|
| 61 |
+
except Exception as e:
|
| 62 |
+
current_status = f"error: {e}"
|
| 63 |
+
logger.error(f"Failed to load TTS model: {e}")
|
| 64 |
+
|
| 65 |
+
load_thread = threading.Thread(target=load_model, daemon=True)
|
| 66 |
+
load_thread.start()
|
| 67 |
+
|
| 68 |
+
# API endpoints
|
| 69 |
+
@self.settings_app.post("/speak")
|
| 70 |
+
def speak(request: SpeakRequest):
|
| 71 |
+
if not tts_engine.is_loaded():
|
| 72 |
+
return {"error": "Model still loading", "status": current_status}
|
| 73 |
+
with speak_queue_lock:
|
| 74 |
+
speak_queue.append(request.text)
|
| 75 |
+
return {"queued": True, "text": request.text}
|
| 76 |
+
|
| 77 |
+
@self.settings_app.get("/status")
|
| 78 |
+
def get_status():
|
| 79 |
+
return StatusResponse(
|
| 80 |
+
status=current_status,
|
| 81 |
+
model_loaded=tts_engine.is_loaded(),
|
| 82 |
+
model_load_time=tts_engine.metrics.model_load_time,
|
| 83 |
+
voice_load_time=tts_engine.metrics.voice_load_time,
|
| 84 |
+
last_inference_time=tts_engine.metrics.inference_time,
|
| 85 |
+
last_audio_duration=tts_engine.metrics.audio_duration,
|
| 86 |
+
last_realtime_factor=tts_engine.metrics.realtime_factor,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
def speak_with_wobble(text: str):
|
| 90 |
+
"""Generate audio and play with head wobble."""
|
| 91 |
+
nonlocal is_speaking, current_status, speech_offsets
|
| 92 |
+
|
| 93 |
+
is_speaking = True
|
| 94 |
+
current_status = "generating"
|
| 95 |
+
sway.reset()
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
# Generate audio
|
| 99 |
+
audio, metrics = tts_engine.generate(text)
|
| 100 |
+
sample_rate = tts_engine.sample_rate
|
| 101 |
+
|
| 102 |
+
current_status = "speaking"
|
| 103 |
+
|
| 104 |
+
# Compute all sway offsets from the audio
|
| 105 |
+
sway_results = sway.feed(audio, sample_rate)
|
| 106 |
+
|
| 107 |
+
# Start audio playback
|
| 108 |
+
sd.play(audio, sample_rate)
|
| 109 |
+
|
| 110 |
+
# Apply wobble offsets in sync with audio
|
| 111 |
+
hop_dt = HOP_MS / 1000.0
|
| 112 |
+
t0 = time.monotonic()
|
| 113 |
+
|
| 114 |
+
for i, r in enumerate(sway_results):
|
| 115 |
+
# Wait for the right time to apply this offset
|
| 116 |
+
target_time = t0 + i * hop_dt
|
| 117 |
+
now = time.monotonic()
|
| 118 |
+
if target_time > now:
|
| 119 |
+
time.sleep(target_time - now)
|
| 120 |
+
|
| 121 |
+
# Update speech offsets (will be applied in main loop)
|
| 122 |
+
with speech_offsets_lock:
|
| 123 |
+
speech_offsets = (
|
| 124 |
+
r["x_mm"] / 1000.0,
|
| 125 |
+
r["y_mm"] / 1000.0,
|
| 126 |
+
r["z_mm"] / 1000.0,
|
| 127 |
+
r["roll_rad"],
|
| 128 |
+
r["pitch_rad"],
|
| 129 |
+
r["yaw_rad"],
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
if stop_event.is_set():
|
| 133 |
+
sd.stop()
|
| 134 |
+
break
|
| 135 |
+
|
| 136 |
+
# Wait for audio to finish
|
| 137 |
+
sd.wait()
|
| 138 |
+
|
| 139 |
+
# Fade out wobble
|
| 140 |
+
fade_steps = 10
|
| 141 |
+
with speech_offsets_lock:
|
| 142 |
+
current = speech_offsets
|
| 143 |
+
for i in range(fade_steps):
|
| 144 |
+
factor = 1.0 - (i + 1) / fade_steps
|
| 145 |
+
with speech_offsets_lock:
|
| 146 |
+
speech_offsets = tuple(v * factor for v in current)
|
| 147 |
+
time.sleep(0.02)
|
| 148 |
+
|
| 149 |
+
with speech_offsets_lock:
|
| 150 |
+
speech_offsets = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
|
| 151 |
+
|
| 152 |
+
except Exception as e:
|
| 153 |
+
logger.error(f"Error during speech: {e}")
|
| 154 |
+
current_status = f"error: {e}"
|
| 155 |
+
finally:
|
| 156 |
+
is_speaking = False
|
| 157 |
+
current_status = "ready"
|
| 158 |
+
|
| 159 |
+
# Main control loop
|
| 160 |
+
while not stop_event.is_set():
|
| 161 |
+
# Check for queued speech
|
| 162 |
+
text_to_speak = None
|
| 163 |
+
with speak_queue_lock:
|
| 164 |
+
if speak_queue and not is_speaking:
|
| 165 |
+
text_to_speak = speak_queue.pop(0)
|
| 166 |
+
|
| 167 |
+
if text_to_speak:
|
| 168 |
+
# Run speech in a separate thread so we can keep the control loop running
|
| 169 |
+
speech_thread = threading.Thread(
|
| 170 |
+
target=speak_with_wobble,
|
| 171 |
+
args=(text_to_speak,),
|
| 172 |
+
daemon=True
|
| 173 |
+
)
|
| 174 |
+
speech_thread.start()
|
| 175 |
+
|
| 176 |
+
# Get current speech offsets
|
| 177 |
+
with speech_offsets_lock:
|
| 178 |
+
x_off, y_off, z_off, roll_off, pitch_off, yaw_off = speech_offsets
|
| 179 |
+
|
| 180 |
+
# Create head pose with speech offsets
|
| 181 |
+
if is_speaking:
|
| 182 |
+
# Apply wobble offsets
|
| 183 |
+
head_pose = create_head_pose(
|
| 184 |
+
x=x_off,
|
| 185 |
+
y=y_off,
|
| 186 |
+
z=z_off,
|
| 187 |
+
roll=roll_off,
|
| 188 |
+
pitch=pitch_off,
|
| 189 |
+
yaw=yaw_off,
|
| 190 |
+
degrees=False,
|
| 191 |
+
mm=False,
|
| 192 |
+
)
|
| 193 |
+
else:
|
| 194 |
+
# Idle: neutral pose
|
| 195 |
+
head_pose = create_head_pose(0, 0, 0, 0, 0, 0, degrees=True)
|
| 196 |
+
|
| 197 |
+
# Send to robot
|
| 198 |
+
reachy_mini.set_target(
|
| 199 |
+
head=head_pose,
|
| 200 |
+
antennas=[0.0, 0.0],
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
time.sleep(0.01) # 100Hz control loop
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
if __name__ == "__main__":
|
| 207 |
+
logging.basicConfig(level=logging.INFO)
|
| 208 |
+
app = ReachyPocketTtsDemo()
|
| 209 |
+
try:
|
| 210 |
+
app.wrapped_run()
|
| 211 |
+
except KeyboardInterrupt:
|
| 212 |
+
app.stop()
|
reachy_pocket_tts_demo/speech_tapper.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Audio-reactive head sway generator.
|
| 2 |
+
|
| 3 |
+
Adapted from reachy_mini_conversation_app to generate head wobble offsets
|
| 4 |
+
based on audio amplitude and voice activity detection.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
import math
|
| 9 |
+
from typing import Any, Dict, List
|
| 10 |
+
from itertools import islice
|
| 11 |
+
from collections import deque
|
| 12 |
+
|
| 13 |
+
import numpy as np
|
| 14 |
+
from numpy.typing import NDArray
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Tunables - these match the conversation app's wobble parameters
|
| 18 |
+
SR = 16_000
|
| 19 |
+
FRAME_MS = 20
|
| 20 |
+
HOP_MS = 50
|
| 21 |
+
|
| 22 |
+
SWAY_MASTER = 1.5
|
| 23 |
+
SENS_DB_OFFSET = +4.0
|
| 24 |
+
VAD_DB_ON = -35.0
|
| 25 |
+
VAD_DB_OFF = -45.0
|
| 26 |
+
VAD_ATTACK_MS = 40
|
| 27 |
+
VAD_RELEASE_MS = 250
|
| 28 |
+
ENV_FOLLOW_GAIN = 0.65
|
| 29 |
+
|
| 30 |
+
SWAY_F_PITCH = 2.2
|
| 31 |
+
SWAY_A_PITCH_DEG = 4.5
|
| 32 |
+
SWAY_F_YAW = 0.6
|
| 33 |
+
SWAY_A_YAW_DEG = 7.5
|
| 34 |
+
SWAY_F_ROLL = 1.3
|
| 35 |
+
SWAY_A_ROLL_DEG = 2.25
|
| 36 |
+
SWAY_F_X = 0.35
|
| 37 |
+
SWAY_A_X_MM = 4.5
|
| 38 |
+
SWAY_F_Y = 0.45
|
| 39 |
+
SWAY_A_Y_MM = 3.75
|
| 40 |
+
SWAY_F_Z = 0.25
|
| 41 |
+
SWAY_A_Z_MM = 2.25
|
| 42 |
+
|
| 43 |
+
SWAY_DB_LOW = -46.0
|
| 44 |
+
SWAY_DB_HIGH = -18.0
|
| 45 |
+
LOUDNESS_GAMMA = 0.9
|
| 46 |
+
SWAY_ATTACK_MS = 50
|
| 47 |
+
SWAY_RELEASE_MS = 250
|
| 48 |
+
|
| 49 |
+
# Derived
|
| 50 |
+
FRAME = int(SR * FRAME_MS / 1000)
|
| 51 |
+
HOP = int(SR * HOP_MS / 1000)
|
| 52 |
+
ATTACK_FR = max(1, int(VAD_ATTACK_MS / HOP_MS))
|
| 53 |
+
RELEASE_FR = max(1, int(VAD_RELEASE_MS / HOP_MS))
|
| 54 |
+
SWAY_ATTACK_FR = max(1, int(SWAY_ATTACK_MS / HOP_MS))
|
| 55 |
+
SWAY_RELEASE_FR = max(1, int(SWAY_RELEASE_MS / HOP_MS))
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _rms_dbfs(x: NDArray[np.float32]) -> float:
|
| 59 |
+
"""Root-mean-square in dBFS for float32 mono array in [-1,1]."""
|
| 60 |
+
x = x.astype(np.float32, copy=False)
|
| 61 |
+
rms = np.sqrt(np.mean(x * x, dtype=np.float32) + 1e-12, dtype=np.float32)
|
| 62 |
+
return float(20.0 * math.log10(float(rms) + 1e-12))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _loudness_gain(db: float, offset: float = SENS_DB_OFFSET) -> float:
|
| 66 |
+
"""Normalize dB into [0,1] with gamma; clipped to [0,1]."""
|
| 67 |
+
t = (db + offset - SWAY_DB_LOW) / (SWAY_DB_HIGH - SWAY_DB_LOW)
|
| 68 |
+
if t < 0.0:
|
| 69 |
+
t = 0.0
|
| 70 |
+
elif t > 1.0:
|
| 71 |
+
t = 1.0
|
| 72 |
+
return t**LOUDNESS_GAMMA if LOUDNESS_GAMMA != 1.0 else t
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _to_float32_mono(x: NDArray[Any]) -> NDArray[np.float32]:
|
| 76 |
+
"""Convert arbitrary PCM array to float32 mono in [-1,1]."""
|
| 77 |
+
a = np.asarray(x)
|
| 78 |
+
if a.ndim == 0:
|
| 79 |
+
return np.zeros(0, dtype=np.float32)
|
| 80 |
+
|
| 81 |
+
if a.ndim == 2:
|
| 82 |
+
if a.shape[0] <= 8 and a.shape[0] <= a.shape[1]:
|
| 83 |
+
a = np.mean(a, axis=0)
|
| 84 |
+
else:
|
| 85 |
+
a = np.mean(a, axis=1)
|
| 86 |
+
elif a.ndim > 2:
|
| 87 |
+
a = np.mean(a.reshape(a.shape[0], -1), axis=0)
|
| 88 |
+
|
| 89 |
+
if np.issubdtype(a.dtype, np.floating):
|
| 90 |
+
return a.astype(np.float32, copy=False)
|
| 91 |
+
info = np.iinfo(a.dtype)
|
| 92 |
+
scale = float(max(-info.min, info.max))
|
| 93 |
+
return a.astype(np.float32) / (scale if scale != 0.0 else 1.0)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def _resample_linear(x: NDArray[np.float32], sr_in: int, sr_out: int) -> NDArray[np.float32]:
|
| 97 |
+
"""Lightweight linear resampler for short buffers."""
|
| 98 |
+
if sr_in == sr_out or x.size == 0:
|
| 99 |
+
return x
|
| 100 |
+
n_out = int(round(x.size * sr_out / sr_in))
|
| 101 |
+
if n_out <= 1:
|
| 102 |
+
return np.zeros(0, dtype=np.float32)
|
| 103 |
+
t_in = np.linspace(0.0, 1.0, num=x.size, dtype=np.float32, endpoint=True)
|
| 104 |
+
t_out = np.linspace(0.0, 1.0, num=n_out, dtype=np.float32, endpoint=True)
|
| 105 |
+
return np.interp(t_out, t_in, x).astype(np.float32, copy=False)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class SwayRollRT:
|
| 109 |
+
"""Feed audio chunks -> per-hop sway outputs.
|
| 110 |
+
|
| 111 |
+
Usage:
|
| 112 |
+
rt = SwayRollRT()
|
| 113 |
+
results = rt.feed(pcm_int16_or_float, sr) -> List[dict]
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
def __init__(self, rng_seed: int = 7):
|
| 117 |
+
"""Initialize state."""
|
| 118 |
+
self._seed = int(rng_seed)
|
| 119 |
+
self.samples: deque[float] = deque(maxlen=10 * SR)
|
| 120 |
+
self.carry: NDArray[np.float32] = np.zeros(0, dtype=np.float32)
|
| 121 |
+
|
| 122 |
+
self.vad_on = False
|
| 123 |
+
self.vad_above = 0
|
| 124 |
+
self.vad_below = 0
|
| 125 |
+
|
| 126 |
+
self.sway_env = 0.0
|
| 127 |
+
self.sway_up = 0
|
| 128 |
+
self.sway_down = 0
|
| 129 |
+
|
| 130 |
+
rng = np.random.default_rng(self._seed)
|
| 131 |
+
self.phase_pitch = float(rng.random() * 2 * math.pi)
|
| 132 |
+
self.phase_yaw = float(rng.random() * 2 * math.pi)
|
| 133 |
+
self.phase_roll = float(rng.random() * 2 * math.pi)
|
| 134 |
+
self.phase_x = float(rng.random() * 2 * math.pi)
|
| 135 |
+
self.phase_y = float(rng.random() * 2 * math.pi)
|
| 136 |
+
self.phase_z = float(rng.random() * 2 * math.pi)
|
| 137 |
+
self.t = 0.0
|
| 138 |
+
|
| 139 |
+
def reset(self) -> None:
|
| 140 |
+
"""Reset state but keep initial phases/seed."""
|
| 141 |
+
self.samples.clear()
|
| 142 |
+
self.carry = np.zeros(0, dtype=np.float32)
|
| 143 |
+
self.vad_on = False
|
| 144 |
+
self.vad_above = 0
|
| 145 |
+
self.vad_below = 0
|
| 146 |
+
self.sway_env = 0.0
|
| 147 |
+
self.sway_up = 0
|
| 148 |
+
self.sway_down = 0
|
| 149 |
+
self.t = 0.0
|
| 150 |
+
|
| 151 |
+
def feed(self, pcm: NDArray[Any], sr: int | None) -> List[Dict[str, float]]:
|
| 152 |
+
"""Stream in PCM chunk. Returns a list of sway dicts, one per hop (HOP_MS)."""
|
| 153 |
+
sr_in = SR if sr is None else int(sr)
|
| 154 |
+
x = _to_float32_mono(pcm)
|
| 155 |
+
if x.size == 0:
|
| 156 |
+
return []
|
| 157 |
+
if sr_in != SR:
|
| 158 |
+
x = _resample_linear(x, sr_in, SR)
|
| 159 |
+
if x.size == 0:
|
| 160 |
+
return []
|
| 161 |
+
|
| 162 |
+
if self.carry.size:
|
| 163 |
+
self.carry = np.concatenate([self.carry, x])
|
| 164 |
+
else:
|
| 165 |
+
self.carry = x
|
| 166 |
+
|
| 167 |
+
out: List[Dict[str, float]] = []
|
| 168 |
+
|
| 169 |
+
while self.carry.size >= HOP:
|
| 170 |
+
hop = self.carry[:HOP]
|
| 171 |
+
remaining: NDArray[np.float32] = self.carry[HOP:]
|
| 172 |
+
self.carry = remaining
|
| 173 |
+
|
| 174 |
+
self.samples.extend(hop.tolist())
|
| 175 |
+
if len(self.samples) < FRAME:
|
| 176 |
+
self.t += HOP_MS / 1000.0
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
frame = np.fromiter(
|
| 180 |
+
islice(self.samples, len(self.samples) - FRAME, len(self.samples)),
|
| 181 |
+
dtype=np.float32,
|
| 182 |
+
count=FRAME,
|
| 183 |
+
)
|
| 184 |
+
db = _rms_dbfs(frame)
|
| 185 |
+
|
| 186 |
+
# VAD with hysteresis + attack/release
|
| 187 |
+
if db >= VAD_DB_ON:
|
| 188 |
+
self.vad_above += 1
|
| 189 |
+
self.vad_below = 0
|
| 190 |
+
if not self.vad_on and self.vad_above >= ATTACK_FR:
|
| 191 |
+
self.vad_on = True
|
| 192 |
+
elif db <= VAD_DB_OFF:
|
| 193 |
+
self.vad_below += 1
|
| 194 |
+
self.vad_above = 0
|
| 195 |
+
if self.vad_on and self.vad_below >= RELEASE_FR:
|
| 196 |
+
self.vad_on = False
|
| 197 |
+
|
| 198 |
+
if self.vad_on:
|
| 199 |
+
self.sway_up = min(SWAY_ATTACK_FR, self.sway_up + 1)
|
| 200 |
+
self.sway_down = 0
|
| 201 |
+
else:
|
| 202 |
+
self.sway_down = min(SWAY_RELEASE_FR, self.sway_down + 1)
|
| 203 |
+
self.sway_up = 0
|
| 204 |
+
|
| 205 |
+
up = self.sway_up / SWAY_ATTACK_FR
|
| 206 |
+
down = 1.0 - (self.sway_down / SWAY_RELEASE_FR)
|
| 207 |
+
target = up if self.vad_on else down
|
| 208 |
+
self.sway_env += ENV_FOLLOW_GAIN * (target - self.sway_env)
|
| 209 |
+
if self.sway_env < 0.0:
|
| 210 |
+
self.sway_env = 0.0
|
| 211 |
+
elif self.sway_env > 1.0:
|
| 212 |
+
self.sway_env = 1.0
|
| 213 |
+
|
| 214 |
+
loud = _loudness_gain(db) * SWAY_MASTER
|
| 215 |
+
env = self.sway_env
|
| 216 |
+
self.t += HOP_MS / 1000.0
|
| 217 |
+
|
| 218 |
+
# Oscillators
|
| 219 |
+
pitch = (
|
| 220 |
+
math.radians(SWAY_A_PITCH_DEG)
|
| 221 |
+
* loud
|
| 222 |
+
* env
|
| 223 |
+
* math.sin(2 * math.pi * SWAY_F_PITCH * self.t + self.phase_pitch)
|
| 224 |
+
)
|
| 225 |
+
yaw = (
|
| 226 |
+
math.radians(SWAY_A_YAW_DEG)
|
| 227 |
+
* loud
|
| 228 |
+
* env
|
| 229 |
+
* math.sin(2 * math.pi * SWAY_F_YAW * self.t + self.phase_yaw)
|
| 230 |
+
)
|
| 231 |
+
roll = (
|
| 232 |
+
math.radians(SWAY_A_ROLL_DEG)
|
| 233 |
+
* loud
|
| 234 |
+
* env
|
| 235 |
+
* math.sin(2 * math.pi * SWAY_F_ROLL * self.t + self.phase_roll)
|
| 236 |
+
)
|
| 237 |
+
x_mm = SWAY_A_X_MM * loud * env * math.sin(2 * math.pi * SWAY_F_X * self.t + self.phase_x)
|
| 238 |
+
y_mm = SWAY_A_Y_MM * loud * env * math.sin(2 * math.pi * SWAY_F_Y * self.t + self.phase_y)
|
| 239 |
+
z_mm = SWAY_A_Z_MM * loud * env * math.sin(2 * math.pi * SWAY_F_Z * self.t + self.phase_z)
|
| 240 |
+
|
| 241 |
+
out.append(
|
| 242 |
+
{
|
| 243 |
+
"pitch_rad": pitch,
|
| 244 |
+
"yaw_rad": yaw,
|
| 245 |
+
"roll_rad": roll,
|
| 246 |
+
"x_mm": x_mm,
|
| 247 |
+
"y_mm": y_mm,
|
| 248 |
+
"z_mm": z_mm,
|
| 249 |
+
},
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
return out
|
reachy_pocket_tts_demo/static/index.html
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<title>Pocket TTS Demo</title>
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 8 |
+
<link rel="stylesheet" href="/static/style.css">
|
| 9 |
+
</head>
|
| 10 |
+
|
| 11 |
+
<body>
|
| 12 |
+
<h1>Pocket TTS Demo</h1>
|
| 13 |
+
<p class="subtitle">Text-to-speech with head wobble on Reachy Mini</p>
|
| 14 |
+
|
| 15 |
+
<div id="status-panel">
|
| 16 |
+
<div id="status-indicator" class="loading">Loading model...</div>
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<div id="controls">
|
| 20 |
+
<textarea id="text-input" placeholder="Enter text for the robot to speak..." rows="4"></textarea>
|
| 21 |
+
<button id="speak-btn" disabled>Speak</button>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<div id="metrics">
|
| 25 |
+
<h3>Performance Metrics</h3>
|
| 26 |
+
<div class="metric">
|
| 27 |
+
<span class="label">Model load time:</span>
|
| 28 |
+
<span id="model-load-time" class="value">--</span>
|
| 29 |
+
</div>
|
| 30 |
+
<div class="metric">
|
| 31 |
+
<span class="label">Voice load time:</span>
|
| 32 |
+
<span id="voice-load-time" class="value">--</span>
|
| 33 |
+
</div>
|
| 34 |
+
<div class="metric">
|
| 35 |
+
<span class="label">Last inference time:</span>
|
| 36 |
+
<span id="inference-time" class="value">--</span>
|
| 37 |
+
</div>
|
| 38 |
+
<div class="metric">
|
| 39 |
+
<span class="label">Audio duration:</span>
|
| 40 |
+
<span id="audio-duration" class="value">--</span>
|
| 41 |
+
</div>
|
| 42 |
+
<div class="metric">
|
| 43 |
+
<span class="label">Real-time factor:</span>
|
| 44 |
+
<span id="realtime-factor" class="value">--</span>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
<script src="/static/main.js"></script>
|
| 49 |
+
</body>
|
| 50 |
+
|
| 51 |
+
</html>
|
reachy_pocket_tts_demo/static/main.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Pocket TTS Demo - Web UI
|
| 2 |
+
|
| 3 |
+
const statusIndicator = document.getElementById("status-indicator");
|
| 4 |
+
const textInput = document.getElementById("text-input");
|
| 5 |
+
const speakBtn = document.getElementById("speak-btn");
|
| 6 |
+
|
| 7 |
+
// Metrics elements
|
| 8 |
+
const modelLoadTime = document.getElementById("model-load-time");
|
| 9 |
+
const voiceLoadTime = document.getElementById("voice-load-time");
|
| 10 |
+
const inferenceTime = document.getElementById("inference-time");
|
| 11 |
+
const audioDuration = document.getElementById("audio-duration");
|
| 12 |
+
const realtimeFactor = document.getElementById("realtime-factor");
|
| 13 |
+
|
| 14 |
+
let currentStatus = "loading";
|
| 15 |
+
|
| 16 |
+
async function fetchStatus() {
|
| 17 |
+
try {
|
| 18 |
+
const resp = await fetch("/status");
|
| 19 |
+
const data = await resp.json();
|
| 20 |
+
updateUI(data);
|
| 21 |
+
} catch (e) {
|
| 22 |
+
statusIndicator.textContent = "Connection error";
|
| 23 |
+
statusIndicator.className = "error";
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function updateUI(data) {
|
| 28 |
+
currentStatus = data.status;
|
| 29 |
+
|
| 30 |
+
// Update status indicator
|
| 31 |
+
statusIndicator.textContent = getStatusText(data.status);
|
| 32 |
+
statusIndicator.className = getStatusClass(data.status);
|
| 33 |
+
|
| 34 |
+
// Enable/disable speak button
|
| 35 |
+
speakBtn.disabled = !data.model_loaded || data.status === "generating" || data.status === "speaking";
|
| 36 |
+
|
| 37 |
+
// Update metrics
|
| 38 |
+
if (data.model_load_time > 0) {
|
| 39 |
+
modelLoadTime.textContent = data.model_load_time.toFixed(2) + "s";
|
| 40 |
+
}
|
| 41 |
+
if (data.voice_load_time > 0) {
|
| 42 |
+
voiceLoadTime.textContent = data.voice_load_time.toFixed(2) + "s";
|
| 43 |
+
}
|
| 44 |
+
if (data.last_inference_time > 0) {
|
| 45 |
+
inferenceTime.textContent = data.last_inference_time.toFixed(2) + "s";
|
| 46 |
+
}
|
| 47 |
+
if (data.last_audio_duration > 0) {
|
| 48 |
+
audioDuration.textContent = data.last_audio_duration.toFixed(2) + "s";
|
| 49 |
+
}
|
| 50 |
+
if (data.last_realtime_factor > 0) {
|
| 51 |
+
realtimeFactor.textContent = data.last_realtime_factor.toFixed(1) + "x";
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function getStatusText(status) {
|
| 56 |
+
switch (status) {
|
| 57 |
+
case "loading": return "Loading model...";
|
| 58 |
+
case "ready": return "Ready";
|
| 59 |
+
case "generating": return "Generating audio...";
|
| 60 |
+
case "speaking": return "Speaking...";
|
| 61 |
+
default:
|
| 62 |
+
if (status.startsWith("error:")) {
|
| 63 |
+
return "Error: " + status.substring(7);
|
| 64 |
+
}
|
| 65 |
+
return status;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function getStatusClass(status) {
|
| 70 |
+
if (status === "ready") return "ready";
|
| 71 |
+
if (status === "loading" || status === "generating") return "loading";
|
| 72 |
+
if (status === "speaking") return "speaking";
|
| 73 |
+
if (status.startsWith("error")) return "error";
|
| 74 |
+
return "";
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
async function speak() {
|
| 78 |
+
const text = textInput.value.trim();
|
| 79 |
+
if (!text) {
|
| 80 |
+
alert("Please enter some text");
|
| 81 |
+
return;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
speakBtn.disabled = true;
|
| 85 |
+
|
| 86 |
+
try {
|
| 87 |
+
const resp = await fetch("/speak", {
|
| 88 |
+
method: "POST",
|
| 89 |
+
headers: { "Content-Type": "application/json" },
|
| 90 |
+
body: JSON.stringify({ text }),
|
| 91 |
+
});
|
| 92 |
+
const data = await resp.json();
|
| 93 |
+
|
| 94 |
+
if (data.error) {
|
| 95 |
+
alert("Error: " + data.error);
|
| 96 |
+
}
|
| 97 |
+
} catch (e) {
|
| 98 |
+
alert("Failed to send speak request: " + e);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
// Event listeners
|
| 103 |
+
speakBtn.addEventListener("click", speak);
|
| 104 |
+
|
| 105 |
+
textInput.addEventListener("keydown", (e) => {
|
| 106 |
+
// Ctrl+Enter or Cmd+Enter to speak
|
| 107 |
+
if ((e.ctrlKey || e.metaKey) && e.key === "Enter") {
|
| 108 |
+
e.preventDefault();
|
| 109 |
+
if (!speakBtn.disabled) {
|
| 110 |
+
speak();
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
});
|
| 114 |
+
|
| 115 |
+
// Poll status every 500ms
|
| 116 |
+
setInterval(fetchStatus, 500);
|
| 117 |
+
|
| 118 |
+
// Initial fetch
|
| 119 |
+
fetchStatus();
|
reachy_pocket_tts_demo/static/style.css
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
* {
|
| 2 |
+
box-sizing: border-box;
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
body {
|
| 6 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
| 7 |
+
max-width: 600px;
|
| 8 |
+
margin: 0 auto;
|
| 9 |
+
padding: 20px;
|
| 10 |
+
background: #1a1a2e;
|
| 11 |
+
color: #eee;
|
| 12 |
+
min-height: 100vh;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
h1 {
|
| 16 |
+
text-align: center;
|
| 17 |
+
color: #ff9900;
|
| 18 |
+
margin-bottom: 5px;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.subtitle {
|
| 22 |
+
text-align: center;
|
| 23 |
+
color: #888;
|
| 24 |
+
margin-top: 0;
|
| 25 |
+
margin-bottom: 30px;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
#status-panel {
|
| 29 |
+
margin-bottom: 20px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
#status-indicator {
|
| 33 |
+
padding: 12px 20px;
|
| 34 |
+
border-radius: 8px;
|
| 35 |
+
text-align: center;
|
| 36 |
+
font-weight: 600;
|
| 37 |
+
transition: all 0.3s ease;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#status-indicator.loading {
|
| 41 |
+
background: #2d2d44;
|
| 42 |
+
color: #ffd700;
|
| 43 |
+
animation: pulse 1.5s infinite;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
#status-indicator.ready {
|
| 47 |
+
background: #1e3a1e;
|
| 48 |
+
color: #4ade80;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#status-indicator.speaking {
|
| 52 |
+
background: #1e2a3a;
|
| 53 |
+
color: #60a5fa;
|
| 54 |
+
animation: pulse 0.8s infinite;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
#status-indicator.error {
|
| 58 |
+
background: #3a1e1e;
|
| 59 |
+
color: #f87171;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
@keyframes pulse {
|
| 63 |
+
0%, 100% { opacity: 1; }
|
| 64 |
+
50% { opacity: 0.7; }
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
#controls {
|
| 68 |
+
display: flex;
|
| 69 |
+
flex-direction: column;
|
| 70 |
+
gap: 15px;
|
| 71 |
+
margin-bottom: 30px;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
#text-input {
|
| 75 |
+
width: 100%;
|
| 76 |
+
padding: 15px;
|
| 77 |
+
border: 2px solid #333;
|
| 78 |
+
border-radius: 8px;
|
| 79 |
+
background: #2d2d44;
|
| 80 |
+
color: #eee;
|
| 81 |
+
font-size: 16px;
|
| 82 |
+
resize: vertical;
|
| 83 |
+
min-height: 100px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
#text-input:focus {
|
| 87 |
+
outline: none;
|
| 88 |
+
border-color: #ff9900;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
#text-input::placeholder {
|
| 92 |
+
color: #666;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
#speak-btn {
|
| 96 |
+
padding: 15px 30px;
|
| 97 |
+
font-size: 18px;
|
| 98 |
+
font-weight: 600;
|
| 99 |
+
background: #ff9900;
|
| 100 |
+
color: #1a1a2e;
|
| 101 |
+
border: none;
|
| 102 |
+
border-radius: 8px;
|
| 103 |
+
cursor: pointer;
|
| 104 |
+
transition: all 0.2s ease;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
#speak-btn:hover:not(:disabled) {
|
| 108 |
+
background: #ffaa22;
|
| 109 |
+
transform: translateY(-2px);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
#speak-btn:active:not(:disabled) {
|
| 113 |
+
transform: translateY(0);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
#speak-btn:disabled {
|
| 117 |
+
background: #555;
|
| 118 |
+
color: #888;
|
| 119 |
+
cursor: not-allowed;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
#metrics {
|
| 123 |
+
background: #2d2d44;
|
| 124 |
+
border-radius: 8px;
|
| 125 |
+
padding: 20px;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
#metrics h3 {
|
| 129 |
+
margin-top: 0;
|
| 130 |
+
margin-bottom: 15px;
|
| 131 |
+
color: #ff9900;
|
| 132 |
+
font-size: 14px;
|
| 133 |
+
text-transform: uppercase;
|
| 134 |
+
letter-spacing: 1px;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.metric {
|
| 138 |
+
display: flex;
|
| 139 |
+
justify-content: space-between;
|
| 140 |
+
padding: 8px 0;
|
| 141 |
+
border-bottom: 1px solid #3d3d54;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.metric:last-child {
|
| 145 |
+
border-bottom: none;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.metric .label {
|
| 149 |
+
color: #888;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.metric .value {
|
| 153 |
+
font-family: "SF Mono", Monaco, "Courier New", monospace;
|
| 154 |
+
color: #4ade80;
|
| 155 |
+
font-weight: 600;
|
| 156 |
+
}
|
reachy_pocket_tts_demo/tts.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pocket TTS wrapper with timing metrics."""
|
| 2 |
+
|
| 3 |
+
import time
|
| 4 |
+
import logging
|
| 5 |
+
from dataclasses import dataclass
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
from numpy.typing import NDArray
|
| 9 |
+
|
| 10 |
+
logger = logging.getLogger(__name__)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@dataclass
|
| 14 |
+
class TTSMetrics:
|
| 15 |
+
"""Timing metrics for TTS inference."""
|
| 16 |
+
model_load_time: float = 0.0
|
| 17 |
+
voice_load_time: float = 0.0
|
| 18 |
+
inference_time: float = 0.0
|
| 19 |
+
audio_duration: float = 0.0
|
| 20 |
+
|
| 21 |
+
@property
|
| 22 |
+
def realtime_factor(self) -> float:
|
| 23 |
+
"""How many times faster than real-time (audio_duration / inference_time)."""
|
| 24 |
+
if self.inference_time > 0:
|
| 25 |
+
return self.audio_duration / self.inference_time
|
| 26 |
+
return 0.0
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class TTSEngine:
|
| 30 |
+
"""Wrapper around pocket-tts for text-to-speech."""
|
| 31 |
+
|
| 32 |
+
def __init__(self, voice: str = "jean"):
|
| 33 |
+
self.voice_name = voice
|
| 34 |
+
self.model = None
|
| 35 |
+
self.voice_state = None
|
| 36 |
+
self.sample_rate = 24000
|
| 37 |
+
self.metrics = TTSMetrics()
|
| 38 |
+
self._loaded = False
|
| 39 |
+
|
| 40 |
+
def load(self) -> TTSMetrics:
|
| 41 |
+
"""Load the TTS model and voice state. Call once at startup."""
|
| 42 |
+
from pocket_tts import TTSModel
|
| 43 |
+
|
| 44 |
+
logger.info("Loading pocket-tts model...")
|
| 45 |
+
t0 = time.perf_counter()
|
| 46 |
+
self.model = TTSModel.load_model()
|
| 47 |
+
self.metrics.model_load_time = time.perf_counter() - t0
|
| 48 |
+
logger.info(f"Model loaded in {self.metrics.model_load_time:.2f}s")
|
| 49 |
+
|
| 50 |
+
logger.info(f"Loading voice state for '{self.voice_name}'...")
|
| 51 |
+
t0 = time.perf_counter()
|
| 52 |
+
self.voice_state = self.model.get_state_for_audio_prompt(self.voice_name)
|
| 53 |
+
self.metrics.voice_load_time = time.perf_counter() - t0
|
| 54 |
+
logger.info(f"Voice loaded in {self.metrics.voice_load_time:.2f}s")
|
| 55 |
+
|
| 56 |
+
self.sample_rate = self.model.sample_rate
|
| 57 |
+
self._loaded = True
|
| 58 |
+
return self.metrics
|
| 59 |
+
|
| 60 |
+
def is_loaded(self) -> bool:
|
| 61 |
+
"""Check if model is ready."""
|
| 62 |
+
return self._loaded
|
| 63 |
+
|
| 64 |
+
def generate(self, text: str) -> tuple[NDArray[np.float32], TTSMetrics]:
|
| 65 |
+
"""Generate audio from text.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
text: Text to synthesize
|
| 69 |
+
|
| 70 |
+
Returns:
|
| 71 |
+
Tuple of (audio array, metrics)
|
| 72 |
+
"""
|
| 73 |
+
if not self._loaded:
|
| 74 |
+
raise RuntimeError("TTS model not loaded. Call load() first.")
|
| 75 |
+
|
| 76 |
+
logger.info(f"Generating audio for: {text[:50]}...")
|
| 77 |
+
t0 = time.perf_counter()
|
| 78 |
+
audio = self.model.generate_audio(self.voice_state, text)
|
| 79 |
+
self.metrics.inference_time = time.perf_counter() - t0
|
| 80 |
+
|
| 81 |
+
# Convert to numpy if needed
|
| 82 |
+
if hasattr(audio, 'numpy'):
|
| 83 |
+
audio = audio.numpy()
|
| 84 |
+
|
| 85 |
+
self.metrics.audio_duration = len(audio) / self.sample_rate
|
| 86 |
+
logger.info(
|
| 87 |
+
f"Generated {self.metrics.audio_duration:.2f}s audio "
|
| 88 |
+
f"in {self.metrics.inference_time:.2f}s "
|
| 89 |
+
f"({self.metrics.realtime_factor:.1f}x real-time)"
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
return audio.astype(np.float32), self.metrics
|
style.css
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
* {
|
| 2 |
+
margin: 0;
|
| 3 |
+
padding: 0;
|
| 4 |
+
box-sizing: border-box;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
body {
|
| 8 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 9 |
+
line-height: 1.6;
|
| 10 |
+
color: #333;
|
| 11 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 12 |
+
min-height: 100vh;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.hero {
|
| 16 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 17 |
+
color: white;
|
| 18 |
+
padding: 4rem 2rem;
|
| 19 |
+
text-align: center;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.hero-content {
|
| 23 |
+
max-width: 800px;
|
| 24 |
+
margin: 0 auto;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.app-icon {
|
| 28 |
+
font-size: 4rem;
|
| 29 |
+
margin-bottom: 1rem;
|
| 30 |
+
display: inline-block;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.hero h1 {
|
| 34 |
+
font-size: 3rem;
|
| 35 |
+
font-weight: 700;
|
| 36 |
+
margin-bottom: 1rem;
|
| 37 |
+
background: linear-gradient(45deg, #fff, #f0f9ff);
|
| 38 |
+
background-clip: text;
|
| 39 |
+
-webkit-background-clip: text;
|
| 40 |
+
-webkit-text-fill-color: transparent;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.tagline {
|
| 44 |
+
font-size: 1.25rem;
|
| 45 |
+
opacity: 0.9;
|
| 46 |
+
max-width: 600px;
|
| 47 |
+
margin: 0 auto;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.container {
|
| 51 |
+
max-width: 1200px;
|
| 52 |
+
margin: 0 auto;
|
| 53 |
+
padding: 0 2rem;
|
| 54 |
+
position: relative;
|
| 55 |
+
z-index: 2;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.main-card {
|
| 59 |
+
background: white;
|
| 60 |
+
border-radius: 20px;
|
| 61 |
+
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
| 62 |
+
margin-top: -2rem;
|
| 63 |
+
overflow: hidden;
|
| 64 |
+
margin-bottom: 3rem;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.app-preview {
|
| 68 |
+
background: linear-gradient(135deg, #1e3a8a, #3b82f6);
|
| 69 |
+
padding: 3rem;
|
| 70 |
+
color: white;
|
| 71 |
+
text-align: center;
|
| 72 |
+
position: relative;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.preview-image {
|
| 76 |
+
background: #000;
|
| 77 |
+
border-radius: 15px;
|
| 78 |
+
padding: 2rem;
|
| 79 |
+
max-width: 500px;
|
| 80 |
+
margin: 0 auto;
|
| 81 |
+
position: relative;
|
| 82 |
+
overflow: hidden;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.camera-feed {
|
| 86 |
+
font-size: 4rem;
|
| 87 |
+
margin-bottom: 1rem;
|
| 88 |
+
opacity: 0.7;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.detection-overlay {
|
| 92 |
+
position: absolute;
|
| 93 |
+
top: 50%;
|
| 94 |
+
left: 50%;
|
| 95 |
+
transform: translate(-50%, -50%);
|
| 96 |
+
width: 100%;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.bbox {
|
| 100 |
+
background: rgba(34, 197, 94, 0.9);
|
| 101 |
+
color: white;
|
| 102 |
+
padding: 0.5rem 1rem;
|
| 103 |
+
border-radius: 8px;
|
| 104 |
+
font-size: 0.9rem;
|
| 105 |
+
font-weight: 600;
|
| 106 |
+
margin: 0.5rem;
|
| 107 |
+
display: inline-block;
|
| 108 |
+
border: 2px solid #22c55e;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.app-details {
|
| 112 |
+
padding: 3rem;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.app-details h2 {
|
| 116 |
+
font-size: 2rem;
|
| 117 |
+
color: #1e293b;
|
| 118 |
+
margin-bottom: 2rem;
|
| 119 |
+
text-align: center;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.template-info {
|
| 123 |
+
display: grid;
|
| 124 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
| 125 |
+
gap: 2rem;
|
| 126 |
+
margin-bottom: 3rem;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
.info-box {
|
| 130 |
+
background: #f0f9ff;
|
| 131 |
+
border: 2px solid #e0f2fe;
|
| 132 |
+
border-radius: 12px;
|
| 133 |
+
padding: 2rem;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.info-box h3 {
|
| 137 |
+
color: #0c4a6e;
|
| 138 |
+
margin-bottom: 1rem;
|
| 139 |
+
font-size: 1.2rem;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.info-box p {
|
| 143 |
+
color: #0369a1;
|
| 144 |
+
line-height: 1.6;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.how-to-use {
|
| 148 |
+
background: #fefce8;
|
| 149 |
+
border: 2px solid #fde047;
|
| 150 |
+
border-radius: 12px;
|
| 151 |
+
padding: 2rem;
|
| 152 |
+
margin-top: 3rem;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.how-to-use h3 {
|
| 156 |
+
color: #a16207;
|
| 157 |
+
margin-bottom: 1.5rem;
|
| 158 |
+
font-size: 1.3rem;
|
| 159 |
+
text-align: center;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
.steps {
|
| 163 |
+
display: flex;
|
| 164 |
+
flex-direction: column;
|
| 165 |
+
gap: 1.5rem;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.step {
|
| 169 |
+
display: flex;
|
| 170 |
+
align-items: flex-start;
|
| 171 |
+
gap: 1rem;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
.step-number {
|
| 175 |
+
background: #eab308;
|
| 176 |
+
color: white;
|
| 177 |
+
width: 2rem;
|
| 178 |
+
height: 2rem;
|
| 179 |
+
border-radius: 50%;
|
| 180 |
+
display: flex;
|
| 181 |
+
align-items: center;
|
| 182 |
+
justify-content: center;
|
| 183 |
+
font-weight: bold;
|
| 184 |
+
flex-shrink: 0;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.step h4 {
|
| 188 |
+
color: #a16207;
|
| 189 |
+
margin-bottom: 0.5rem;
|
| 190 |
+
font-size: 1.1rem;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
.step p {
|
| 194 |
+
color: #ca8a04;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.download-card {
|
| 198 |
+
background: white;
|
| 199 |
+
border-radius: 20px;
|
| 200 |
+
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
| 201 |
+
padding: 3rem;
|
| 202 |
+
text-align: center;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
.download-card h2 {
|
| 206 |
+
font-size: 2rem;
|
| 207 |
+
color: #1e293b;
|
| 208 |
+
margin-bottom: 1rem;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
.download-card>p {
|
| 212 |
+
color: #64748b;
|
| 213 |
+
font-size: 1.1rem;
|
| 214 |
+
margin-bottom: 2rem;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.dashboard-config {
|
| 218 |
+
margin-bottom: 2rem;
|
| 219 |
+
text-align: left;
|
| 220 |
+
max-width: 400px;
|
| 221 |
+
margin-left: auto;
|
| 222 |
+
margin-right: auto;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
.dashboard-config label {
|
| 226 |
+
display: block;
|
| 227 |
+
color: #374151;
|
| 228 |
+
font-weight: 600;
|
| 229 |
+
margin-bottom: 0.5rem;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
.dashboard-config input {
|
| 233 |
+
width: 100%;
|
| 234 |
+
padding: 0.75rem 1rem;
|
| 235 |
+
border: 2px solid #e5e7eb;
|
| 236 |
+
border-radius: 8px;
|
| 237 |
+
font-size: 0.95rem;
|
| 238 |
+
transition: border-color 0.2s;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
.dashboard-config input:focus {
|
| 242 |
+
outline: none;
|
| 243 |
+
border-color: #667eea;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
.install-btn {
|
| 247 |
+
background: linear-gradient(135deg, #667eea, #764ba2);
|
| 248 |
+
color: white;
|
| 249 |
+
border: none;
|
| 250 |
+
padding: 1.25rem 3rem;
|
| 251 |
+
border-radius: 16px;
|
| 252 |
+
font-size: 1.2rem;
|
| 253 |
+
font-weight: 700;
|
| 254 |
+
cursor: pointer;
|
| 255 |
+
transition: all 0.3s ease;
|
| 256 |
+
display: inline-flex;
|
| 257 |
+
align-items: center;
|
| 258 |
+
gap: 0.75rem;
|
| 259 |
+
margin-bottom: 2rem;
|
| 260 |
+
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.install-btn:hover:not(:disabled) {
|
| 264 |
+
transform: translateY(-3px);
|
| 265 |
+
box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
.install-btn:disabled {
|
| 269 |
+
opacity: 0.7;
|
| 270 |
+
cursor: not-allowed;
|
| 271 |
+
transform: none;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
.manual-option {
|
| 275 |
+
background: #f8fafc;
|
| 276 |
+
border-radius: 12px;
|
| 277 |
+
padding: 2rem;
|
| 278 |
+
margin-top: 2rem;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
.manual-option h3 {
|
| 282 |
+
color: #1e293b;
|
| 283 |
+
margin-bottom: 1rem;
|
| 284 |
+
font-size: 1.2rem;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.manual-option>p {
|
| 288 |
+
color: #64748b;
|
| 289 |
+
margin-bottom: 1rem;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
.btn-icon {
|
| 293 |
+
font-size: 1.1rem;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.install-status {
|
| 297 |
+
padding: 1rem;
|
| 298 |
+
border-radius: 8px;
|
| 299 |
+
font-size: 0.9rem;
|
| 300 |
+
text-align: center;
|
| 301 |
+
display: none;
|
| 302 |
+
margin-top: 1rem;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
.install-status.success {
|
| 306 |
+
background: #dcfce7;
|
| 307 |
+
color: #166534;
|
| 308 |
+
border: 1px solid #bbf7d0;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
.install-status.error {
|
| 312 |
+
background: #fef2f2;
|
| 313 |
+
color: #dc2626;
|
| 314 |
+
border: 1px solid #fecaca;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
.install-status.loading {
|
| 318 |
+
background: #dbeafe;
|
| 319 |
+
color: #1d4ed8;
|
| 320 |
+
border: 1px solid #bfdbfe;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.install-status.info {
|
| 324 |
+
background: #e0f2fe;
|
| 325 |
+
color: #0369a1;
|
| 326 |
+
border: 1px solid #7dd3fc;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
.manual-install {
|
| 330 |
+
background: #1f2937;
|
| 331 |
+
border-radius: 8px;
|
| 332 |
+
padding: 1rem;
|
| 333 |
+
margin-bottom: 1rem;
|
| 334 |
+
display: flex;
|
| 335 |
+
align-items: center;
|
| 336 |
+
gap: 1rem;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
.manual-install code {
|
| 340 |
+
color: #10b981;
|
| 341 |
+
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
|
| 342 |
+
font-size: 0.85rem;
|
| 343 |
+
flex: 1;
|
| 344 |
+
overflow-x: auto;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
.copy-btn {
|
| 348 |
+
background: #374151;
|
| 349 |
+
color: white;
|
| 350 |
+
border: none;
|
| 351 |
+
padding: 0.5rem 1rem;
|
| 352 |
+
border-radius: 6px;
|
| 353 |
+
font-size: 0.8rem;
|
| 354 |
+
cursor: pointer;
|
| 355 |
+
transition: background-color 0.2s;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
.copy-btn:hover {
|
| 359 |
+
background: #4b5563;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
.manual-steps {
|
| 363 |
+
color: #6b7280;
|
| 364 |
+
font-size: 0.9rem;
|
| 365 |
+
line-height: 1.8;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
.footer {
|
| 369 |
+
text-align: center;
|
| 370 |
+
padding: 2rem;
|
| 371 |
+
color: white;
|
| 372 |
+
opacity: 0.8;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
.footer a {
|
| 376 |
+
color: white;
|
| 377 |
+
text-decoration: none;
|
| 378 |
+
font-weight: 600;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
.footer a:hover {
|
| 382 |
+
text-decoration: underline;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
/* Responsive Design */
|
| 386 |
+
@media (max-width: 768px) {
|
| 387 |
+
.hero {
|
| 388 |
+
padding: 2rem 1rem;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
.hero h1 {
|
| 392 |
+
font-size: 2rem;
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
.container {
|
| 396 |
+
padding: 0 1rem;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
.app-details,
|
| 400 |
+
.download-card {
|
| 401 |
+
padding: 2rem;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
.features-grid {
|
| 405 |
+
grid-template-columns: 1fr;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
.download-options {
|
| 409 |
+
grid-template-columns: 1fr;
|
| 410 |
+
}
|
| 411 |
+
}
|