Close Stream
Learn how to send Deepgram a CloseStream message, which closes the websocket stream.
In real-time audio processing, there are scenarios where you may need to force the server to close. Deepgram supports a CloseStream
message to handle such situations. This message will send a shutdown command to the server instructing it to finish processing any cached data, send the response to the client, send a summary metadata object, and then terminate the WebSocket connection.
What is the CloseStream
Message
The CloseStream
message is a JSON command that you send to the Deepgram server, instructing it close the connection. This is particularly useful in scenarios where you need to immediately shutdown the websocket connection and process and return all data to the client.
Sending CloseStream
To send the CloseStream
message, you need to send the following JSON message to the server:
CloseStream
Confirmation
Upon receiving the CloseStream
message, the server will process all remaining audio data and return the following:
Language-Specific Implementations
Conclusion
In summary, when dealing with real-time audio processing, there are situations where it may be necessary to forcibly close the server connection. Deepgram provides the CloseStream
message to facilitate this process. By sending this message, the server is instructed to complete processing any buffered data, return the final response along with summary metadata, and then gracefully terminate the WebSocket connection. This ensures a controlled shutdown, preserving the integrity of the data and the overall process.