#Python SDK live transcription connection error

1 messages · Page 1 of 1 (latest)

versed lagoon
#

Hi, I'm using the live Python SDK Deepgram client (v 3.1.4) (https://github.com/deepgram/deepgram-python-sdk/blob/v3.1.4/deepgram/clients/live/v1/client.py) and sometimes get this error:
Exception in _listening: received 1011 (unexpected error) Deepgram did not receive audio data or a text message within the timeout window. See https://dpgr.am/net0001; then sent 1011 (unexpected error) Deepgram did not receive audio data or a text message within the timeout window. See https://dpgr.am/net0001
The problem is that I'm getting thousands of these messages.

I've checked that the data was sent in the specified timeout, the request_id is aa4da787-2bf7-4d91-8b19-5b84a2573a4f
Could you please help with the following questions:
what was the reason?
what is the correct way to recreate the connection and stop the errors when this happens?

used options:
sample_rate=48000
options = LiveOptions(
model="nova-2",
language="en-US",
# smart_format=True,
sample_rate=sample_rate,
encoding="linear16",
interim_results=True,
utterance_end_ms='2000',
)

GitHub

Official Python SDK for Deepgram's automated speech recognition APIs. - deepgram/deepgram-python-sdk

Deepgram

Power your apps with automatic speech recognition and language understanding capabilities with the world's most powerful speech-to-text API.

Deepgram Docs

Learn how to debug common real-time, live streaming transcription errors.

summer kindleBOT
#

Thanks for asking your question. Please be sure to reply with as much detail as possible so we can assist you efficiently. Such as:

  • Provide the request_id if you've a question about a transcription response.
  • The options you used or the api.deepgram.com URL you sent your request to, including parameters.
  • Any code snippets you can include.
  • Any audio you can include, or if you can't share it here please email it to us at [email protected] and provide a link to this thread.
versed lagoon
#

request_id: aa4da787-2bf7-4d91-8b19-5b84a2573a4f
options:
sample_rate=48000 options = LiveOptions( model="nova-2", language="en-US", # smart_format=True, sample_rate=sample_rate, encoding="linear16", interim_results=True, utterance_end_ms='2000', )

#

code snippet for creating connection:
`
self._dg_stream_connection = self.dg_client.listen.live.v("1")
def on_message(
, result, **kwargs):
# required to check if the result is final if the interim results are enabled
if result.is_final:
sentence = result.channel.alternatives[0].transcript
if len(sentence) == 0:
return
self._transcription_queue.put(sentence)
else:
sentence = result.channel.alternatives[0].transcript
if len(sentence) == 0:
return
self._transcription_queue.put(self.SENTINEL_INTERIM_RESULT)

def on_metadata(_, metadata, **kwargs):
pass

def on_error(_, error, **kwargs):
if not self._error:
self._error = error

def on_utterance_end(_, utterance_end, **kwargs):
self._transcription_queue.put(self.SENTINEL_UTTERANCE_END)

self._dg_stream_connection.on(LiveTranscriptionEvents.Transcript, on_message)
self._dg_stream_connection.on(LiveTranscriptionEvents.Error, on_error)
self._dg_stream_connection.on(LiveTranscriptionEvents.UtteranceEnd, on_utterance_end)

options = LiveOptions(
model="nova-2",
language="en-US",
sample_rate=sample_rate,
encoding="linear16",
interim_results=True,
utterance_end_ms='2000',
)

self._dg_stream_connection.start(options)`

golden compass
#

yea, sounds like you aren't sending the data and the connection is getting closed on you. I would doulbe check to make sure the data stream is getting to the Deepgram endpoint.

once you receive an exception, you need to reconnect to the DG endpoint again and start over. this wont help however unless you are sending data matching the encoding parameter in your LiveOptions.

versed lagoon
#

I don't think that's the case. I double checked the logs and I can see that the time difference between getting the audio chunk and sending the audio chunk to the DeepGram API is minimal as well as the time interval between the receiving of two consecutive audio chunks.

once you receive an exception, you need to reconnect to the DG endpoint again and start over. this wont help however unless you are sending data matching the encoding parameter in your LiveOptions.
So, should I attempt to call finish in the LiveClient in the error handler and then reopen the connection from scratch? Additional question: what is the reason of such amount of error messages in the _listening thread? As I mentioned there are thousands of errors starting with Exception in _listening: received 1011.

golden compass
#

Is the connection termination happening immediately?

here is something to demonstrate the keepalive:

# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from dotenv import load_dotenv
import logging, verboselogs
from time import sleep

from deepgram import (
    DeepgramClient,
    DeepgramClientOptions,
    LiveTranscriptionEvents,
    LiveOptions,
)

load_dotenv()


def main():
    try:
        # example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM
        config = DeepgramClientOptions(
            verbose=logging.DEBUG, options={"keepalive": "true"}
        )
        deepgram: DeepgramClient = DeepgramClient("", config)

        dg_connection = deepgram.listen.live.v("1")

        options: LiveOptions = LiveOptions(
            model="nova-2",
            language="en-US",
            encoding="linear16",
            channels=1,
            sample_rate=16000,
        )
        dg_connection.start(options)

        # wait until finished
        print("\n\n")
        print(
            "Here we are intentionally not going to send any audio data to the server.\n"
        )
        print(
            "If the keepalive doesn't work, you should see a timeout message after 12-ish seconds."
        )
        print("\n\n")
        input("Press Enter to stop recording...\n\n")

        # Indicate that we've finished
        dg_connection.finish()

        print("Finished")

    except Exception as e:
        print(f"Could not open socket: {e}")
        return


if __name__ == "__main__":
    main()

there was a release published a few minutes ago, I would update to that since the exception handling is better. In general though, you should call finish() before creating a new socket

versed lagoon
#

No, it didn't happen right away, only after considerable time. Thanks for the example!

there was a release published a few minutes ago, I would update to that since the exception handling is better. In general though, you should call finish() before creating a new socket
Got it, thanks a lot! Also what's the suggested way to extract deepgram request id? Right now I'm extracting it from the internal field ( dg_stream_connection._socket.response.headers['dg-request-id'])?

golden compass
#

yep! that would be the best way to get it!