From 82f8b2fbadd656bc19434e82418c0ee9a484a721 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Thu, 25 Jan 2024 16:05:30 +0000 Subject: [PATCH] feat: add UtteranceEnd event to sdk (#234) * feat: add utteranceend event and enum * feat: add utteranceend event in latest format * fix: fix typo on new event * fix: add missing feature flag to enable --- src/lib/enums/LiveTranscriptionEvents.ts | 1 + src/lib/types/TranscriptionSchema.ts | 5 +++++ src/lib/types/UtteranceEndEvent.ts | 5 +++++ src/lib/types/index.ts | 1 + src/packages/LiveClient.ts | 5 +++++ 5 files changed, 17 insertions(+) create mode 100644 src/lib/types/UtteranceEndEvent.ts diff --git a/src/lib/enums/LiveTranscriptionEvents.ts b/src/lib/enums/LiveTranscriptionEvents.ts index cc8de9b4..69ed1757 100644 --- a/src/lib/enums/LiveTranscriptionEvents.ts +++ b/src/lib/enums/LiveTranscriptionEvents.ts @@ -5,4 +5,5 @@ export enum LiveTranscriptionEvents { Metadata = "Metadata", // exact match to data type from API Error = "error", Warning = "warning", + UtteranceEnd = "UtteranceEnd", // exact match to data type from API } diff --git a/src/lib/types/TranscriptionSchema.ts b/src/lib/types/TranscriptionSchema.ts index 2dd121b7..a4bc0594 100644 --- a/src/lib/types/TranscriptionSchema.ts +++ b/src/lib/types/TranscriptionSchema.ts @@ -188,6 +188,11 @@ interface LiveSchema extends TranscriptionSchema { * @see https://developers.deepgram.com/docs/interim-results */ interim_results?: boolean; + + /** + * @see https://developers.deepgram.com/docs/understanding-end-of-speech-detection + */ + utterance_end_ms?: number; } export type { TranscriptionSchema, PrerecordedSchema, LiveSchema }; diff --git a/src/lib/types/UtteranceEndEvent.ts b/src/lib/types/UtteranceEndEvent.ts new file mode 100644 index 00000000..83e241cc --- /dev/null +++ b/src/lib/types/UtteranceEndEvent.ts @@ -0,0 +1,5 @@ +export interface UtteranceEndEvent { + type: "UtteranceEnd"; + channel: number[]; + last_word_end: number; +} diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 7f8a3268..ee281ba5 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -47,4 +47,5 @@ export type { SyncAnalyzeResponse } from "./SyncAnalyzeResponse"; export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema"; export type { UpdateProjectMemberScopeSchema } from "./UpdateProjectMemberScopeSchema"; export type { UpdateProjectSchema } from "./UpdateProjectSchema"; +export type { UtteranceEndEvent } from "./UtteranceEndEvent"; export type { VoidResponse } from "./VoidResponse"; diff --git a/src/packages/LiveClient.ts b/src/packages/LiveClient.ts index 2522e4f1..1ed2195c 100644 --- a/src/packages/LiveClient.ts +++ b/src/packages/LiveClient.ts @@ -11,6 +11,7 @@ import type { LiveMetadataEvent, LiveTranscriptionEvent, DeepgramClientOptions, + UtteranceEndEvent, } from "../lib/types"; export class LiveClient extends AbstractWsClient { @@ -53,6 +54,10 @@ export class LiveClient extends AbstractWsClient { if (data.type === LiveTranscriptionEvents.Transcript) { this.emit(LiveTranscriptionEvents.Transcript, data as LiveTranscriptionEvent); } + + if (data.type === LiveTranscriptionEvents.UtteranceEnd) { + this.emit(LiveTranscriptionEvents.UtteranceEnd, data as UtteranceEndEvent); + } } catch (error) { this.emit(LiveTranscriptionEvents.Error, { event,