From e5417da4610fa4e18d49c00bae10f09afce04703 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Fri, 5 Jan 2024 16:38:28 +0000 Subject: [PATCH 1/4] feat: add utteranceend event and enum --- src/lib/enums/LiveTranscriptionEvents.ts | 1 + src/lib/types/UtteranceEndEvent.ts | 3 +++ 2 files changed, 4 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/UtteranceEndEvent.ts b/src/lib/types/UtteranceEndEvent.ts new file mode 100644 index 00000000..168d0485 --- /dev/null +++ b/src/lib/types/UtteranceEndEvent.ts @@ -0,0 +1,3 @@ +export interface LiveTranscriptionEvent { + type: "UtteranceEnd"; +} From 47debed43353e69dadfbe32d07e90cf9e59df22a Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Wed, 24 Jan 2024 13:31:28 +0000 Subject: [PATCH 2/4] feat: add utteranceend event in latest format --- src/lib/types/UtteranceEndEvent.ts | 2 ++ src/packages/LiveClient.ts | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/lib/types/UtteranceEndEvent.ts b/src/lib/types/UtteranceEndEvent.ts index 168d0485..39ae2513 100644 --- a/src/lib/types/UtteranceEndEvent.ts +++ b/src/lib/types/UtteranceEndEvent.ts @@ -1,3 +1,5 @@ export interface LiveTranscriptionEvent { type: "UtteranceEnd"; + channel: number[]; + last_word_end: number; } diff --git a/src/packages/LiveClient.ts b/src/packages/LiveClient.ts index 2522e4f1..f6480806 100644 --- a/src/packages/LiveClient.ts +++ b/src/packages/LiveClient.ts @@ -53,6 +53,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 LiveTranscriptionEvent); + } } catch (error) { this.emit(LiveTranscriptionEvents.Error, { event, From 1a38be04270a7312f95a28871c9e4d14282b1f18 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Wed, 24 Jan 2024 13:52:35 +0000 Subject: [PATCH 3/4] fix: fix typo on new event --- src/lib/types/UtteranceEndEvent.ts | 2 +- src/lib/types/index.ts | 1 + src/packages/LiveClient.ts | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/types/UtteranceEndEvent.ts b/src/lib/types/UtteranceEndEvent.ts index 39ae2513..83e241cc 100644 --- a/src/lib/types/UtteranceEndEvent.ts +++ b/src/lib/types/UtteranceEndEvent.ts @@ -1,4 +1,4 @@ -export interface LiveTranscriptionEvent { +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 7fc52cb9..31954a2d 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -38,4 +38,5 @@ export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse"; 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 f6480806..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 { @@ -55,7 +56,7 @@ export class LiveClient extends AbstractWsClient { } if (data.type === LiveTranscriptionEvents.UtteranceEnd) { - this.emit(LiveTranscriptionEvents.UtteranceEnd, data as LiveTranscriptionEvent); + this.emit(LiveTranscriptionEvents.UtteranceEnd, data as UtteranceEndEvent); } } catch (error) { this.emit(LiveTranscriptionEvents.Error, { From c7a5237355a1eece282dec7edc18634344b11073 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Wed, 24 Jan 2024 16:20:24 +0000 Subject: [PATCH 4/4] fix: add missing feature flag to enable --- src/lib/types/TranscriptionSchema.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/types/TranscriptionSchema.ts b/src/lib/types/TranscriptionSchema.ts index 68dd775b..9ec3fab5 100644 --- a/src/lib/types/TranscriptionSchema.ts +++ b/src/lib/types/TranscriptionSchema.ts @@ -153,6 +153,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 };