Closed matannahmani closed 3 months ago
I speculate if whether because Bun has a built-in websocket, the code is using the class with a subprotol and bun doesn't like that. I also wonder if this will break using Node's new experimental native websocket support. Hmmmmmmm
I speculate if whether because Bun has a built-in websocket, the code is using the class with a subprotol and bun doesn't like that. I also wonder if this will break using Node's new experimental native websocket support. Hmmmmmmm
I tend to agree, I'm not sure what's the expected protocol from deepgram servers but It would be best if we could polyfill it. It's a blocker for me right now, I'm trying to move my stack from assembly ai to deepgram but been breaking my head on this for the past few hours with not success.
What is the current behavior?
When running listen.live on bun the client fails to initialize and start the connection and instead immediately throws and error of client mismatch protocol
Steps to reproduce
export class AudioStream extends Readable { constructor() { super();
}
_read() {}
stopRecording() { if (this.pacat) { this.pacat.kill(); } } }
const startConnection = async () => { const deepgram = createClient('');
const LiveAudioStream = new AudioStream();
const connection = deepgram.listen.live({
model: 'nova-2',
});
connection.on(LiveTranscriptionEvents.Open, async () => { connection.getReadyState() ? console.log('Connection opened') : console.error('Connection failed to open'); LiveAudioStream.on('data', (chunk) => { if (connection && connection.getReadyState() === 1) { // convert back to raw audio connection.send(chunk); } }); });
connection.on(LiveTranscriptionEvents.Close, (event) => { console.log('Connection closed', event); });
connection.on(LiveTranscriptionEvents.Transcript, (results) => { console.log('Received transcription results', results); });
connection.on(LiveTranscriptionEvents.Metadata, (metadata) => { console.log('Received metadata', metadata); });
connection.on(LiveTranscriptionEvents.Error, (error) => { console.error('An error occurred', error); });
// connection.on(LiveTranscriptionEvents, (warning) => { // console.warn("Received a warning", warning); // });
return connection; };
void startConnection();
Connection closed CloseEvent { isTrusted: true, wasClean: true, code: 1002, reason: "Mismatch client protocol", type: "close", target: WebSocket { URL: "wss://api.deepgram.com/v1/listen?model=nova-2", url: "wss://api.deepgram.com/v1/listen?model=nova-2", readyState: 3, bufferedAmount: 0, onopen: [Function], onmessage: [Function], onerror: [Function], onclose: [Function], protocol: "", extensions: "", binaryType: "nodebuffer", send: [Function: send], close: [Function: close], ping: [Function: ping], pong: [Function: pong], terminate: [Function: terminate], CONNECTING: 0, OPEN: 1, CLOSING: 2, CLOSED: 3, addEventListener: [Function: addEventListener], removeEventListener: [Function: removeEventListener], dispatchEvent: [Function: dispatchEvent], }, currentTarget: WebSocket { URL: "wss://api.deepgram.com/v1/listen?model=nova-2", url: "wss://api.deepgram.com/v1/listen?model=nova-2", readyState: 3, bufferedAmount: 0, onopen: [Function], onmessage: [Function], onerror: [Function], onclose: [Function], protocol: "", extensions: "", binaryType: "nodebuffer", send: [Function: send], close: [Function: close], ping: [Function: ping], pong: [Function: pong], terminate: [Function: terminate], CONNECTING: 0, OPEN: 1, CLOSING: 2, CLOSED: 3, addEventListener: [Function: addEventListener], removeEventListener: [Function: removeEventListener], dispatchEvent: [Function: dispatchEvent], }, eventPhase: 2, cancelBubble: false, bubbles: false, cancelable: false, defaultPrevented: false, composed: false, timeStamp: 0, srcElement: WebSocket { URL: "wss://api.deepgram.com/v1/listen?model=nova-2", url: "wss://api.deepgram.com/v1/listen?model=nova-2", readyState: 3, bufferedAmount: 0, onopen: [Function], onmessage: [Function], onerror: [Function], onclose: [Function], protocol: "", extensions: "", binaryType: "nodebuffer", send: [Function: send], close: [Function: close], ping: [Function: ping], pong: [Function: pong], terminate: [Function: terminate], CONNECTING: 0, OPEN: 1, CLOSING: 2, CLOSED: 3, addEventListener: [Function: addEventListener], removeEventListener: [Function: removeEventListener], dispatchEvent: [Function: dispatchEvent], }, returnValue: true, composedPath: [Function: composedPath], stopPropagation: [Function: stopPropagation], stopImmediatePropagation: [Function: stopImmediatePropagation], preventDefault: [Function: preventDefault], initEvent: [Function: initEvent], NONE: 0, CAPTURING_PHASE: 1, AT_TARGET: 2, BUBBLING_PHASE: 3, }