deepgram / deepgram-js-sdk

Official JavaScript SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
127 stars 45 forks source link

Why Require 18.0.0+? #219

Closed seflless closed 6 months ago

seflless commented 6 months ago

I'm getting this same error as this recently closed issue: https://github.com/deepgram/deepgram-js-sdk/issues/218 (ReferenceError: Blob is not defined)

Unfortunately I can't upgrade from 16.15.0 because of legacy reasons at work, this is . Out of curiosity which features made Deepgram set this package to require node 18.0.0+? 16.15.0 isn't that old, it was released April 2021 according to the node release dates table

lukeocodes commented 6 months ago

18 was a large step towards normalising functionality with browser JS. For example, Blob is native in 18 and we use that class. That among other dependencies would require us to polyfill (which has risks and impacts of it's own) or increase the minimum node version to 18.

As this is a isomorphic SDK, a node environment that is closer to browser JS allowed us to use less polyfills and isomorphic dependencies.

The result is that the bundled code (outside of the dev build) is tiny using node 18.

lukeocodes commented 6 months ago

I will add that you're welcome to continue using version 2.14, which we will continue to bug fix. But no new features will be released on version 2.

seflless commented 6 months ago

That totally makes sense. I was able to do a work around. I may be able to move to a recent node in the future, so far the below got me unblocked.

For future explorers, I was able to get it working running in node.js 16.15.0 by using patch-package and doing the following patch, this basically removed the use of Blob. This works at least for my use case where I'm using Buffer instances when calling socket.send(audioChunkBuffer).

patches/@deepgram+sdk+3.0.1.patch

diff --git a/node_modules/@deepgram/sdk/dist/main/packages/LiveClient.js b/node_modules/@deepgram/sdk/dist/main/packages/LiveClient.js
index cf83f41..76080ec 100644
--- a/node_modules/@deepgram/sdk/dist/main/packages/LiveClient.js
+++ b/node_modules/@deepgram/sdk/dist/main/packages/LiveClient.js
@@ -72,9 +72,6 @@ class LiveClient extends AbstractWsClient_1.AbstractWsClient {
             if (typeof data === "string") {
                 this._socket.send(data); // send text data
             }
-            else if (data instanceof Blob) {
-                this._socket.send(data); // send blob data
-            }
             else {
                 const buffer = data;
                 if (buffer.byteLength > 0) {