#websocket 1011 Live Streaming

1 messages · Page 1 of 1 (latest)

wary jackal
#

2025-04-25 16:17:00,974 - asyncio - ERROR - Task exception was never retrieved
future: <Task finished name='Task-228' coro=<LiveTranscription._start() done, defined at /root/telephony-epicode/venv/lib/python3.10/site-packages/deepgram/transcription.py:169> exception=ConnectionClosedError(Close(code=1011, reason='Deepgram did not provide a response message within the timeout window. See https://dpgr.am/net0000'), Close(code=1011, reason='Deepgram did not provide a response message within the timeout window. See https://dpgr.am/net0000'), True)>
Traceback (most recent call last):
File "/root/telephony-epicode/venv/lib/python3.10/site-packages/deepgram/transcription.py", line 213, in _start
await self._socket.send(body)
File "/root/telephony-epicode/venv/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 635, in send
await self.ensure_open()
File "/root/telephony-epicode/venv/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 948, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: received 1011 (internal error) Deepgram did not provide a response message within the timeout window. See https://dpgr.am/net0000; then sent 1011 (internal error) Deepgram did not provide a response message within the timeout window. See https://dpgr.am/net0000

Deepgram

Power enterprise voice solutions with Deepgram’s Speech-to-Text, Text-to-Speech, and Voice Agent APIs. Real-time, accurate, and built for scale.

Deepgram

Power enterprise voice solutions with Deepgram’s Speech-to-Text, Text-to-Speech, and Voice Agent APIs. Real-time, accurate, and built for scale.

tacit larkBOT
#

Hey there! This channel allows you to ask Kapa.ai for assistance. But it looks like you haven't connected your Discord profile to your Deepgram account yet. You can do so at https://community.deepgram.com - by doing so, you'll be able to ask questions in #1115960287183511643 if you need human assistance!

gusty glenBOT
#

