Skip to main content
The useRecording hook provides a React-friendly interface for audio recording, automatically syncing with backend state via Tauri events.

Import

Usage

Return Values

state

Type: RecordingState
Current recording state, automatically synchronized with backend. States:

error

Type: string | null Error message if state is 'error', otherwise null. Example Errors:
  • "Microphone permission denied"
  • "No models installed"
  • "License required to record"

startRecording

Type: () => Promise<void> Start a new recording session. Usage:
Behavior:
  • Invokes start_recording Tauri command
  • State updates are handled by backend events (not the return value)
  • Errors are emitted via recording-state-changed events

stopRecording

Type: () => Promise<void> Stop the current recording and trigger transcription. Usage:

isActive

Type: boolean Whether a recording session is active (not idle or error). Equivalent to:
Use Case: Preventing auto-updates during recording

Events Listened

The hook automatically subscribes to these backend events:

recording-state-changed

Payload:
Description: Primary state synchronization event. Updates state and error.

recording-started

Payload: void Description: Legacy event, sets state to 'recording' and clears error.

recording-timeout

Payload: void Description: Recording exceeded maximum duration, sets state to 'stopping'.

recording-stopped-silence

Payload: void Description: Recording stopped due to silence detection.

transcription-started

Payload: void Description: Audio processing began, sets state to 'transcribing'.

Component Examples

Basic Recording Button


Recording Status Display


Keyboard Shortcuts


Error Handling


TypeScript Types


Implementation Details

Initial State Check

On mount, the hook fetches the current recording state from the backend:

Update Service Integration

The hook automatically notifies the update service to prevent auto-updates during recording:

See Also