From 1f80babc4c61fa29e52dfecacabaedaa88b7d665 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Thu, 25 Jan 2024 16:08:02 +0000 Subject: [PATCH] feat: add speechstarted event to sdk (#235) --- src/lib/enums/LiveTranscriptionEvents.ts | 1 + src/lib/types/SpeechStartedEvent.ts | 5 +++++ src/lib/types/index.ts | 1 + src/packages/LiveClient.ts | 5 +++++ 4 files changed, 12 insertions(+) create mode 100644 src/lib/types/SpeechStartedEvent.ts diff --git a/src/lib/enums/LiveTranscriptionEvents.ts b/src/lib/enums/LiveTranscriptionEvents.ts index 69ed1757..cad0323c 100644 --- a/src/lib/enums/LiveTranscriptionEvents.ts +++ b/src/lib/enums/LiveTranscriptionEvents.ts @@ -6,4 +6,5 @@ export enum LiveTranscriptionEvents { Error = "error", Warning = "warning", UtteranceEnd = "UtteranceEnd", // exact match to data type from API + SpeechStarted = "SpeechStarted", } diff --git a/src/lib/types/SpeechStartedEvent.ts b/src/lib/types/SpeechStartedEvent.ts new file mode 100644 index 00000000..2a8bdaba --- /dev/null +++ b/src/lib/types/SpeechStartedEvent.ts @@ -0,0 +1,5 @@ +export interface SpeechStartedEvent { + type: "SpeechStarted"; + channel: number[]; + timestamp: number; +} diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index ee281ba5..0acd1827 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -42,6 +42,7 @@ export type { AnalyzeSource, } from "./DeepgramSource"; export type { SendProjectInviteSchema } from "./SendProjectInviteSchema"; +export type { SpeechStartedEvent } from "./SpeechStartedEvent"; export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse"; export type { SyncAnalyzeResponse } from "./SyncAnalyzeResponse"; export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema"; diff --git a/src/packages/LiveClient.ts b/src/packages/LiveClient.ts index 1ed2195c..d1353cb1 100644 --- a/src/packages/LiveClient.ts +++ b/src/packages/LiveClient.ts @@ -12,6 +12,7 @@ import type { LiveTranscriptionEvent, DeepgramClientOptions, UtteranceEndEvent, + SpeechStartedEvent, } from "../lib/types"; export class LiveClient extends AbstractWsClient { @@ -58,6 +59,10 @@ export class LiveClient extends AbstractWsClient { if (data.type === LiveTranscriptionEvents.UtteranceEnd) { this.emit(LiveTranscriptionEvents.UtteranceEnd, data as UtteranceEndEvent); } + + if (data.type === LiveTranscriptionEvents.SpeechStarted) { + this.emit(LiveTranscriptionEvents.SpeechStarted, data as SpeechStartedEvent); + } } catch (error) { this.emit(LiveTranscriptionEvents.Error, { event,