Upload Audio
The wearable or mobile app streams audio to the server in 30-second windowed chunks during an active session; the Lambda stores each chunk in S3 and triggers downstream ingest when both audio and frames are ready for a window.
Flow
Per-window chunk upload (primary path)
-
Client sends audio chunk — A
POSTrequest is sent to/sessions/{sessionId}/audio?windowIndex=<n>with the audio bytes as the request body (audio/wav, possibly base64-encoded by API Gateway). -
Session lookup —
sessionIdis extracted from path parameters; missing session ID returns HTTP 400. -
Body decoding — If
isBase64Encodedis set in the API Gateway event, the body is base64-decoded; otherwise it is used as-is. -
S3 write — Audio is stored at
sessions/{sessionId}/window_{windowIndex:03d}/audio.wav. -
DynamoDB atomic update —
completedAudioWindowsset is extended withwindowIndexusing anADDoperation; the updated session record is returned. -
Ingest trigger decision — Ingest is triggered if:
captureMode == "audio_only", OR-
the same
windowIndexalready appears incompletedFrameWindows -
Deduplication claim — A conditional
ADDtoingestTriggeredWindowsensures only one invocation triggers ingest per window (idempotent across retries and concurrent calls). -
Ingest Lambda invocation — The ingest function is called asynchronously (
InvocationType=Event) with{ sessionId, userId, windowIndex, frameCount }. -
Response — Returns
{ "ok": true, "s3Key": "...", "windowIndex": n, "ingestTriggered": true/false }.
Legacy full-session upload (backward compat)
If windowIndex is absent from the query string, the entire audio body is stored at sessions/{sessionId}/audio/full.{ext} and returns { "ok": true, "s3Key": "...", "legacy": true }. No ingest is triggered.
Entry Point
- Lambda:
main/server/api/sessions/audio/app.py→lambda_handler - HTTP method:
POST /sessions/{sessionId}/audio(API Gateway)
Dependencies
- S3 bucket:
BUCKET_NAME(defaultencache-raw-memory) - DynamoDB:
SESSIONS_TABLE_NAME - Lambda:
INGEST_FUNCTION_NAME
Error Cases
| Condition | Response |
|---|---|
| Missing sessionId path param | 400 |
| Non-integer windowIndex | 400 |
| Negative windowIndex | 400 |