Status: In progress — partial implementation exists in crates/elata-facial-affect (Rust core + calibration). See also architecture-sentiment.md. Phases below still describe a TS-first MediaPipe path; align any new work with the crate and architecture doc before duplicating APIs.
Extract facial sentiment logic from the existing reference implementation into a reusable, platform-agnostic module that consumes face landmarks and emits calibrated labels plus quality signals.
- Confirm output labels:
Neutral|Happy|Stressed|Surprised|Focused|Fatigue. - Decide required outputs: label, confidence, feature deltas, acute stress counter.
- Lock thresholds from the reference implementation or define configuration knobs.
- Create a pure module (TS preferred) that accepts:
- Landmarks or precomputed metrics (smile, browHeight, browDistance, eyeOpenness).
- Calibration state and optional baseline.
- Implement:
- Feature normalization (scale by inter-eye distance).
- Baseline calibration buffer + averaging.
- Rolling history smoothing (last ~15 samples).
- Acute stress detection (brow distance drop or brow height spike).
- Label classification thresholds.
- Export a small API:
update(landmarks, timestamp)->SentimentResultstartCalibration()/finalizeCalibration()reset()
- Build a
MediaPipeSentimentAdapterthat:- Owns camera + FaceMesh.
- Emits
SentimentInputframes to the core module. - Emits
SentimentResultto app listeners.
- Handle face-not-found cases with a quality flag.
- Wire output into stress/tilt models (same as the reference implementation):
- Use
Stressed/Surprised/Fatigueas soft risk cues. - Expose acute stress counter for panic detection.
- Use
- Capture representative landmark fixtures (neutral, smile, brow furrow, fatigue).
- Unit test:
- Baseline calibration stability.
- Label classification thresholds.
- Acute stress counter behavior.
- Compare outputs to the current reference implementation behavior.
- Only if needed: port the pure core to Rust and expose via WASM/FFI.
- Keep adapters in JS/native and feed landmarks to WASM.
- Pure sentiment core module.
- MediaPipe adapter and sample usage.
- Test fixtures + unit tests.
- Docs and examples.
- Optional web wrapper package if distributed alongside WASM APIs.