Phase 4 Voice Recording and Text-to-Speech

Antigravity·Zephyrxx0·6d ago·49min·14 Checkpoints·61 file changes·+4111/-128

/gsd-discuss-phase 4

6d ago·14m

Created: .planning/phases/04-voice-notes-narration-loop-routing/04-CONTEXT.md and .planning/phases/04-voice-notes-narration-loop-routing/04-DISCUSSION-LOG.md on branch phase-4-voice-narration-routing.

Decisions Captured

Voice Note UI & Attachment Context

  • Dual recording triggers: Floating mic in /walk dock attaches to active walk session (walkId); "Add voice note" button on /entry/[id] attaches field reflections directly to that specimen find (entryId).
  • Review drawer: Post-recording bottom sheet with audio playback, detected language badge, and editable transcript textarea with Save/Discard.
  • Map & summary integration: Terracotta audio pin at GPS coordinate along MapLibre trail; scrollable voice notes list in walk completion summary drawer.
  • IndexedDB storage: Compressed audio (WebM/Opus) stored alongside transcript text in Dexie notes table (~30–50KB per 60s note).

Audio Recording Interaction & Waveform

  • Unified smart gesture: Short tap toggles hands-free recording on/off; continuous press-and-hold records until finger release.
  • 60-second limit & visual timer: Circular terracotta progress ring fills clockwise around mic button with MM:SS counter, amber warning at 50s, auto-stopping and dispatching to transcription at 60.0s.
  • Dynamic equalizer waveform: 24–32 responsive terracotta gradient bars via Web Audio AnalyserNode animated with requestAnimationFrame.
  • Cancellation & mic permissions: Slide-to-cancel gesture during hold; red trash icon during hands-free; polite browser permission recovery guidance.

TTS Narration & Speech Playback

  • Full card narration: "Listen" button narrates organism intro name, summary paragraph, and all numbered grounded facts in natural storytelling flow.
  • Inline fact-card audio pill: Replaces "Listen" button with interactive pill featuring Play/Pause, scrubbing progress, elapsed time, and 1x/1.2x speed toggle.
  • Voice style & device fallback: Warm nature-documentary voice for ElevenLabs; seamless fallback to browser speechSynthesis with subtle "Device voice" chip.
  • IndexedDB caching: SHA-256 hash of text + voiceId stored as Blob in speechCache table with LRU pruning (up to 50 clips / 50MB) for instant offline replay.

