deepgram/deepgram-js-sdk

Simple fix: add LiveTranscriptionEvents enum

Closed this issue · 3 comments

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) {

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

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