From 0ff55dd5f8b14057be93552b894e35626bad2b32 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Wed, 24 Jan 2024 13:50:52 +0000 Subject: [PATCH] feat: add speechstarted event to sdk --- 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 cc8de9b4..7beceadd 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", + 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 7fc52cb9..f1e01c1e 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -34,6 +34,7 @@ export type { LiveTranscriptionEvent } from "./LiveTranscriptionEvent"; export type { MessageResponse } from "./MessageResponse"; export type { FileSource, PrerecordedSource, UrlSource } from "./PrerecordedSource"; export type { SendProjectInviteSchema } from "./SendProjectInviteSchema"; +export type { SpeechStartedEvent } from "./SpeechStartedEvent"; export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse"; export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema"; export type { UpdateProjectMemberScopeSchema } from "./UpdateProjectMemberScopeSchema"; diff --git a/src/packages/LiveClient.ts b/src/packages/LiveClient.ts index 2522e4f1..68deb2e4 100644 --- a/src/packages/LiveClient.ts +++ b/src/packages/LiveClient.ts @@ -11,6 +11,7 @@ import type { LiveMetadataEvent, LiveTranscriptionEvent, DeepgramClientOptions, + SpeechStartedEvent, } 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.SpeechStarted) { + this.emit(LiveTranscriptionEvents.SpeechStarted, data as SpeechStartedEvent); + } } catch (error) { this.emit(LiveTranscriptionEvents.Error, { event,