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
| State | Description |
|---|---|
idle | No recording in progress |
starting | Initializing microphone |
recording | Actively recording audio |
stopping | Finalizing audio file |
transcribing | Processing audio to text |
error | An error occurred (check error field) |
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:
- Invokes
start_recordingTauri command - State updates are handled by backend events (not the return value)
- Errors are emitted via
recording-state-changedevents
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:
Events Listened
The hook automatically subscribes to these backend events:recording-state-changed
Payload: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
- Audio Commands - Backend recording commands
- usePermissions Hook - Permission management
- useModelManagement Hook - Model selection