deepgram/deepgram-python-sdk

websocket send function is not processing subsequent messages

tgvarner opened this issue ยท 12 comments

I am sending chunks of audio bytes (each chunk is 10 seconds of audio) through the WebSocket connection to Deepgram. However, Deepgram is only processing and returning the first chunk, and not doing so for subsequent chunks, while keeping the WebSocket connection alive.

It returns with a Metadata object, representing the first chunk, and returns nothing else, and does not trigger events for error, finalize, unhandled, or close. I've confirmed that I am indeed calling the send method to send subsequent chunks.

Below are the relevant pieces of code:

def transcribe_live_from_deepgram():
  # Implement from here: https://developers.deepgram.com/docs/getting-started-with-live-streaming-audio

  try:
    config = DeepgramClientOptions(
        options={
            "keepalive": "true",
            "encoding": "linear16",
        }
    )
    deepgram = DeepgramClient(
        <my_key>, config)

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

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

    def on_metadata(self, metadata, **kwargs):
      print(f"\n\n{metadata}\n\n")

    def on_error(self, error, **kwargs):
      print(f"\n\n{error}\n\n")

    def on_finalize(self, finalize, **kwargs):
      print(f"\n\n{finalize}\n\n")

    def on_close(self, close, **kwargs):
      print(f"\n\n{close}\n\n")

    def on_unhandled(self, unhandled, **kwargs):
      print(f"\n\n{unhandled}\n\n")

    dg_connection.on(LiveTranscriptionEvents.Transcript, on_message)
    dg_connection.on(LiveTranscriptionEvents.Metadata, on_metadata)
    dg_connection.on(LiveTranscriptionEvents.Error, on_error)
    dg_connection.on(LiveTranscriptionEvents.Close, on_close)
    dg_connection.on(LiveTranscriptionEvents.Finalize, on_finalize)
    dg_connection.on(LiveTranscriptionEvents.Unhandled, on_unhandled)

    options = LiveOptions(
        model="nova-2",
        language="en-US",
        smart_format=True,
    )

    dg_connection.start(options)

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

@app.websocket("/ws/listen")
async def transcribe_from_websocket(websocket: WebSocket, client_id: int):
  # Start websocket connection to client
  await encounter_connection_manager.connect(websocket)

  # Start websocket connection to Deepgram
  dg_connection = transcribe_live_from_deepgram()

  connected = True

  try:
    while connected:
      message = await websocket.receive()
      if message:
        try:
          message_bytes = bytes(base64.b64decode(message['text']))

          print(f'Message byte length: {len(message_bytes)}')

          dg_connection.send(message_bytes)
          ...
        except Exception as e:
          encounter_connection_manager.disconnect(websocket)
          ...

When I run the following code, it correctly returns the transcribed items for the first chunk, and then it sends the following metadata message:

{
    "type": "Metadata",
    "transaction_key": "deprecated",
    "request_id": "e508a3cc-8c04-4a76-a3ae-801337bdbc80",
    "sha256": "181598a8b95bf32daaa3796a7af976098dd1408f426883d390ad010cee7ad727",
    "created": "2024-07-02T06:39:02.759Z",
    "duration": 9.898687,
    "channels": 1,
    "models": [
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    ],
    "model_info": {
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        }
    }
}

I receive no additional messages for the subsequent chunks. Is there something wrong with setup, or is there a bug?

I've also tried with smaller audio chunks (250ms), but the same issue still occurs.

My client code is as follows:

// Client-side (Browser)
// import RecordRTC from 'recordrtc';

console.log('Recorder client loaded');

let ws = new WebSocket('ws://localhost:8000/ws/listen');
let mediaRecorder;

ws.onmessage = event => {
  let responseContainer = document.getElementById('responseContainer');
  responseContainer.innerHTML += `<p>${event.data}</p>`;
};

let handleDataAvailable = (event) => {
  if (event.size > 0) {
    console.log('blob', event)
    blobToBase64(event).then(b64 => {
      ws.send(b64)
    })
  }
};

function blobToBase64(blob) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onload = () => {
      const base64String = reader.result.split(',')[1];
      resolve(base64String);
    };
    reader.onerror = (error) => reject(error);
  });
}

