# Plappi MVP — bilingualer KI-Sprach-Tutor

Erster **handfester** Plappi-Build: ein Sprach-Tutor, mit dem ein Kind per Stimme
redet und der bilingual antwortet. Handy-App heute, Raspberry-Pi-Gerät später —
**ohne das Backend zu ändern**.

## Architektur — „Gehirn im Backend, dünner Client"

```
CLIENT (austauschbar)                 PLAPPI-BACKEND  (= das Produkt)
┌─────────────────────┐   POST       ┌──────────────────────────────────────┐
│ heute:  Handy-PWA   │  /api/turn   │ 1. ASR     whisper.cpp (lokal, gratis) │
│  Push-to-Talk, Mikro│ ───────────► │ 2. DIALOG  Plappi-Persona + Sicherheit │
│  Lautsprecher       │ ◄─────────── │            (claude → später OSS-EU)    │
│ morgen: Raspberry Pi│   Audio+Text │ 3. TTS     edge-tts (neuronal, gratis) │
│  Mikro + GPIO-Knopf │              │ + Session-Verlauf je Kind              │
└─────────────────────┘              └──────────────────────────────────────┘
```

Der Client ist dumm (Mikro + Lautsprecher + Netz). Alle Intelligenz lebt im
Backend. Darum ist der spätere Pi nur ein anderer Client an **derselben** API
(`clients/pi/`), und die KI-Arbeit (ASR/Dialog/TTS) wird genau einmal gebaut.

## Tech (alles bereits auf der VM, kostenlos)
- **ASR:** whisper.cpp + `ggml-small` — lokal, offline-fähig, keine API-Kosten
- **Dialog:** claude-CLI (vorhandenes Abo) — *swappbar* gegen private OSS-EU-Inferenz (das geförderte F&E-AP)
- **TTS:** edge-tts (neuronale Stimmen, de-AT/de-DE/sr-RS …)
- **Server:** FastAPI + uvicorn

## Starten
```bash
cd plappi-mvp
./run.sh                      # http://localhost:8800  (serviert Backend + Handy-Client)
```
Vom Handy im selben Netz: `http://<VM-IP>:8800`.
> Mikrofon im Browser braucht **HTTPS oder localhost**. Fürs Handy-Testen daher
> entweder `localhost`-Tunnel (ssh -L / cloudflared) oder TLS-Reverse-Proxy davor.

### Schnelltest ohne Mikro
```bash
curl -s -X POST localhost:8800/api/say -F session_id=test -F text="Hallo Plappi" | python3 -m json.tool
```

## Konfiguration (ENV)
| Var | Default | Zweck |
|---|---|---|
| `PLAPPI_CHILD_LANG` / `PLAPPI_TARGET_LANG` | `de` / `sr` | Starke Sprache / Lernsprache |
| `PLAPPI_VOICE` | `de-AT-IngridNeural` | TTS-Stimme |
| `PLAPPI_DIALOG_MODEL` | `haiku` | Dialog-Modell (claude-CLI) |
| `PLAPPI_WHISPER_MODEL` | `…/ggml-small.bin` | ASR-Modell |
| `PLAPPI_PORT` | `8800` | Server-Port |

## Produkt-Compliance (eingebaut)
Plappi ist strikt **Lernwerkzeug/Tutor, nie „Freund/Begleiter"** — hält
Kickstarter-Regeln (Verbot manipulativer Companion-Toys) + EU-AI-Act ein.
Kindersicherheits-Regeln stehen in `backend/dialog.py` (Persona).

## Status & nächste Iterationen
- [x] Backend-Kern: ASR → Dialog → TTS, Sessions, Handy-PWA, Reset
- [x] Plappi-Persona mit Sicherheits-/Compliance-Regeln
- [ ] Code-Switching-TTS: Zielsprach-Wörter mit eigener Stimme (`sr-RS-Sophie`) segmentiert sprechen
- [ ] TLS/Tunnel für Handy-Mikro-Test unterwegs
- [ ] Streaming/Latenz: Dialog-Modell auf schnelle lokale/EU-Inferenz
- [ ] Pädagogik: Vokabel-Tracking + Spaced-Repetition pro Session (Abo-Wert)
- [ ] `clients/pi/pi_client.py` — Gerät-Build (siehe `clients/pi/README.md`)
```
plappi-mvp/
  backend/   app.py · asr.py · dialog.py · tts.py · sessions.py · config.py
  clients/   web/ (Handy-PWA, läuft jetzt) · pi/ (Gerät, später)
  data/      audio/ (TTS-Cache) · uploads/
```
