For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Ask AIPlaygroundLoginFree API Key
HomeAPI ReferenceVoice AgentSpeech-to-TextText-to-SpeechIntelligenceSelf-Hosted Deployments
HomeAPI ReferenceVoice AgentSpeech-to-TextText-to-SpeechIntelligenceSelf-Hosted Deployments
    • Getting Started with Speech to Text
  • Pre-Recorded Audio
    • Getting Started
    • Feature Overview
    • Template Apps
  • Streaming Audio
      • Getting Started
      • Feature Overview
      • Live Streaming Starter Kit
      • Template Apps
        • Close Stream
        • Finalize
        • Audio Keep Alive
    • Compare Flux to Nova-3
  • Models and Languages
    • Models & Languages Overview
    • Languages Support
    • Language Detection
    • Multilingual Codeswitching
    • Model Options
    • Version
  • Formatting
    • Speaker Diarization
    • Dictation
    • Filler Words
    • Measurements
    • Numerals
    • Paragraphs
    • Profanity Filtering
    • Punctuation
    • Redaction
    • Smart Formatting
    • Supported Entity Types
    • Utterances
    • Utterance Split
  • Custom Vocabulary
    • Find and Replace
    • Keyterm Prompting
    • Keywords
    • Search
  • Media Input Settings
    • Channels
    • Encoding
    • Multichannel
    • Sample Rate
  • Results Processing
    • Understanding Word Confidence Scores
    • STT Callback
    • STT Tagging
    • Extra Metadata
  • Migrating
    • Migrating From Amazon Web Services (AWS) Transcribe to Deepgram
    • Migrating From Google Speech-to-Text (STT) to Deepgram
    • Migrating From OpenAI Whisper to Deepgram
    • Migrating from AssemblyAI Speech-to-Text to Deepgram
LogoLogo
Ask AIPlaygroundLoginFree API Key
On this page
  • Purpose
  • Example Payloads
  • Language-Specific Implementations
Streaming AudioTranscription (Nova-3)Control Messages

Close Stream

Send a CloseStream message to close the WebSocket stream.
Was this page helpful?
Previous

Finalize

Send a Finalize message to flush the WebSocket stream.
Next
Built with
Streaming:Nova

Use the CloseStream message to close 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 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.

Example Payloads

To send the CloseStream message, you need to send the following JSON message to the server:

JSON
1{
2 "type": "CloseStream"
3}

Upon receiving the CloseStream message, the server will process all remaining audio data and return the following:

JSON
1{
2 "type": "Metadata",
3 "transaction_key": "deprecated",
4 "request_id": "8c8ebea9-dbec-45fa-a035-e4632cb05b5f",
5 "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
6 "created": "2024-08-29T22:37:55.202Z",
7 "duration": 0.0,
8 "channels": 0
9}

Language-Specific Implementations

Below are code examples to help you get started using CloseStream.

1const WebSocket = require("ws");
2
3// Assuming 'headers' is already defined for authorization
4const ws = new WebSocket("wss://api.deepgram.com/v1/listen", { headers });
5
6ws.on('open', function open() {
7 // Construct CloseStream message
8 const closeStreamMsg = JSON.stringify({ type: "CloseStream" });
9
10 // Send CloseStream message
11 ws.send(closeStreamMsg);
12});