Loop Route Suggestion & Map Integration

  • Pre-walk start drawer: Segmented picker for "Free Walk" vs "Loop Route (1km / 2km / 3km)", previewing calculated route geometry on MapLibre before starting walk.
  • MapLibre guideline styling: Dashed semi-transparent terracotta polyline (#F35C2B, 0.6 opacity) with direction chevrons; active GPS trail paints glowing solid polyline over it.
  • Non-intrusive off-route guidance: No fitness-style alarms; quiet "Off route" HUD badge with 1-tap "Clear Route" button.
  • Graceful ORS fallback: If ORS_API_KEY is missing or offline, displays calm notice, draws synthetic circular loop for testing/preview, and provides 1-tap "Start Free Walk".

▶ Next Up — [TRE] Treads

Phase 4: Voice Notes, Narration & Loop Routing — Hold/tap voice recorder with live waveform, ElevenLabs Scribe STT with Web Speech fallback, TTS narration, and ORS pedestrian loop routes.

Run:

/gsd-plan-phase 4

6d ago·2m

⚠ UI-SPEC.md missing for Phase 4

▶ Recommended next step: /gsd-ui-phase 4 — generate UI design contract before planning

─────────────────────────────────────────────── Also available:

  • /gsd-plan-phase 4 --skip-ui — plan without UI-SPEC (not recommended for frontend phases)

/gsd-ui-phase 4

6d ago·2m

Created: .planning/phases/04-voice-notes-narration-loop-routing/04-UI-SPEC.md

UI Design Contract Approved for Phase 4

  • Design System: shadcn Base UI (@base-ui-components/react) with Lucide icons and Tangerin Dream CSS tokens.
  • Microphone Action FAB: 56px (w-14 h-14) touch target with 64px circular SVG countdown timer ring (turns warning amber at 50s, auto-finishes at 60s).
  • Voice Recording Sheet & Waveform: Real-time Web Audio AnalyserNode 24–32 vertical bar equalizer in Tangerin Dream terracotta gradient (#F35C2B to #FF8C66), slide-to-cancel cue, red trash action, and review drawer with audio playback, language badge, and editable transcript <textarea>.
  • Fact Card "Listen" Audio Pill: Interactive inline pill on fact-card.tsx with Play/Pause, scrubbing progress bar, elapsed timer (0:14 / 0:42), 1.0x / 1.2x speed toggle, and calm "Device voice" fallback chip.
  • Pedestrian Loop Route Drawer: Pre-walk mode toggle ("Free Walk" vs "Loop Route"), distance picker (1 km, 2 km, 3 km), dashed terracotta guideline on MapLibre, quiet "Off suggested loop" HUD badge with 1-tap "Clear Route", and graceful fallback notice with synthetic loop generation.
  • All 6 Dimensions Verified: Copywriting, Visuals, Color, Typography, Spacing, and Registry Safety: PASS.

▶ Next Up — [TRE] Treads

Phase 4: Voice Notes, Narration & Loop Routing

Run:

/gsd-plan-phase 4

6d ago·4m

Phase 4 execution plans have been generated, checked, and committed on branch phase-4-voice-narration-routing.

Planning Summary — Phase 4: Voice Notes, Narration & Loop Routing

Wave 1

  • 04-01-PLAN.md: Voice Recorder, Live Waveform, ElevenLabs Scribe STT with Web Speech Fallback & Dexie Notes Persistence
    • Task 1: Audio recording engine (lib/audio.ts) with MediaRecorder, Web Audio AnalyserNode frequency analyzer, and browser webkitSpeechRecognition fallback wrapper.
    • Task 2: /api/transcribe route forwarding audio to ElevenLabs Scribe STT with token-bucket rate limiting (30/day) and mock fallback.
    • Task 3: Dynamic Canvas waveform equalizer (voice-waveform.tsx), 60s SVG timer progress ring, unified hold-or-tap gesture sheet (voice-recorder-sheet.tsx), post-recording transcript review drawer with Save/Discard, and trigger wiring on /walk dock and /entry/[id].
    • Automated Verification: scripts/test-transcribe-route.ts

Wave 2 (blocked on Wave 1)

  • 04-02-PLAN.md: Fact Card TTS Narration with Speech Cache & OpenRouteService Pedestrian Loop Routing
    • Task 1: Fact card TTS spoken narration engine (lib/speech.ts), /api/speak ElevenLabs TTS audio stream route, SHA-256 text-hash caching in Dexie speechCache with LRU pruning (up to 50 clips), browser speechSynthesis fallback, and interactive inline audio pill on fact-card.tsx.
    • Task 2: OpenRouteService pedestrian round-trip loop engine (lib/route.ts), /api/route endpoint, and synthetic circular loop fallback generator when ORS_API_KEY is missing or network is offline.
    • Task 3: Pre-walk route preview sheet (route-preview-sheet.tsx) with 1km, 2km, and 3km distance pickers, MapLibre dashed terracotta guideline layer, quiet off-route HUD badge with 1-tap clear route, terracotta audio trail marker pins, and summary notes reel in walk-summary-sheet.tsx.
    • Automated Verification: scripts/test-speak-route.ts and scripts/test-route-loop.ts

Quality & Governance Gates

  • Requirements Coverage: 7/7 requirements (VOIC-01, VOIC-02, VOIC-03, SPK-01, SPK-02, ROUT-01, ROUT-02) mapped and covered.
  • Decision Coverage: 16/16 decisions from 04-CONTEXT.md covered.
  • UI Design Contract: All 6 dimensions verified in 04-UI-SPEC.md.
  • Validation Strategy: Nyquist feedback sampling configured in 04-VALIDATION.md.

▶ Next Up — [TRE] Treads

Execute Phase 4:

/gsd-execute-phase 4

6d ago·18m

Phase 4 Complete: Voice Notes, Narration & Loop Routing

Both plans in Phase 4 (04-01-PLAN.md and 04-02-PLAN.md) have been executed, verified, and committed on branch phase-4-voice-narration-routing.


Key Deliverables Implemented & Verified

1. Audio Recording & Transcription Engine (04-01)

  • Web Audio Infrastructure (lib/audio.ts): Cross-browser audio context, AnalyserNode (fftSize = 64, 32 frequency bins), Opus media recording, hardware track release (stopMediaStream), and browser speech recognition fallback.
  • ElevenLabs Scribe STT Route (app/api/transcribe/route.ts): Rate-limited (30 req/day) STT endpoint with automatic fallback.
  • Dynamic Waveform Visualizer (components/voice/voice-waveform.tsx): 28-bar canvas equalizer with Tangerin Dream terracotta gradient (#F35C2B to #FF8C66).
  • Voice Recorder Sheet (components/voice/voice-recorder-sheet.tsx):
    • Unified hold/tap gestures.
    • 60s SVG timer ring with amber warning at 50s.
    • Slide-to-cancel & trash button.
    • Review drawer with editable transcript <textarea>.
    • Persistence to Dexie db.notes with active walk coordinates (lat, lng).

2. Spoken Fact Narration & Speech Cache (04-02)

  • Speech Cache & Device Speech (lib/speech.ts):
    • Deterministic SHA-256 text hashing (computeSpeechHash).
    • Dexie speechCache storage with LRU pruning keeping $\le 50$ clips.
    • speakWithBrowserUtterance fallback.
  • ElevenLabs TTS Route (app/api/speak/route.ts): Calm nature-documentary voice endpoint with rate limiting (40 req/day) and { fallback: true } signal.
  • Interactive Inline Audio Pill (components/speech/fact-audio-player.tsx): Replaced static "Listen" button in FactCard with Play/Pause, timeline scrubber, elapsed timer, 1.0x/1.2x speed toggle, and "Device voice" chip.

3. OpenRouteService Pedestrian Loop Discovery (04-02)

  • Pedestrian Loop Route Engine (lib/route.ts, app/api/route/route.ts):
    • OpenRouteService round-trip pedestrian loop queries (1km, 2km, 3km) with rate limiting (40 req/day).
    • Synthetic geometric loop fallback generator with organic trigonometric perturbation.
  • Pre-Walk Route Preview Sheet (components/route/route-preview-sheet.tsx): "Free Walk" vs "Loop Route" toggle with 1km / 2km / 3km distance pills and live MapLibre preview before starting.
  • MapLibre Guidelines & Trail Pins (components/map/walk-map.tsx):
    • Dashed terracotta polyline (walk-route-line, #F35C2B at 0.6 opacity) beneath solid active GPS trail.
    • 32px circular terracotta pins with mic icon marking voice notes along the trail.
  • Quiet Off-Route Guidance (components/walk/walk-hud.tsx): Non-intrusive "Off suggested loop" chip if walker diverges $> 60\text{m}$, with 1-tap "Clear Route" button.
  • Summary Notes Reel (components/walk/walk-summary-sheet.tsx): Scrollable voice notes list with in-situ audio playback.

Verification Summary

  • pnpm exec tsc --noEmit $\rightarrow$ 0 errors
  • pnpm exec tsx scripts/test-transcribe-route.ts $\rightarrow$ Passed
  • pnpm exec tsx scripts/test-speak-route.ts $\rightarrow$ Passed
  • pnpm exec tsx scripts/test-route-loop.ts $\rightarrow$ Passed
  • Governance: Updated .planning/ROADMAP.md and .planning/STATE.md (Phase 4: 100% complete).

/gsd-verify-work , write verification doc, commit all files

6d ago

/gsd-verify-work 4, write verification doc, commit all files

6d ago·3m

Phase 4 Verification Complete: Voice Notes, Narration & Loop Routing

All verification artifacts for Phase 4 have been created, automated test suites and production builds verified green, and all files committed on branch phase-4-voice-narration-routing.


Verification Artifacts Created & Committed

  1. UAT Test Results Document (.planning/phases/04-voice-notes-narration-loop-routing/04-UAT.md):

    • Tracks all 15 observable user acceptance tests covering both execution waves (04-01 and 04-02).
    • Confirms pass results for hold/tap gestures, live canvas equalizer, 60s countdown ring, slide-to-cancel, Scribe STT, Dexie note persistence with GPS coordinates, specimen-linked voice notes on /entry/[id], fact card TTS narration, inline audio player pill, SHA-256 speech cache with LRU eviction, pre-walk loop selector drawer, dashed MapLibre route guidelines, off-route HUD guidance, synthetic circular fallbacks, and completion summary notes reel.
    • Score: 15/15 passed (0 issues, 0 gaps).
  2. Phase Verification Report (.planning/phases/04-voice-notes-narration-loop-routing/04-VERIFICATION.md):

    • Executive summary of implemented subsystems.
    • Complete requirement traceability matrix across VOIC-01 through ROUT-02 (7/7 passed).
    • Complete decision traceability matrix across D-01 through D-16 (16/16 verified).
    • Threat mitigation verification (T-04-01 through T-04-06).
    • Final verdict: PASSED.

Empirical Verification Results

  • Next.js 16.4 Production Build (pnpm build):
    • Turbopack compilation: Compiled successfully in 5.4s
    • TypeScript: 0 errors in 1225ms
    • Routes compiled and optimized: 15 routes (○ /, ○ /walk, ƒ /entry/[id], ƒ /api/transcribe, ƒ /api/speak, ƒ /api/route, etc.)
  • Automated Test Harnesses:
    • pnpm exec tsx scripts/test-transcribe-route.ts $\rightarrow$ All /api/transcribe tests passed
    • pnpm exec tsx scripts/test-speak-route.ts $\rightarrow$ All /api/speak tests passed
    • pnpm exec tsx scripts/test-route-loop.ts $\rightarrow$ All /api/route tests passed
  • Git State: Clean working tree on commit b32d81e: