Skip to main content

Frontend API

AudioTranscription.tsx

The AudioTranscription.tsx file implements a React component for real-time audio transcription and tile prediction, using the browser's microphone, the MediaRecorder API, and a backend via Socket.io.

This component is ideal for applications that require speech-to-text capabilities with intelligent suggestions (tiles) based on both spoken words and tile interactions—such as communication boards or accessible UIs for AAC (Augmentative and Alternative Communication).

Dependencies - Socket.io

  • socket.io-client for WebSocket communication.
  • Several state/context providers (e.g., useTranscript, usePredictedTiles, useUtteredTiles, useRecordingControl)—assumed to be from the app's custom state management system.

Purpose: Sends audio chunks to the backend, receives live transcription.

  • Client emits: audio-chunk
  • Server emits: transcript (with transcribed text)

No REST endpoint, handled via Socket.io events.

Example flow:

  • Client emits: audio-chunk (binary)
  • Server responds: transcript (string)

Component Structure

Main State & Refs

NameTypePurpose
recordbooleanIf recording is active
transcriptstringCurrent transcript text
audioURLstring | nullRecorded audio file URL
audioProgressnumberAudio playback progress (0–100%)
isPlayingbooleanIf audio is currently playing
predictedTilesstring[]Tile suggestions from backend
utteredTilesArray<{ text: string }>Tiles "pressed" by the user
isActivebooleanIf recording/session is enabled
isPredictingbooleanIf a prediction request is in progress
......Various refs for timers, intervals, handlers

Main Functions & Their Roles

FunctionPurposeUsage Context
startRecording()Starts MediaRecorder, sets up listeners, and begins sending audio to serverOn start/auto-start
stopRecording()Stops MediaRecorder, removes listeners, clears transcript & predictionsOn stop or inactive
predictNextTiles()Calls /api/nextTilePred to get suggestions based on transcript/tilesOn interval, tile click
setupPeriodicPredictionInterval()Sets up 15s interval for automatic prediction callsOn recording
togglePlayback()Plays or pauses recorded audioOn play/pause button
handleTimeUpdate()Updates progress bar as audio playsOn audio playback