Closed subodhjena closed 1 month ago
We're facing the same issue as well here.
The opposite of this is true. When closing the WebSocket from the Deepgram end, we send a metadata message.
The closing of the connection is usually because no data was sent for 10 seconds, or you sent invalid data. I'd suggest using our streaming test suite to debug your data stream.
@lukeocodes There are two aspects to the issue that I would like to highlight:
Keep-alive Interval: The keep-alive function runs every 10 seconds to maintain the WebSocket connection. Do you think reducing the interval might help prevent the connection from closing prematurely?
Browser Audio Streaming: We are directly sending browser audio to our WebSocket using the following code:
const audioTracks = mediaStreamRef.current.getAudioTracks();
if (audioTracks && audioTracks.length > 0 && isConnected && ws) {
const audioStream = new MediaStream(audioTracks);
try {
const mediaRecorder = new MediaRecorder(audioStream, {
mimeType: "audio/webm; codecs=opus",
});
mediaRecorder.ondataavailable = (event: BlobEvent) => {
if (ws && event.data.size > 0 && ws.readyState === WebSocket.OPEN) {
event.data.arrayBuffer().then((buffer) => {
ws.send(buffer);
});
}
};
mediaRecorder.start(1000); // Records and sends audio chunks every 1 second
setIsStreaming(true);
} catch (error) {
console.error("Error starting media recorder:", error);
}
} else {
console.error("No audio tracks available or WebSocket is not connected");
}
As I explained in my previous question, the connection does not always fail—it works fine on production and cloud servers. However, the issue mostly occurs when working locally, but I am concerned that this might happen in the production/cloud environment as well.
Was this question asked in the Discord community too?
For your request ID: f71f632f-df82-49d4-8459-a25671fc24d9
we received no audio at all. Please let me know if you see any pattern in which browsers/OSs you're having issues with, or whether it's after something else has occurred on your app beforehand. It seems that we're not receiving audio in these instances
@lukeocodes There are two aspects to the issue that I would like to highlight:
- Keep-alive Interval: The keep-alive function runs every 10 seconds to maintain the WebSocket connection. Do you think reducing the interval might help prevent the connection from closing prematurely?
- Browser Audio Streaming: We are directly sending browser audio to our WebSocket using the following code:
const audioTracks = mediaStreamRef.current.getAudioTracks(); if (audioTracks && audioTracks.length > 0 && isConnected && ws) { const audioStream = new MediaStream(audioTracks); try { const mediaRecorder = new MediaRecorder(audioStream, { mimeType: "audio/webm; codecs=opus", }); mediaRecorder.ondataavailable = (event: BlobEvent) => { if (ws && event.data.size > 0 && ws.readyState === WebSocket.OPEN) { event.data.arrayBuffer().then((buffer) => { ws.send(buffer); }); } }; mediaRecorder.start(1000); // Records and sends audio chunks every 1 second setIsStreaming(true); } catch (error) { console.error("Error starting media recorder:", error); } } else { console.error("No audio tracks available or WebSocket is not connected"); }
As I explained in my previous question, the connection does not always fail—it works fine on production and cloud servers. However, the issue mostly occurs when working locally, but I am concerned that this might happen in the production/cloud environment as well.
Yepp I tried reducing the keepalive timeout to 9seconds and the issue is happening less frequently, also @lukeocodes I am facing the same connection closing issue in the text-to-speech. I am using deepgram-sdk 3.8.0 in nodejs, but the live speech does not have a keepAlive event in the SDK, any idea how to fix that in live speech?
So is this another issue now with TTS? Or the same issue with STT?
Following this, as I am also experiencing a similar issue in local environment (but not in production)
Same issue
@lukeocodes There are two aspects to the issue that I would like to highlight:
- Keep-alive Interval: The keep-alive function runs every 10 seconds to maintain the WebSocket connection. Do you think reducing the interval might help prevent the connection from closing prematurely?
- Browser Audio Streaming: We are directly sending browser audio to our WebSocket using the following code:
const audioTracks = mediaStreamRef.current.getAudioTracks(); if (audioTracks && audioTracks.length > 0 && isConnected && ws) { const audioStream = new MediaStream(audioTracks); try { const mediaRecorder = new MediaRecorder(audioStream, { mimeType: "audio/webm; codecs=opus", }); mediaRecorder.ondataavailable = (event: BlobEvent) => { if (ws && event.data.size > 0 && ws.readyState === WebSocket.OPEN) { event.data.arrayBuffer().then((buffer) => { ws.send(buffer); }); } }; mediaRecorder.start(1000); // Records and sends audio chunks every 1 second setIsStreaming(true); } catch (error) { console.error("Error starting media recorder:", error); } } else { console.error("No audio tracks available or WebSocket is not connected"); }
As I explained in my previous question, the connection does not always fail—it works fine on production and cloud servers. However, the issue mostly occurs when working locally, but I am concerned that this might happen in the production/cloud environment as well.
Yepp I tried reducing the keepalive timeout to 9seconds and the issue is happening less frequently, also @lukeocodes I am facing the same connection closing issue in the text-to-speech. I am using deepgram-sdk 3.8.0 in nodejs, but the live speech does not have a keepAlive event in the SDK, any idea how to fix that in live speech?
I'm not following this, as there are so many accounts replying I don't know if I'm even replying to the original poster.
Latency can be a factor on KeepAlive. Reduce the timeout without penalty to factor this in. Try 5 seconds if you have to.
We have a ticket open for keepalive on TTS
What is the current behavior?
The WebSocket connection to Deepgram intermittently closes after sending a metadata message while developing in the local environment. The last message received before the connection closure is:
After this message, the WebSocket connection is closed unexpectedly. This issue does not always happen but occurs frequently during local development.
Steps to reproduce:
Expected behavior:
The WebSocket connection should remain active during the entire audio transmission, and the connection should not close prematurely after receiving a metadata message.
Please tell us about your environment:
@deepgram/deepgram-js-sdk@3.8.0
Other information:
Here's some logs for you as well
Do let me know if there are any known issues with handling metadata messages or if there are any steps I can take to debug the WebSocket closure further. Any advice or potential fixes would be appreciated!