Hi @wary jackal. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error you are seeing—ConnectionClosedError(Close(code=1011, reason='Deepgram did not provide a response message within the timeout window. See <https://dpgr.am/net0000'>)—indicates that Deepgram's WebSocket connection was closed because the service did not send a response message within the expected timeout window.

According to Deepgram's documentation, a 1011 code with the NET-0000 payload means:

The service has not transmitted a Text frame to the client within the timeout window. This may indicate an internal issue with Deepgram’s systems, or Deepgram may have not received enough audio data to transcribe a frame.
Debugging Websocket Errors

What this means and what you can do:

  • This error can occur if Deepgram is unable to generate a transcript for the audio data you are sending before the system times out.
  • It may be due to an internal issue on Deepgram’s side, or it could be that not enough audio data was received to process a transcription.
  • If you are consistently seeing this error, first check Deepgram’s status page to ensure their systems are operational.
  • If Deepgram’s systems are operational and you are still experiencing this issue, it may be necessary to contact Deepgram Support for further assistance, as this could indicate a deeper issue with the service or your integration.

Additional troubleshooting steps:

#
  • Ensure that you are sending valid and sufficient audio data to Deepgram.
  • If your audio stream is very short or intermittent, consider sending a CloseStream message when you are done sending audio, to prompt Deepgram to process what it has received.
  • If you are using KeepAlive messages, note that they do not substitute for actual audio data; Deepgram needs to receive audio to process and respond.

If you need more specific guidance, please provide details about your audio stream (format, duration, how you are sending it) and any relevant code snippets.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen do share the details about audio stream format duration and other relevant things

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I'm sorry, but the knowledge sources you provided do not contain specific details about your audio stream's format, duration, or other relevant parameters. To effectively troubleshoot the 1011 WebSocket error with Deepgram, you would need to share information such as:

  • Audio format (e.g., linear16, mulaw, opus, etc.)
  • Sample rate (e.g., 8000 Hz, 16000 Hz)
  • Encoding (e.g., raw PCM, WAV, etc.)
  • Channel count (mono or stereo)
  • Duration of the audio being streamed
  • How you are sending the audio (e.g., chunk size, interval, whether you are sending silence, etc.)

If you can provide these details, it will be much easier to diagnose the issue. The knowledge sources emphasize that mismatches in encoding, unsupported formats, or not sending enough audio data are common causes for connection errors like 1011. You can also inspect your logs to see how much audio data is actually being sent and received by Deepgram, as this is a frequent troubleshooting step recommended in the documentation and community discussions Using Lower-Level Websockets with the Streaming API Streaming STT with no transcription and zero audio duration.

If you need further help, please provide the above details about your audio stream.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen here is the code which am using

async def connect_to_deepgram(self):
try:
print("Connect to deepgram function came ")
logger.info(
f"Connecting to deepgram Session ID {self.sessionId} and language {self.language}"
)

        self.socket = await self.dg_client.transcription.live(
            {
                "punctuate": True,
                "interim_results": True,
                "language": self.language,
                "sample_rate": 8000,
                "encoding": "linear16",
            }
        )
        self.socket.registerHandler(
            self.socket.event.CLOSE,
            lambda c: print(f"Connection closed with code {c}."),
        )
        self.socket.registerHandler(
            self.socket.event.TRANSCRIPT_RECEIVED, self.get_transcript
        )
    except Exception as e:
        raise Exception(f"Could not open socket: {e}")
gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Based on your code, you are configuring the Deepgram live transcription WebSocket with the following audio stream parameters:

  • Language: (set by self.language)
  • Sample rate: 8000 Hz
  • Encoding: linear16 (PCM)
  • Punctuation: enabled
  • Interim results: enabled

What this means:

  • You are sending audio in raw linear16 PCM format at 8000 Hz, which is a common telephony audio format.
  • The language is set dynamically (make sure it matches Deepgram’s supported language codes).
  • You are requesting both interim and final transcription results.

Important notes from the knowledge sources:

  • Deepgram requires that the encoding and sample_rate parameters match the actual audio data you are sending. If there is a mismatch, or if the audio is not being sent correctly, the connection may be closed with errors like 1011 or 1008 Using Lower-Level Websockets with the Streaming API.
  • If you do not send audio data within ~10 seconds of opening the WebSocket, Deepgram will close the connection with a 1011 error Troubleshooting 1011 - NET-0001 WebSocket Errors.
  • The audio stream should be continuous; sending only a small amount of audio or pausing for long periods can also cause the connection to close.
#

If you are still encountering 1011 errors:

  • Double-check that the audio you are sending is actually linear16 PCM at 8000 Hz.
  • Ensure you are sending audio data promptly after opening the connection and continuously during the session.
  • If your audio stream is short, consider sending a CloseStream message when finished to prompt Deepgram to process the received audio.
  • If you are still having issues, capture a sample of your audio and verify its format, or try sending it to Deepgram using a cURL request as described in the troubleshooting docs.

If you need more help, please provide details about how you are capturing and sending the audio data, and whether you have verified the audio format matches your configuration Debugging Websocket Errors.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

Can you give me the updated code based on new deepgram SDK @gusty glen

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Certainly! Here is an updated example for connecting to Deepgram’s live transcription using the latest Python SDK (v3), based on the official migration and streaming documentation. This code uses the async/await interface and matches your use case (linear16, 8000 Hz, language selection, etc.):

from deepgram import DeepgramClient, LiveOptions, LiveTranscriptionEvents

# Initialize the Deepgram client with your API key
deepgram = DeepgramClient("<YOUR_DEEPGRAM_API_KEY>")

async def get_transcript(result, **kwargs):
    sentence = result.channel.alternatives[0].transcript
    if len(sentence) == 0:
        return
    print(f"Transcription: {sentence}")

async def connect_to_deepgram(language):
    options = LiveOptions(
        punctuate=True,
        interim_results=True,
        language=language,
        sample_rate=8000,
        encoding="linear16",
    )

    # Create the async live connection
    dg_connection = deepgram.listen.asynclive.v("1")

    # Register event handlers
    dg_connection.on(LiveTranscriptionEvents.Transcript, get_transcript)
    dg_connection.on(LiveTranscriptionEvents.Close, lambda c: print(f"Connection closed with code {c}."))
    dg_connection.on(LiveTranscriptionEvents.Error, lambda e: print(f"Error: {e}"))

    # Start the connection
    await dg_connection.start(options)
    return dg_connection

Key points:

  • Use LiveOptions to specify your parameters.
  • Use deepgram.listen.asynclive.v("1") to create the async live connection.
  • Register your event handlers using the on method and the LiveTranscriptionEvents enum.
  • Start the connection with await dg_connection.start(options).
#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

yes do share me the full example @gusty glen

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

tacit larkBOT
#

Hey there, it looks like you've been talking with Kapa for a bit. If you need additional help, you should consider moving to #1115960287183511643 where our team can answer your query.

gusty glenBOT
#

Certainly! Here is a full example of live streaming audio to Deepgram using the latest Python SDK (v3), based on the official documentation and code samples. This example uses pyaudio to capture microphone input and streams it to Deepgram for real-time transcription. The code is adapted from the official Deepgram Python SDK examples and the streaming transcription documentation.

import pyaudio
import asyncio
from deepgram import DeepgramClient, LiveOptions, LiveTranscriptionEvents

# Replace with your Deepgram API key
DEEPGRAM_API_KEY = "<YOUR_DEEPGRAM_API_KEY>"

# Audio stream configuration
FORMAT = pyaudio.paInt16
CHANNELS = 1
SAMPLE_RATE = 8000
FRAMES_PER_BUFFER = 3200

# Initialize Deepgram client
deepgram = DeepgramClient(DEEPGRAM_API_KEY)

async def main():
    # Set up Deepgram live transcription options
    options = LiveOptions(
        model="nova-2",  # or your preferred model
        language="en-US",
        punctuate=True,
        interim_results=True,
        encoding="linear16",
        sample_rate=SAMPLE_RATE,
        channels=CHANNELS,
    )

    # Create the async live connection
    dg_connection = deepgram.listen.asynclive.v("1")

    # Event handler for receiving transcripts
    async def on_transcript(self, result, **kwargs):
        sentence = result.channel.alternatives[0].transcript
        if sentence:
            print(f"Transcript: {sentence}")
#

Register event handlers

dg_connection.on(LiveTranscriptionEvents.Transcript, on_transcript)
dg_connection.on(LiveTranscriptionEvents.Close, lambda c, **kwargs: print(f"Connection closed with code {c}"))
dg_connection.on(LiveTranscriptionEvents.Error, lambda e, **kwargs: print(f"Error: {e}"))

# Start the Deepgram connection
await dg_connection.start(options)

# Set up PyAudio stream
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=CHANNELS, rate=SAMPLE_RATE, input=True, frames_per_buffer=FRAMES_PER_BUFFER)

