deepgram / deepgram-js-sdk

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

`deepgram.transcription.live` has a difficult to use return type #139

Closed bensalilijames closed 1 year ago

bensalilijames commented 1 year ago

What is the current behavior?

deepgram.transcription.live returns a LiveTranscription | ErrorResponse, which makes it a bit unergonomic to use in TypeScript, because you have to explicitly cast the result to LiveTranscription:

const transcriber = deepgram.transcription.live({
  model: "nova",
  // other options...
}) as LiveTranscription;

Since it can never be ErrorResponse (see implementation here, which can only return a new instance of LiveTranscription) would you consider reverting this change to how it was pre 2.0.0, where it just returns LiveTranscription?

If it's important to keep ErrorResponse, would you be able to suggest a way to safely use the return value, e.g. exporting LiveTranscription and ErrorResponse from this package, and thereby adding support for:

if (transcriber instanceof LiveTranscription) {
  // happy
} else if (transcriber instanceof ErrorResponse) {
  // not happy
}

Thank you! 😃

lukeocodes commented 1 year ago

This is a really good explanation and suggestion. We have a PR in-progress to revert those changes, and I am planning on a change for the v3 SDK to change it to a pattern that i've personally got a lot more enjoyment from using

const { ws, error } = deepgram.transcription.live({...etc});

and

const { result, error } = deepgram.transcription.preRecorded({...etc});
lukeocodes commented 1 year ago

closed by #142