This is crazy issue because I just don't understand!
I read the documentation and I am spamming the "keep-alive" but Deepgram Still Closes!
BRO Connection closed for stream MZ7b6ca693f016d1a1ed3d3393055ad9eb. Status code: 1011, Reason: Deepgram did not receive audio data or a text message within the timeout window. See https://dpgr.am/net0001. Trying to re-establish.
Keep Alive Code:
def keep_alive(ws): """Send a KeepAlive message every interval seconds.""" keep_alive_msg = json.dumps({"type": "KeepAlive"}) try: ws.send(keep_alive_msg) # Send the KeepAlive message except Exception as e: print(f"Error sending KeepAlive: {e}")
How I spam it:
def send_audio_to_deepgram(audio_chunk, ws): if ws: try: if not ws.sock or not ws.sock.connected: raise websocket.WebSocketConnectionClosedException("Connection is closed") ws.send(audio_chunk, opcode=websocket.ABNF.OPCODE_BINARY) keep_alive(ws)