print("Start speaking... (Press Ctrl+C to stop)")

try:
    while True:
        data = stream.read(FRAMES_PER_BUFFER, exception_on_overflow=False)
        await dg_connection.send(data)
except KeyboardInterrupt:
    print("Stopping transcription...")
finally:
    await dg_connection.finish()
    stream.stop_stream()
    stream.close()
    p.terminate()

if name == "main":
asyncio.run(main())


**Notes:**
- This example uses `pyaudio` to capture audio from your microphone in real time.
- The audio is sent in chunks to Deepgram using the async SDK.
- Transcripts are printed as they are received.
- Make sure your audio format (`linear16`, 8000 Hz, mono) matches the options you set for Deepgram.
- Replace `<YOUR_DEEPGRAM_API_KEY>` with your actual API key.

**References:**  
- [Live Streaming Audio Transcription Example](<https://developers.deepgram.com/docs/python-sdk-streaming-transcription#where-to-find-additional-examples>)
- [WebSocket Microphone Example](<https://github.com/deepgram/deepgram-python-sdk/tree/main/examples/speech-to-text/websocket/microphone>)
#

If you need to stream from a file or another source, let me know!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen got the below error
2025-04-26 17:14:54,507 - deepgram.clients.common.v1.abstract_sync_websocket - ERROR - WebSocketException in AbstractSyncWebSocketClient.start: server rejected WebSocket connection: HTTP 403
ListenWebSocketClient.start failed
2025-04-26 17:14:54,507 - deepgram.clients.common.v1.abstract_sync_websocket - ERROR - ListenWebSocketClient.start failed
Traceback Traceback (most recent call last):
File "/root/telephony-epicode/epicodeConsumer.py", line 814, in connect_to_deepgram_updated
await self.socket.start(config)
TypeError: object bool can't be used in 'await' expression

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Your error message indicates two main issues:

1. HTTP 403 Forbidden on WebSocket Connection

WebSocketException in AbstractSyncWebSocketClient.start: server rejected WebSocket connection: HTTP 403
ListenWebSocketClient.start failed

A 403 error means the Deepgram server is rejecting your WebSocket connection due to invalid credentials or permissions. The most common causes are:

  • Incorrect API Key: Double-check that your API key is correct, has no extra spaces, and is not expired or revoked.
  • API Key Format: The API key should not have dashes and should be passed as token <YOUR_DEEPGRAM_API_KEY> in the Authorization header, not as API_KEY <key> or any other format Debugging Websocket Errors.
  • Insufficient Permissions: Ensure your API key has the necessary permissions for live transcription.
  • Endpoint URL: Make sure you are connecting to the correct Deepgram WebSocket endpoint (e.g., wss://api.deepgram.com/v1/listen).

If you are using the Python SDK, ensure you are initializing the client with the correct API key and not overriding headers in a way that breaks authentication.

2. TypeError: object bool can't be used in 'await' expression

TypeError: object bool can't be used in 'await' expression

This error means you are trying to await a function or method that returns a boolean, not a coroutine. In the latest Deepgram Python SDK (v3), the start() method for the live connection is asynchronous and should be awaited, but if you are using a synchronous client or the wrong method, you might get this error.

#

Check the following:

  • If you are using the async client, use await dg_connection.start(options).
  • If you are using the sync client, do not use await—just call dg_connection.start(options).

Example for async:

await dg_connection.start(options)

Example for sync:

dg_connection.start(options)

What to do next

  • Double-check your API key and how you pass it to the Deepgram client.
  • Make sure you are using the correct method (await for async, no await for sync).
  • If you continue to get a 403, try generating a new API key from the Deepgram Console and use that.

For more details on debugging WebSocket connection errors and correct API key usage, see the official documentation:
Debugging Websocket Errors

If you need further help, please share how you are initializing the Deepgram client and how you are calling the start() method.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

Got the below error for the new codce

WebSocketException in AbstractSyncWebSocketClient.start: server rejected WebSocket connection: HTTP 403
ListenWebSocketClient.start failed

@gusty glen

wary jackal
#

hi @gusty glen can you help me

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Of course, I'm here to help! If you have a specific question or issue related to Deepgram—such as API usage, troubleshooting WebSocket errors, SDK integration, or anything else—please provide more details about your problem. The more information you share (error messages, code snippets, audio format, etc.), the better I can assist you.

If you need immediate troubleshooting help or have a complex issue, you can also reach out directly to Deepgram Support.

If you have any questions or need help troubleshooting, please contact Deepgram Support here.


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen i want a similar code with lastest deepgram sdk version for testing Speech to text
async def connect_to_deepgram(self):
try:
print("Connect to deepgram function came ")
logger.info(
f"Connecting to deepgram Session ID {self.sessionId} and language {self.language}"
)

        self.socket = await self.dg_client.transcription.live(
            {
                "punctuate": True,
                "interim_results": True,
                "language": self.language,
                "sample_rate": 8000,
                "encoding": "linear16",
            }
        )
        self.socket.registerHandler(
            self.socket.event.CLOSE,
            lambda c: print(f"Connection closed with code {c}."),
        )
        self.socket.registerHandler(
            self.socket.event.TRANSCRIPT_RECEIVED, self.get_transcript
        )
    except Exception as e:
        raise Exception(f"Could not open socket: {e}")
gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I'm happy to help! However, your last message ("helpe here") does not include any specific details or a question about Deepgram.

If you are experiencing an issue or have a question about using Deepgram (such as API errors, SDK usage, audio streaming, or integration), please provide more information or clarify your request. This will help me give you the most accurate and relevant assistance based on the available knowledge sources.

If you need immediate troubleshooting or have a complex issue, you can also reach out directly to Deepgram Support.

If you have any questions or need help troubleshooting, please contact Deepgram Support here.


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen i want a similar code with lastest deepgram sdk version for testing Speech to text
async def connect_to_deepgram(self):
try:
print("Connect to deepgram function came ")
logger.info(
f"Connecting to deepgram Session ID {self.sessionId} and language {self.language}"
)

        self.socket = await self.dg_client.transcription.live(
            {
                "punctuate": True,
                "interim_results": True,
                "language": self.language,
                "sample_rate": 8000,
                "encoding": "linear16",
            }
        )
        self.socket.registerHandler(
            self.socket.event.CLOSE,
            lambda c: print(f"Connection closed with code {c}."),
        )
        self.socket.registerHandler(
            self.socket.event.TRANSCRIPT_RECEIVED, self.get_transcript
        )
    except Exception as e:
        raise Exception(f"Could not open socket: {e}")
gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Here is an updated example for testing Speech-to-Text using the latest Deepgram Python SDK (v3), following the official documentation and migration guide. This code uses the new event system and async/await interface, and matches your original intent:

from deepgram import DeepgramClient, LiveOptions, LiveTranscriptionEvents

# Initialize the Deepgram client with your API key
deepgram = DeepgramClient("<YOUR_DEEPGRAM_API_KEY>")

async def get_transcript(result, **kwargs):
    sentence = result.channel.alternatives[0].transcript
    if sentence:
        print(f"Transcription: {sentence}")

async def connect_to_deepgram(session_id, language):
    print("Connect to deepgram function called")
    print(f"Connecting to Deepgram Session ID {session_id} and language {language}")

    options = LiveOptions(
        punctuate=True,
        interim_results=True,
        language=language,
        sample_rate=8000,
        encoding="linear16",
    )

    # Create the async live connection
    dg_connection = deepgram.listen.asynclive.v("1")

    # Register event handlers
    dg_connection.on(LiveTranscriptionEvents.Transcript, get_transcript)
    dg_connection.on(LiveTranscriptionEvents.Close, lambda c, **kwargs: print(f"Connection closed with code {c}"))
    dg_connection.on(LiveTranscriptionEvents.Error, lambda e, **kwargs: print(f"Error: {e}"))

    # Start the connection
    await dg_connection.start(options)
    return dg_connection

How this matches your original code:

  • Uses the latest SDK's async/await interface and event system.
  • Registers event handlers for transcript, close, and error events.
  • Uses LiveOptions for configuration, matching your parameters.
  • Returns the connection object so you can send audio with await dg_connection.send(audio_chunk).
#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen getting the below error
Connecting to Deepgram Session ID 2ea7065d-3326-467e-937b-7c6927a6e236 and language en-US
WebSocketException in AbstractAsyncWebSocketClient.start: server rejected WebSocket connection: HTTP 403
2025-04-27 16:40:22,437 - deepgram.clients.common.v1.abstract_async_websocket - ERROR - WebSocketException in AbstractAsyncWebSocketClient.start: server rejected WebSocket connection: HTTP 403
AsyncListenWebSocketClient.start failed
2025-04-27 16:40:22,438 - deepgram.clients.common.v1.abstract_async_websocket - ERROR - AsyncListenWebSocketClient.start failed

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The error message server rejected WebSocket connection: HTTP 403 means that Deepgram is refusing your connection due to an authentication or permission issue. According to the official Deepgram documentation and community discussions, the most common causes for a 403 error are:

  • Invalid API Key: Double-check that your API key is correct, has no extra spaces, and is not expired or revoked.
  • API Key Format: The API key should be passed as token <YOUR_DEEPGRAM_API_KEY> in the Authorization header. If you are using the Deepgram SDK and providing the key as shown in the examples, this should be handled for you Debugging Websocket Errors.
  • Insufficient Permissions: Ensure your API key has the necessary permissions for live transcription.
  • Endpoint URL: Make sure you are connecting to the correct Deepgram WebSocket endpoint (e.g., wss://api.deepgram.com/v1/listen).

A Deepgram maintainer also confirmed in a similar case that a 403 "almost always means there is something wrong with your Deepgram API key. Did you set it in the code? If so, make sure it's the correct value. It should not have any dashes in it" "403 error in streaming connection".

#

What you should do:

  1. Regenerate your API key from the Deepgram Console and use the new key.
  2. Make sure you are not accidentally using a revoked or expired key.
  3. Ensure you are not overriding the authentication headers in your code.
  4. If you are still seeing the error, try running a basic connection test using the Deepgram streaming test suite to rule out issues with your environment How can I troubleshoot my WebSocket errors?.

If after these steps you still encounter the 403 error, please provide the exact way you are initializing the Deepgram client and how you are passing the API key, as this will help further diagnose the issue.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen in deepgram logs i see this Error: "Project does not have access to the requested model."

what does this mean ?

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The error message "Project does not have access to the requested model." means that the Deepgram API key or project you are using does not have permission to use the specific model you requested. This can happen if:

  • The model is restricted to certain users or plans.
  • Your project has not been granted access to that model.
  • You are trying to use a model that is in beta or requires special access.

For example, if you try to use a medical or language-specific model without having access, you will see this error. The official documentation confirms that a 403 Forbidden with this message indicates your project does not have access to the requested model Deepgram API Errors.

To resolve this, you may need to request access to the model or use a model that your project is authorized for. If you believe you should have access, contact Deepgram support or your account representative.

Example error response:

{
  "err_code":"INSUFFICIENT_PERMISSIONS",
  "err_msg":"Project does not have access to the requested model.",
  "request_id":"uuid"
}

Deepgram API Errors

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen how to solve this issue
ConnectionClosed in AbstractAsyncWebSocketClient._listening with code 1011: Deepgram did not receive audio data or a text message within the timeout window. See https://dpgr.am/net0001
2025-04-27 16:49:49,452 - deepgram.clients.common.v1.abstract_async_websocket - ERROR - ConnectionClosed in AbstractAsyncWebSocketClient._listening with code 1011: Deepgram did not receive audio data or a text message within the timeout window. See https://dpgr.am/net0001
Error: <deepgram.clients.listen.v1.websocket.async_client.AsyncListenWebSocketClient object at 0x7f07a26a9030>

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

The error ConnectionClosed in AbstractAsyncWebSocketClient._listening with code 1011: Deepgram did not receive audio data or a text message within the timeout window. See <https://dpgr.am/net0001> means that Deepgram closed your WebSocket connection because it did not receive any audio data or a text message (such as a KeepAlive or CloseStream message) within the required timeout window.

How to solve this issue:

  1. Send Audio Promptly:
    Deepgram requires that you send audio data within approximately 10 seconds of opening the WebSocket connection. If no audio is received in that time, the connection will be closed with this error. Make sure your code starts streaming audio data immediately after the connection is established Debugging Websocket Errors.

  2. Continuous Audio Streaming:
    If you pause or stop sending audio for more than 10 seconds during an active session, Deepgram will also close the connection. Ensure your audio stream is continuous, or use KeepAlive messages if you need to keep the connection open during short pauses What is the KeepAlive message?.

  3. Send a CloseStream Message When Done:
    If your audio stream is short or you are done sending audio, send a CloseStream message ({ "type": "CloseStream" }) to tell Deepgram to process the received audio and close the connection gracefully Debugging Websocket Errors.

#
  1. Check Audio Format and Data:
    Make sure the audio you are sending matches the format and encoding specified in your connection options. Mismatches or sending no data at all will also cause this error Using Lower-Level Websockets with the Streaming API.

If you have implemented these steps and still encounter the error, there may be a network issue or a problem with how your audio data is being captured and sent.

If you have any questions or need help troubleshooting, please contact Deepgram Support here.


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen how does event handlers work here ?

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

In the latest Deepgram Python SDK, event handlers are used to respond to specific events that occur during a live transcription session over WebSockets. You register these handlers using the .on() method of the live connection object, associating each event type with a callback function.

How it works:

  • When you create a live transcription connection (e.g., with deepgram.listen.asynclive.v("1")), you can register event handlers for events such as receiving a transcript, connection close, or errors.
  • Each event type is represented by an enum value from LiveTranscriptionEvents.
  • The callback function you provide will be called automatically when the corresponding event occurs, and it will receive event-specific data as arguments.

Example from the knowledge sources:

from deepgram import DeepgramClient, LiveOptions, LiveTranscriptionEvents

deepgram = DeepgramClient("<YOUR_DEEPGRAM_API_KEY>")
dg_connection = deepgram.listen.asynclive.v("1")

async def on_transcript(result, **kwargs):
    sentence = result.channel.alternatives[0].transcript
    if sentence:
        print(f"Transcription: {sentence}")

dg_connection.on(LiveTranscriptionEvents.Transcript, on_transcript)
dg_connection.on(LiveTranscriptionEvents.Close, lambda c, **kwargs: print(f"Connection closed with code {c}"))
dg_connection.on(LiveTranscriptionEvents.Error, lambda e, **kwargs: print(f"Error: {e}"))
  • Here, on_transcript will be called every time a new transcript is received.
  • The lambda functions handle the Close and Error events.

Supported events include:

  • LiveTranscriptionEvents.Transcript – when a transcript is received
  • LiveTranscriptionEvents.Close – when the connection is closed
  • LiveTranscriptionEvents.Error – when an error occurs
#

This event-driven approach allows you to react to real-time transcription results and connection state changes in your application logic Python SDK Streaming Transcription.

If you need more details or a full list of events, let me know!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

@gusty glen i have registered an event on transcript but that method is not getting called what could be the problem
this is happening after i receive a chunk of audio from telephony

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

If your event handler for LiveTranscriptionEvents.Transcript is not being called after sending a chunk of audio from telephony, there are several possible causes based on the knowledge sources:

  1. Audio Format or Encoding Mismatch:
    Deepgram requires that the audio format and encoding you specify in your LiveOptions exactly match the audio data you are sending. For example, if you specify "encoding": "linear16" and "sample_rate": 8000, but your audio is actually in a different format or sample rate, Deepgram may not be able to process it, resulting in no transcript events being fired. This is a common issue when streaming telephony audio, as formats like mulaw or base64-encoded audio are often used and must be decoded and matched to the specified options Empty transcript when streaming RTP audio, No response received from deepgram streaming websockets.

  2. No or Insufficient Audio Data Sent:
    If Deepgram does not receive enough audio data, or if the data is not sent promptly after opening the connection, it may not generate any transcript events. This can also lead to connection closure with a 1011 error. Make sure you are sending valid audio data immediately after the connection is established and that the data is not empty or silent Debugging Websocket Errors.

#
  1. Incorrect Event Registration:
    Ensure that you are registering the event handler before starting the connection and sending audio. The handler should be registered using the .on() method with the correct event type (LiveTranscriptionEvents.TranscriptPython SDK Streaming Transcription.

  2. Audio Data Not Properly Decoded:
    If you are receiving audio from telephony systems (like Twilio or Asterisk), the audio payload may be base64-encoded or in a format like mulaw. You must decode base64 and, if necessary, convert mulaw to linear16 PCM before sending it to Deepgram, or set the encoding to match the actual audio format No response received from deepgram streaming websockets, Transcribing live stream calls from Twilio in python.

  3. Connection or Permission Issues:
    If there are authentication or permission issues (e.g., 403 errors, or your project does not have access to the requested model), Deepgram will not process your audio and no events will be fired Deepgram API Errors.

What you should check:

  • Verify the audio format, encoding, and sample rate match between your telephony source and Deepgram options.
  • Ensure you are sending actual audio data (not just silence or empty chunks) right after the connection opens.
  • Decode and convert the audio if it is base64-encoded or in a different codec.
  • Register your event handler before starting the connection and sending audio.
  • Check for any errors or warnings in the logs that might indicate connection or permission issues.
#

If you are still having trouble, try logging the raw audio data you are sending and confirm its format, or test with a known-good audio file to isolate the issue.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@wary jackal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

wary jackal
#

now how to send the chunk to deepgram after receivingfrom telephony @gusty glen

gusty glenBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

To send audio chunks to Deepgram after receiving them from your telephony system, you need to ensure the audio is in the correct format and then use the Deepgram SDK's send() method on your live connection object.

Key steps:

  1. Decode/Convert the Audio (if needed):

  2. Send the Audio Chunk:

    • Use the send() method of your Deepgram live connection object to send the audio bytes.
    • Example (Python, async SDK v3):
# After receiving and decoding/converting your audio chunk:
await dg_connection.send(audio_chunk)

Example for Twilio (mulaw, base64-encoded):

import base64

# Assume 'media_payload' is the base64-encoded audio chunk from telephony
audio_chunk = base64.b64decode(media_payload)
await dg_connection.send(audio_chunk)

This matches the official advice for Twilio and other telephony integrations: decode the base64 payload and send the raw bytes to Deepgram No response received from deepgram streaming websockets.

#

Important:

  • The audio format and sample rate must match what you specified in your Deepgram connection options.
  • Send the audio chunk as soon as you receive it to avoid timeouts.

If you need to send silence (for example, to flush the buffer), you can send a chunk of the appropriate "silence" byte for your encoding (e.g., 0xff for mulaw) Real Time transcription of Twilio call: transaction_key":"deprecated".

If you need more details for your specific telephony provider, please specify which one you are using.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: