Skip to content

Homework voice mode: Nova Sonic STT + TTS (#64) - #65

Closed
tpaulshippy wants to merge 3 commits into
mainfrom
feature/roadmap-64-homework-voice
Closed

Homework voice mode: Nova Sonic STT + TTS (#64)#65
tpaulshippy wants to merge 3 commits into
mainfrom
feature/roadmap-64-homework-voice

Conversation

@tpaulshippy

Copy link
Copy Markdown
Owner

Summary

Implements issue #64 (Homework Voice Mode) using Amazon Nova Sonic (amazon.nova-sonic-v1:0) as the speech engine, replacing the Transcribe/Polly path originally sketched in the issue.

Backend (Django)

  • NovaSonicService drives turn-based speech-to-text and text-to-speech over Bedrock InvokeModelWithBidirectionalStream (async aws-sdk-bedrock-runtime). WAV/PCM handled natively; compressed uploads fall back to ffmpeg.
  • POST /api/chats/<id>/voice: gated by Bot.enable_voice and Profile.voice_enabled (403 otherwise), short-circuits on the daily cost cap before STT/LLM (429), stores the transcript as a user message with meta.voice_input, runs the normal agent path in voice mode (spoken replies kept under 80 words), and returns a base64 WAV of the spoken reply.
  • safety.py checks transcripts before the agent runs.
  • STT/TTS metered into the daily cap via Message.voice_cost (per-minute rates are configurable in settings).

Frontend (Expo)

  • Hold-to-talk voice input (VoiceInput.tsx, expo-audio) replaces the composer when voice is enabled for both selected bot and profile, with a recording timer, cancel button, and TTS autoplay toggle. Mic permission added to app.json.
  • Parent controls: Enable Voice switches in the bot editors and an Allow Voice switch in the profile editor.

Tests

Covers the issue's success list — 403 gating, mocked-STT message creation, TTS audio response, safety block, and over-limit short-circuit. 92 backend tests pass; 55 frontend jest tests pass; ruff and lint clean.

Test plan

  • Backend: pytest in back/ (92 passing)
  • Frontend: npm run lint && npm test in front/ (lint clean, 55 passing)
  • Configure NOVA_SONIC_* env vars + AWS creds on the server, enable voice on a bot and profile, and try hold-to-talk on a device

Closes #64

Backend:
- NovaSonicService drives Amazon Nova Sonic (amazon.nova-sonic-v1:0)
  over Bedrock InvokeModelWithBidirectionalStream for turn-based
  speech-to-text and text-to-speech, with WAV/PCM handling and
  ffmpeg fallback for compressed uploads
- POST /api/chats/<id>/voice: gated by Bot.enable_voice AND
  Profile.voice_enabled (403 otherwise), short-circuits on daily
  cap before STT/LLM (429), stores transcript as user message with
  meta.voice_input, runs the normal agent path in voice mode
  (spoken answers under 80 words), returns base64 WAV of spoken reply
- Safety service checks transcripts and blocks unsafe turns
- STT/TTS metered into the daily cost cap via Message.voice_cost
  with per-minute rates configurable in settings

Frontend:
- Hold-to-talk voice input (expo-audio) replacing the composer when
  voice is enabled for both selected bot and profile; recording
  timer, cancel button, TTS autoplay toggle
- Parent controls: Enable Voice switches in bot editors, Allow Voice
  switch in profile editor; mic permission copy in app.json

Tests cover the issue's success list: 403 gating, mocked-STT message
creation, TTS audio response, safety block, over-limit short-circuit.
The voice tests that exercise the agent path constructed a real
ChatBedrock client, which fails AWS credential validation in CI where
no AWS region is configured. Patch ChatBedrock in those tests so the
agent path is mocked, matching how test_chat.py injects a mock client.
@tpaulshippy

Copy link
Copy Markdown
Owner Author

Superseded by #66 (fresh commit SHA so CI check suite runs cleanly; #65's suite became wedged by rerun attempts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Homework Voice Mode — STT input + TTS playback

1 participant