navigator.mediaDevices.getUserMedia({ audio: true })
  .then(stream => {
    let recorder = RecordRTC(stream, {
      type: 'audio',
      recorderType: StereoAudioRecorder,
      mimeType: 'audio/wav',
      timeSlice: 10000,
      desiredSampRate: 16000,
      numberOfAudioChannels: 1,
      ondataavailable: handleDataAvailable
    });

    document.getElementById('startButton').addEventListener('click', () => {
      recorder.startRecording();
      let status = document.getElementById('status');
      status.innerHTML += `<p>Recording</p>`;
    });

    document.getElementById('pauseButton').addEventListener('click', () => {
      recorder.pauseRecording();
      let status = document.getElementById('status');
      status.innerHTML += `<p>Paused</p>`;
    });

    document.getElementById('resumeButton').addEventListener('click', () => {
      recorder.resumeRecording();
      let status = document.getElementById('status');
      status.innerHTML += `<p>Playing</p>`;
    });

    document.getElementById('stopButton').addEventListener('click', () => {
      recorder.stopRecording();
      let status = document.getElementById('status');
      status.innerHTML += `<p>Stopped</p>`;
    });
  });

ws.onopen = () => {
  console.log('WebSocket connection opened');
};

ws.onclose = () => {
  console.log('WebSocket connection closed');
};

MacOS 14.4.1
Python Version 3.11.9

The metadata message usually indicates that the connection was closed. One way to terminate the connection is by sending an empty byte array. I would dump each message you send to a text file for debugging. I am willing to bet that is what is happening. Additional, trace in your code might also be helpful to see if you are exiting accidentally.

You can also enable debug on the SDK to help out. For more information:
https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/streaming/http/main.py#L27-L28

Hi @dvonthenen thanks so much for the quick reply.

I do not think that is the case. I updated my example above, to print the length of the byte array that is sent to DG. And I get the following output:

Message byte length: 316802
speaker: After an unprecedented
speaker: 3 year time out on federal student loan payments,
speaker: because of the pandemic. Millions of borrowers began repaying their debt
Message byte length: 322262
Message byte length: 322262


{
    "type": "Metadata",
    "transaction_key": "deprecated",
    "request_id": "9eba4b58-dd9b-4283-85f4-e0e2e83c310d",
    "sha256": "b614fafc444000c3769ed0e6df24e01969907de8635c64142f2e9b58855923e2",
    "created": "2024-07-02T20:56:53.109Z",
    "duration": 9.898687,
    "channels": 1,
    "models": [
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    ],
    "model_info": {
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        }
    }
}


Message byte length: 319532
Message byte length: 322262
Message byte length: 322262
Message byte length: 322262
Message byte length: 322262
Message byte length: 322262

As you can see, the first chunk is transcribed, and subsequent chunks are not. I am not sending any empty byte arrays. I increased the chunk size to 10 seconds of audio to make it easier to debug.

Also, FWIW, although I don't think that sending an empty byte array is causing the issue above, it seems weird that sending an empty byte array would arbitrarily close the connection without sending a thorough message via the Closed event explaining that the connection was closed for that reason.

Any thoughts on the above?...This issue is preventing me from using Deepgram. And I'm doing something basic, using the same code from the documentation: https://developers.deepgram.com/docs/getting-started-with-live-streaming-audio

Can you enable debugging outlined in my last reply and drop the trace info here? If you aren't comfortable post here, you can reach out on Discord with a DM.

The DG endpoint is programmed to terminate the connection on an empty byte array which is why I asked. Definitely not weird if that's the expected behavior. It's part of the application level protocol.

Thanks @dvonthenen. The link you sent does not work. But yes I will give that a try now, I just need to know how - preferably using the SDK. Can you send an updated link?

Also, in regards to the zero-byte array closing the WS connection, I think this issue captures the problem. I couldn't find where it is documented that sending a zero byte array closes the WS, and even if that is the case, the API should make it abundantly clear that's the reason for terminating the connection. <-- This is an issue, but I'd like to not deviate from the main issue. Sorry for harping on this lol ๐Ÿ˜…

Nvm, I found out how to do the logging. The following is the output:

