Audio Keep Alive
Use the KeepAlive
message to keep your WebSocket connection open during periods of silence, preventing timeouts and optimizing costs.
Purpose
Send a KeepAlive
message every 3-5 seconds to prevent the 10-second timeout that triggers a NET-0001
error and closes the connection. Ensure the message is sent as a text WebSocket frame—sending it as binary may result in incorrect handling and potential connection issues.
Example Payloads
To send the KeepAlive
message, send the following JSON message to the server:
The server will not send a response back when you send a KeepAlive
message. If no audio data or KeepAlive
messages are sent within a 10-second window, the connection will close with a NET-0001
error.
Language Specific Implementations
Below are code examples to help you get started using KeepAlive
.
Sending a KeepAlive
message in JSON Format
Construct a JSON message containing the KeepAlive
type and send it over the WebSocket connection in each respective language.
Streaming Examples
Make a streaming request and use KeepAlive
to keep the connection open.
Using Deepgram SDKs
Deepgram’s SDKs make it easier to build with Deepgram in your preferred language. For more information on using Deepgram SDKs, refer to the SDKs documentation in the GitHub Repository.
Word Timings
Word timings in streaming transcription results are based on the audio stream itself, not the lifetime of the WebSocket connection. If you send KeepAlive messages without any audio payloads for a period of time, then resume sending audio, the timestamps will continue from where the audio left off—not from when the KeepAlive messages were sent.
Here is an example timeline demonstrating the behavior.