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

Simple fix: add LiveTranscriptionEvents enum #298

Closed tieje3 closed 4 weeks ago

tieje3 commented 4 weeks ago

Proposed changes

Current code:

export interface LiveTranscriptionEvent {
  type: "Results";
  channel_index: number[];
  duration: number;
  start: number;
  // ... etc.
  };
}
import { LiveTranscriptionEvents } from "../enums";

export interface LiveTranscriptionEvent {
  type: LiveTranscriptionEvents;
  channel_index: number[];
  duration: number;
  start: number;
  // ... etc.
  };
}

Context

Desired for ease of use.

I understand that this is here because it depends on the type of connection that you're listening to:

connection.addListener(LiveTranscriptionEvents.Transcript, onTranscript);
connection.addListener(LiveTranscriptionEvents.UtteranceEnd, onTranscript);

The workaround for now is to add a @ts-ignore pragma:

const onUtteranceEnd = (data: LiveTranscriptionEvent) => {
    const { type } = data;
    // @ts-ignore
    if (type === LiveTranscriptionEvents.UtteranceEnd) {
tieje3 commented 4 weeks ago

I guess you don't really need it because you'll only ever receive the event and not much more info than that.

lukeocodes commented 4 weeks ago

I think you'd get a TS error if you data never matched the event coming through?

tieje3 commented 4 weeks ago

Thanks for the quick response. I realized that I was just being dumb and I closed the ticket. 😊 You may wish to review the ticket for future updates though.

From: Luke Oliff @.> Sent: Tuesday, May 28, 2024 11:49 AM To: deepgram/deepgram-js-sdk @.> Cc: Francis, Thomas James @.>; State change @.> Subject: Re: [deepgram/deepgram-js-sdk] Simple fix: add LiveTranscriptionEvents enum (Issue #298)

I think you'd get a TS error if you data never matched the event coming through?

— Reply to this email directly, view it on GitHubhttps://github.com/deepgram/deepgram-js-sdk/issues/298#issuecomment-2135585483, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BIFMW5BO5ZCEUU22HLIBG23ZESRPZAVCNFSM6AAAAABINDABGCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZVGU4DKNBYGM. You are receiving this because you modified the open/close state.Message ID: @.***>