Version.v ENTER
version: 1
path: deepgram.clients.live.v1.client
class_name: LiveClient
Version.v succeeded
Version.v LEAVE
event subscribed: Results
event subscribed: Metadata
event subscribed: Error
event subscribed: Close
event subscribed: Finalize
event subscribed: Unhandled
LiveClient.start ENTER
options: {
    "language": "en-US",
    "model": "nova-2",
    "smart_format": true
}
addons: None
headers: None
members: None
kwargs: {}
LiveOptions switching class -> dict
combined_options: {'language': 'en-US', 'model': 'nova-2', 'smart_format': True}
combined_headers: {'Accept': 'application/json', 'Authorization': 'Token 387351dd19967b42f9396480567cd8f737655624', 'User-Agent': '@deepgram/sdk/v3.3.1 python/11.9'}
after running thread: MainThread
after running thread: Thread-6 (recv_events)
number of active threads: 2
keepalive is enabled
LiveClient._listening ENTER
autoflush is disabled
LiveClient._keep_alive ENTER
after running thread: MainThread
after running thread: Thread-6 (recv_events)
after running thread: Thread-7 (_listening)
after running thread: Thread-8 (_keep_alive)
number of active threads: 4
callback handlers for: Open
start succeeded
LiveClient.start LEAVE
INFO:     connection open
Sending KeepAlive...
keep_alive succeeded
Sending KeepAlive...
keep_alive succeeded
Sending KeepAlive...
keep_alive succeeded
Sending KeepAlive...
keep_alive succeeded
Sending KeepAlive...
keep_alive succeeded
Message byte length: 316802
Sending KeepAlive...
keep_alive succeeded
response_type: Results, data: {'type': 'Results', 'channel_index': [0, 1], 'duration': 2.51, 'start': 0.0, 'is_final': True, 'speech_final': True, 'channel': {'alternatives': [{'transcript': '', 'confidence': 0.0, 'words': []}]}, 'metadata': {'request_id': 'ef82c1e2-4963-415a-a9ef-602531d19e87', 'model_info': {'name': '2-general-nova', 'version': '2024-01-18.26916', 'arch': 'nova-2'}, 'model_uuid': 'c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c'}, 'from_finalize': False}
LiveResultResponse: {
    "channel": {
        "alternatives": [
            {
                "transcript": "",
                "confidence": 0.0,
                "words": []
            }
        ]
    },
    "metadata": {
        "model_info": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        },
        "request_id": "ef82c1e2-4963-415a-a9ef-602531d19e87",
        "model_uuid": "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    },
    "type": "Results",
    "channel_index": [
        0,
        1
    ],
    "duration": 2.51,
    "start": 0.0,
    "is_final": true,
    "from_finalize": false,
    "speech_final": true
}
callback handlers for: Results
response_type: Results, data: {'type': 'Results', 'channel_index': [0, 1], 'duration': 2.9399998, 'start': 2.51, 'is_final': True, 'speech_final': True, 'channel': {'alternatives': [{'transcript': 'Estimating the overall size of the financial markets is difficult.', 'confidence': 0.99575555, 'words': [{'word': 'estimating', 'start': 2.59, 'end': 3.09, 'confidence': 0.9979948, 'punctuated_word': 'Estimating'}, {'word': 'the', 'start': 3.15, 'end': 3.31, 'confidence': 0.9946964, 'punctuated_word': 'the'}, {'word': 'overall', 'start': 3.31, 'end': 3.79, 'confidence': 0.99941754, 'punctuated_word': 'overall'}, {'word': 'size', 'start': 3.79, 'end': 4.0299997, 'confidence': 0.99575555, 'punctuated_word': 'size'}, {'word': 'of', 'start': 4.0299997, 'end': 4.1099997, 'confidence': 0.9947523, 'punctuated_word': 'of'}, {'word': 'the', 'start': 4.1099997, 'end': 4.35, 'confidence': 0.9978447, 'punctuated_word': 'the'}, {'word': 'financial', 'start': 4.35, 'end': 4.67, 'confidence': 0.99767286, 'punctuated_word': 'financial'}, {'word': 'markets', 'start': 4.67, 'end': 4.91, 'confidence': 0.946919, 'punctuated_word': 'markets'}, {'word': 'is', 'start': 4.91, 'end': 5.16, 'confidence': 0.974795, 'punctuated_word': 'is'}, {'word': 'difficult', 'start': 5.16, 'end': 5.45, 'confidence': 0.5732408, 'punctuated_word': 'difficult.'}]}]}, 'metadata': {'request_id': 'ef82c1e2-4963-415a-a9ef-602531d19e87', 'model_info': {'name': '2-general-nova', 'version': '2024-01-18.26916', 'arch': 'nova-2'}, 'model_uuid': 'c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c'}, 'from_finalize': False}
LiveResultResponse: {
    "channel": {
        "alternatives": [
            {
                "transcript": "Estimating the overall size of the financial markets is difficult.",
                "confidence": 0.99575555,
                "words": [
                    {
                        "word": "estimating",
                        "start": 2.59,
                        "end": 3.09,
                        "confidence": 0.9979948,
                        "punctuated_word": "Estimating"
                    },
                    {
                        "word": "the",
                        "start": 3.15,
                        "end": 3.31,
                        "confidence": 0.9946964,
                        "punctuated_word": "the"
                    },
                    {
                        "word": "overall",
                        "start": 3.31,
                        "end": 3.79,
                        "confidence": 0.99941754,
                        "punctuated_word": "overall"
                    },
                    {
                        "word": "size",
                        "start": 3.79,
                        "end": 4.0299997,
                        "confidence": 0.99575555,
                        "punctuated_word": "size"
                    },
                    {
                        "word": "of",
                        "start": 4.0299997,
                        "end": 4.1099997,
                        "confidence": 0.9947523,
                        "punctuated_word": "of"
                    },
                    {
                        "word": "the",
                        "start": 4.1099997,
                        "end": 4.35,
                        "confidence": 0.9978447,
                        "punctuated_word": "the"
                    },
                    {
                        "word": "financial",
                        "start": 4.35,
                        "end": 4.67,
                        "confidence": 0.99767286,
                        "punctuated_word": "financial"
                    },
                    {
                        "word": "markets",
                        "start": 4.67,
                        "end": 4.91,
                        "confidence": 0.946919,
                        "punctuated_word": "markets"
                    },
                    {
                        "word": "is",
                        "start": 4.91,
                        "end": 5.16,
                        "confidence": 0.974795,
                        "punctuated_word": "is"
                    },
                    {
                        "word": "difficult",
                        "start": 5.16,
                        "end": 5.45,
                        "confidence": 0.5732408,
                        "punctuated_word": "difficult."
                    }
                ]
            }
        ]
    },
    "metadata": {
        "model_info": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        },
        "request_id": "ef82c1e2-4963-415a-a9ef-602531d19e87",
        "model_uuid": "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    },
    "type": "Results",
    "channel_index": [
        0,
        1
    ],
    "duration": 2.9399998,
    "start": 2.51,
    "is_final": true,
    "from_finalize": false,
    "speech_final": true
}
callback handlers for: Results
speaker: Estimating the overall size of the financial markets is difficult.
Sending KeepAlive...
keep_alive succeeded
Message byte length: 322262
response_type: Results, data: {'type': 'Results', 'channel_index': [0, 1], 'duration': 4.4486876, 'start': 5.45, 'is_final': True, 'speech_final': False, 'channel': {'alternatives': [{'transcript': 'It is hard in the 1st place to decide exactly what transaction should be included', 'confidence': 0.9947418, 'words': [{'word': 'it', 'start': 6.0899997, 'end': 6.1699996, 'confidence': 0.99738234, 'punctuated_word': 'It'}, {'word': 'is', 'start': 6.1699996, 'end': 6.33, 'confidence': 0.99890494, 'punctuated_word': 'is'}, {'word': 'hard', 'start': 6.33, 'end': 6.49, 'confidence': 0.99883586, 'punctuated_word': 'hard'}, {'word': 'in', 'start': 6.49, 'end': 6.6499996, 'confidence': 0.9862634, 'punctuated_word': 'in'}, {'word': 'the', 'start': 6.6499996, 'end': 6.7699995, 'confidence': 0.9872738, 'punctuated_word': 'the'}, {'word': '1st', 'start': 6.7699995, 'end': 6.89, 'confidence': 0.884519, 'punctuated_word': '1st'}, {'word': 'place', 'start': 6.89, 'end': 7.21, 'confidence': 0.99901867, 'punctuated_word': 'place'}, {'word': 'to', 'start': 7.21, 'end': 7.37, 'confidence': 0.9976169, 'punctuated_word': 'to'}, {'word': 'decide', 'start': 7.37, 'end': 7.6899996, 'confidence': 0.9997447, 'punctuated_word': 'decide'}, {'word': 'exactly', 'start': 7.6899996, 'end': 8.19, 'confidence': 0.99952245, 'punctuated_word': 'exactly'}, {'word': 'what', 'start': 8.25, 'end': 8.49, 'confidence': 0.9947418, 'punctuated_word': 'what'}, {'word': 'transaction', 'start': 8.49, 'end': 8.99, 'confidence': 0.69651425, 'punctuated_word': 'transaction'}, {'word': 'should', 'start': 9.049999, 'end': 9.21, 'confidence': 0.9945259, 'punctuated_word': 'should'}, {'word': 'be', 'start': 9.21, 'end': 9.45, 'confidence': 0.9934175, 'punctuated_word': 'be'}, {'word': 'included', 'start': 9.45, 'end': 9.898687, 'confidence': 0.92426544, 'punctuated_word': 'included'}]}]}, 'metadata': {'request_id': 'ef82c1e2-4963-415a-a9ef-602531d19e87', 'model_info': {'name': '2-general-nova', 'version': '2024-01-18.26916', 'arch': 'nova-2'}, 'model_uuid': 'c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c'}, 'from_finalize': False}
LiveResultResponse: {
    "channel": {
        "alternatives": [
            {
                "transcript": "It is hard in the 1st place to decide exactly what transaction should be included",
                "confidence": 0.9947418,
                "words": [
                    {
                        "word": "it",
                        "start": 6.0899997,
                        "end": 6.1699996,
                        "confidence": 0.99738234,
                        "punctuated_word": "It"
                    },
                    {
                        "word": "is",
                        "start": 6.1699996,
                        "end": 6.33,
                        "confidence": 0.99890494,
                        "punctuated_word": "is"
                    },
                    {
                        "word": "hard",
                        "start": 6.33,
                        "end": 6.49,
                        "confidence": 0.99883586,
                        "punctuated_word": "hard"
                    },
                    {
                        "word": "in",
                        "start": 6.49,
                        "end": 6.6499996,
                        "confidence": 0.9862634,
                        "punctuated_word": "in"
                    },
                    {
                        "word": "the",
                        "start": 6.6499996,
                        "end": 6.7699995,
                        "confidence": 0.9872738,
                        "punctuated_word": "the"
                    },
                    {
                        "word": "1st",
                        "start": 6.7699995,
                        "end": 6.89,
                        "confidence": 0.884519,
                        "punctuated_word": "1st"
                    },
                    {
                        "word": "place",
                        "start": 6.89,
                        "end": 7.21,
                        "confidence": 0.99901867,
                        "punctuated_word": "place"
                    },
                    {
                        "word": "to",
                        "start": 7.21,
                        "end": 7.37,
                        "confidence": 0.9976169,
                        "punctuated_word": "to"
                    },
                    {
                        "word": "decide",
                        "start": 7.37,
                        "end": 7.6899996,
                        "confidence": 0.9997447,
                        "punctuated_word": "decide"
                    },
                    {
                        "word": "exactly",
                        "start": 7.6899996,
                        "end": 8.19,
                        "confidence": 0.99952245,
                        "punctuated_word": "exactly"
                    },
                    {
                        "word": "what",
                        "start": 8.25,
                        "end": 8.49,
                        "confidence": 0.9947418,
                        "punctuated_word": "what"
                    },
                    {
                        "word": "transaction",
                        "start": 8.49,
                        "end": 8.99,
                        "confidence": 0.69651425,
                        "punctuated_word": "transaction"
                    },
                    {
                        "word": "should",
                        "start": 9.049999,
                        "end": 9.21,
                        "confidence": 0.9945259,
                        "punctuated_word": "should"
                    },
                    {
                        "word": "be",
                        "start": 9.21,
                        "end": 9.45,
                        "confidence": 0.9934175,
                        "punctuated_word": "be"
                    },
                    {
                        "word": "included",
                        "start": 9.45,
                        "end": 9.898687,
                        "confidence": 0.92426544,
                        "punctuated_word": "included"
                    }
                ]
            }
        ]
    },
    "metadata": {
        "model_info": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        },
        "request_id": "ef82c1e2-4963-415a-a9ef-602531d19e87",
        "model_uuid": "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    },
    "type": "Results",
    "channel_index": [
        0,
        1
    ],
    "duration": 4.4486876,
    "start": 5.45,
    "is_final": true,
    "from_finalize": false,
    "speech_final": false
}
callback handlers for: Results
speaker: It is hard in the 1st place to decide exactly what transaction should be included
Sending KeepAlive...
keep_alive succeeded
Sending KeepAlive...
keep_alive succeeded
Message byte length: 322262
response_type: Metadata, data: {'type': 'Metadata', 'transaction_key': 'deprecated', 'request_id': 'ef82c1e2-4963-415a-a9ef-602531d19e87', 'sha256': 'fe9165e9c7b16f78838b78ed2f59a6fed1678d7dce0929a3c8a0700b85437e8f', 'created': '2024-07-03T02:26:15.778Z', 'duration': 9.898687, 'channels': 1, 'models': ['c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c'], 'model_info': {'c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c': {'name': '2-general-nova', 'version': '2024-01-18.26916', 'arch': 'nova-2'}}}
MetadataResponse: {
    "type": "Metadata",
    "transaction_key": "deprecated",
    "request_id": "ef82c1e2-4963-415a-a9ef-602531d19e87",
    "sha256": "fe9165e9c7b16f78838b78ed2f59a6fed1678d7dce0929a3c8a0700b85437e8f",
    "created": "2024-07-03T02:26:15.778Z",
    "duration": 9.898687,
    "channels": 1,
    "models": [
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    ],
    "model_info": {
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        }
    }
}
callback handlers for: Metadata


