Skip to content

Commit

Permalink
feat: add speechstarted event to sdk (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeocodes authored Jan 25, 2024
1 parent 1add378 commit 1f80bab
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/enums/LiveTranscriptionEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export enum LiveTranscriptionEvents {
Error = "error",
Warning = "warning",
UtteranceEnd = "UtteranceEnd", // exact match to data type from API
SpeechStarted = "SpeechStarted",
}
5 changes: 5 additions & 0 deletions src/lib/types/SpeechStartedEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface SpeechStartedEvent {
type: "SpeechStarted";
channel: number[];
timestamp: number;
}
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 5 additions & 0 deletions src/packages/LiveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
LiveTranscriptionEvent,
DeepgramClientOptions,
UtteranceEndEvent,
SpeechStartedEvent,
} from "../lib/types";

export class LiveClient extends AbstractWsClient {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1f80bab

Please sign in to comment.