Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add UtteranceEnd event to sdk #234

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 };
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 @@ -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";
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