/ws/stream when the clinician starts recording. Your application owns the microphone and clear Recording, Paused, and Generating states. When recording ends, send RU9G, close the WebSocket, and call End ambient session endpoint to start processing the ambient session’s generated content.Use this guide to design the recorder experience and sequence these operations correctly. For WebSocket handshake, PCM encoding, frame structure, and control-event details, see Stream Ambient audio and Ambient streaming wire format. Ambient and Form filling share the same wire format on
/ws/stream; this guide focuses on Ambient recorder UX.Create the Ambient Session
Add Visit Context
Open /ws/stream
Capture and Stream Audio
Handle Pause and Resume
EVENT PAUSE, EVENT RESUME, and EVENT KEEP_ALIVE messages when the clinician pauses or resumes.Send RU9G to Stop Recording
RU9G after the final PCM audio chunk.Close the WebSocket
RU9G is sent.Call the End Endpoint
Poll Status and Retrieve Content
Design the recorder experience
A custom ambient experience should make the recording state clear at every point. The clinician should always be able to tell whether audio is being captured. At minimum, provide:- Start to begin ambient recording indicating that the ambient session is active.
- Pause to temporarily stop capturing audio and show in the UI that the ambient session is paused.
- Resume to continue the same ambient session. If you are showing a timer, resume the timer when the ambient session is resumed.
- Stop to finish recording and start processing. Show in the UI that the ambient session is generating content.
Show the recording state clearly
Use a persistent recording indicator while the ambient session is capturing audio. When the clinician pauses, make the paused state equally clear. After Stop, move the UI to a Generating state rather than leaving the clinician in a Recording state while ambient content is processed.Keep microphone ownership clear
Do not stream Ambient and Dictation audio streams from the same device microphone at the same time. The two experiences use different streaming contracts and can contend for microphone access. Disable Dictation microphone while ambient session owns the microphone. Depending on your application flow, you may also keep it disabled while the ambient session is generating.Pause and resume
Pause and Resume should operate on the same ambient session. When the clinician pauses:- Send the
EVENTPAUSEmessage. - Stop sending audio.
- Continue sending
EVENTKEEP_ALIVEmessages at least every 5 seconds.
- Send the
EVENTRESUMEmessage. - Resume audio capture.
- Continue streaming audio on the same ambient session.
Stop the recording cleanly
Stopping an ambient session recording requires more than closing the WebSocket. After the final PCM audio chunk has been sent:- Send
RU9Gon the WebSocket. - Close the WebSocket.
- Call the Ambient
Endendpoint. - Poll the ambient session status.
- Retrieve the ambient session’s generated content after processing completes.
Audio capture requirements
For ambient session streaming, capture:- Channel: Mono
- Encoding: LINEAR16 PCM
- Sample rate: 16 kHz
- Send audio and control information according to the ambient session WebSocket wire format.
- For frame structure and handshake behavior, see Ambient streaming wire format. Keep those details in the streaming client implementation, not in the recorder UI layer.
- Plan for about one minute or longer of captured audio. Short or empty sessions may finish with a
skippedstatus after End.
Implementation flow
Use the following sequence in your application.Authenticate and Create the Session
Add Visit Context
Open the WebSocket
/ws/stream using the authentication pattern required by your client. See Audio streaming API.Stream Audio
Handle Pause and Resume
EVENT PAUSE and EVENT RESUME messages as the clinician pauses and resumes recording. While paused, send EVENT KEEP_ALIVE at least every 5 seconds.Stop and End the Session
RU9G, close the WebSocket, and call the End endpoint.Wait for Processing
What belongs in your application
Keep the responsibilities separated between your recorder UI and streaming client.Recorder UI
- Start, Pause, Resume, and Stop controls.
- Showing whether Ambient is Recording, Paused, or Generating.
- Managing microphone access.
- Preventing conflicting microphone use with Dictation.
- Moving the UI from Recording to Generating after Stop.
Streaming Client
- Opening
/ws/streamat the correct point in the session lifecycle. - Capturing and encoding audio in the required format.
- Sending audio frames.
- Sending control events (
EVENTmessages for pause, resume, and keep-alive). - Maintaining keep-alives while paused.
- Sending
RU9Gbefore closing the WebSocket.
Common mistakes to avoid
Opening the WebSocket Too Early
Opening the WebSocket Too Early
/ws/stream before the ambient session has been created and visit context has been added. Open it as part of the Start Ambient flow.Treating Socket Close as the End of the Session
Treating Socket Close as the End of the Session
RU9G, close the socket, and call the Ambient End endpoint.Stopping Keep-Alives While Paused
Stopping Keep-Alives While Paused
EVENT KEEP_ALIVE at least every 5 seconds while paused.Hiding the Recording State
Hiding the Recording State
Ending Very Short Sessions
Ending Very Short Sessions
skipped status.Implementation checklist
- Creates the ambient session before opening
/ws/stream. - Adds visit context before streaming begins.
- Clearly shows Recording, Paused, and Generating states.
- Supports Pause and Resume on the same ambient session.
- Sends
EVENTKEEP_ALIVEat least every 5 seconds while paused. - Keeps Ambient and Dictation from using the same microphone at the same time.
- Captures mono LINEAR16 PCM at 16 kHz.
- Sends
RU9Gafter the final audio. - Closes the WebSocket after sending
RU9G. - Calls the Ambient End endpoint after closing the socket.
- Polls session status after End.
- Handles the
skippedstatus for short or empty sessions.
Related guides
Stream Ambient Audio
Ambient Streaming Wire Format
Audio Capture Best Practices
Ambient vs Dictation Streaming
Available cookbooks
Available tutorials
Build an Ambient Streaming Client
Authenticate, create a session, stream PCM audio over WebSocket, and retrieve clinical note results.
Build Headless Ambient Recorder
Use Headless Web SDK hooks to authenticate, create an ambient session, and control recording in React.