{
    "type": "Metadata",
    "transaction_key": "deprecated",
    "request_id": "ef82c1e2-4963-415a-a9ef-602531d19e87",
    "sha256": "fe9165e9c7b16f78838b78ed2f59a6fed1678d7dce0929a3c8a0700b85437e8f",
    "created": "2024-07-03T02:26:15.778Z",
    "duration": 9.898687,
    "channels": 1,
    "models": [
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c"
    ],
    "model_info": {
        "c0d1a568-ce81-4fea-97e7-bd45cb1fdf3c": {
            "name": "2-general-nova",
            "version": "2024-01-18.26916",
            "arch": "nova-2"
        }
    }
}


_listening(1000) exiting gracefully
LiveClient._listening LEAVE
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
Message byte length: 322262
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
Message byte length: 322262
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
Sending KeepAlive...
send() exiting gracefully: 1000
LiveClient._keep_alive LEAVE
keep_alive succeeded
INFO:     connection closed

It looks like the client is terminating for some reason, while keeping the WS connection alive, and not reporting any errors, or anything really. What do you think is the cause?

What version of the SDK are you using?

If I remember correctly, the 1000 error code is coming from the server from a graceful shutdown.

deepgram-sdk: 3.3.1

Also, this seems to be the same issue, but the thread does not show the resolution. I added the encoding param with value "linear16" to LiveOptions, as you suggested in the thread. I've attached my client code to show that I am using WAV data:

    ...
    options = LiveOptions(
        model="nova-2",
        language="en-US",
        smart_format=True,
        encoding="linear16"
    )

    dg_connection.start(options)
    ...

Respectfully, can someone please tell me what's going on here? @dvonthenen

Respectfully, can someone please tell me what's going on here? @dvonthenen

Respectfully, I am helping out a great number of people. Sometimes patience is required.

You also need a sample rate along with the encoding type.

This might help you out as well:
https://discord.com/channels/1108042150941294664/1255239994457718926/1255239994457718926

This seems to be an issue with the way that stream is being handled (ie manipulated) from your application.

Respectfully, I am helping out a great number of people.

How am I supposed to know that?...respectfully

But thanks, the sample_rate param along with the encoder param in LiveOptions is what was missing, and everything now works.

It would be great if the documentation (https://developers.deepgram.com/docs/python-sdk-streaming-transcription, and https://developers.deepgram.com/docs/getting-started-with-live-streaming-audio) communicated the need for these params, as well as having working links to the demos.