Skip to content

Commit

Permalink
feat: add UtteranceEnd event to sdk (#234)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lukeocodes authored Jan 25, 2024
1 parent d8de666 commit 82f8b2f
Show file tree
Hide file tree
Showing 5 changed files with 17 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 @@ -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
}
5 changes: 5 additions & 0 deletions src/lib/types/TranscriptionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
5 changes: 5 additions & 0 deletions src/lib/types/UtteranceEndEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface UtteranceEndEvent {
type: "UtteranceEnd";
channel: number[];
last_word_end: number;
}
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
5 changes: 5 additions & 0 deletions src/packages/LiveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
LiveMetadataEvent,
LiveTranscriptionEvent,
DeepgramClientOptions,
UtteranceEndEvent,
} from "../lib/types";

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

0 comments on commit 82f8b2f

Please sign in to comment.