Updated
- The
useAmbientSessionhook returns asessionTypeproperty so you can tell whether the session is online or offline. - Ambient recording accepts an optional microphone
deviceIdthroughconfig.audio(v0.3.1). Pass aMediaDeviceInfo.deviceIdfrom your own . Changing the mic while recording requirespause()thenresume(). Refer to Select a microphone.
useAmbientSession hook allows you to control the ambient recording workflow after you have an ambientSessionId. It exposes start, pause, resume, cancel, and submit, optional setSessionContext, cancelRemote, endRemote, session status, sessionType (online or offline), optional onSessionTerminatedByPeer, and optional real-time audio chunks for visualizations. You can also pass an optional microphone deviceId so the recording uses a specific microphone when it starts or resumes.
Configuration
Pass theambientSessionId you received from useAmbient after session.isSuccess is true (refer to Create ambient session). Run the hook under PlatformClientProvider.
Refer to Platform client and provider for more information.
Common use cases
Control the Recording Lifecycle
Use the recording control methods to match the behavior of your application’s recording experience:
start()to begin recording.pause()to temporarily stop audio capture.resume()to continue a paused recording.cancel()to discard the current session.submit()to finalize and submit the recording for processing.
Select a Microphone for Ambient Capture
Pass
config.audio.deviceId with a MediaDeviceInfo.deviceId from your own navigator.mediaDevices.enumerateDevices() flow. Your app owns how you design and implement the microphone picker UI and device list. When deviceId is omitted, the recording uses the browser default microphone.The selected device is applied when recording starts or resumes. Changing deviceId while recording does not switch the microphone that is already in use. Call pause(), then resume(), after you update config.audio.deviceId. Refer to Select a microphone guide for more details.Attach Clinical Context to a Session
Use
setSessionContext() to associate patient, provider, and visit metadata with the active session.Call setSessionContext() after start() and before submit() to ensure the metadata is included with the session. For supported fields and examples, refer to Session context.Support Online and Offline Session Flows
Read
sessionType to determine how the session is running:"online"for real-time workflows."offline"for deferred or asynchronous processing workflows.
Process Audio Waveform Data
Use
onAudioChunkAvailable to receive streamed audio chunks during recording. Audio data is returned as batched Int16Array chunks.Optionally configure config.audioBatchSize to control the batch size and frequency of audio chunk delivery.Build Responsive Session Status UI
Use the returned session state values to drive UI behavior throughout the recording workflow:
sessionStatusfor the server-side session lifecycle (for examplecreated,submitted,completed).sessionTypefor online versus offline messaging.
idle, recording, paused) for Start, Pause, and Resume. Do not use sessionStatus alone for recording versus paused.Resolve a Remote Session Conflicts
Use
cancelRemote or endRemote with the blocking session id from a sessionAlreadyExists create error when another Suki product holds the active ambient session. Then retry create. Refer to Handle ambient session conflicts.Handle Peer Session Termination
Pass
onSessionTerminatedByPeer so your UI can clear recording controls when another product cancels or ends the live session. Update UI only. Do not call local cancel, submit, or remote clear APIs for that direction.useAmbientSession hook
Usage
CalluseAmbientSession with an object that includes ambientSessionId and optional config, onAudioChunkAvailable, and onSessionTerminatedByPeer.
Returns
The hook returns control methods, session status,sessionType, and related fields. For parameter and return shapes refer to Configuration and What it returns guides.
How recording works
- Pass the session ID: Provide the
ambientSessionIdfromuseAmbient. - Configure options: Optionally set
config.audioBatchSize,config.audio.deviceId, andonAudioChunkAvailablefor microphone selection and real-time audio batches. - Use the controls: Call
start,pause,resume,cancel, andsubmitto move through the lifecycle your UI needs.