Finalize
Use the Finalize
message to flush the WebSocket stream. This forces the server to immediately process any unprocessed audio data and return the final transcription results.
Purpose
In real-time audio processing, there are scenarios where you may need to force the server to process (or flush) all unprocessed audio data immediately. Deepgram supports a Finalize
message to handle such situations, ensuring that interim results are treated as final.
Example Payloads
To send the Finalize
message, you need to send the following JSON message to the server:
You can optionally specify a channel
field to finalize a specific channel. If the channel
field is omitted, all channels in the audio will be finalized. Note that channel indexing starts at 0, so to finalize only the first channel you need to send:
Upon receiving the Finalize message, the server will process all remaining audio data and return the final results. You may receive a response with the from_finalize
attribute set to true
, indicating that the finalization process is complete. This response typically occurs when there is a noticeable amount of audio buffered in the server.
If you specified a channel
to be finalized, use the response’s channel_index
field to check which channel was finalized.
In most cases, you will receive this response, but it is not guaranteed if there is no significant amount of audio data to process.
Language-Specific Implementations
Below are code examples to help you get started using Finalize
.
Sending a Finalize
message in JSON Format
These snippets demonstrate how to construct a JSON message containing the “Finalize” type and send it over the WebSocket connection in each respective language.
Streaming Examples
Here are more complete examples that make a streaming request and use Finalize. Try running these examples to see how Finalize can be sent to Deepgram, forcing the API to process all unprocessed audio data and immediately return the results.