Skip to content

Commit 23bf960

Browse files
committed
feat: support nova-3 and keyterms in stt
1 parent 21dcc9b commit 23bf960

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

examples/node-live/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const live = async () => {
1010
let is_finals = [];
1111

1212
const connection = deepgram.listen.live({
13-
model: "nova-2",
13+
model: "nova-3",
1414
language: "en-US",
1515
// Apply smart formatting to the output
1616
smart_format: true,
@@ -20,6 +20,8 @@ const live = async () => {
2020
vad_events: true,
2121
// Time in milliseconds of silence to wait for before finalizing speech
2222
endpointing: 300,
23+
// Keyterm Prompting allows you improve Keyword Recall Rate (KRR) for important keyterms or phrases up to 90%.
24+
keyterms: ["BBC"],
2325
});
2426

2527
connection.on(LiveTranscriptionEvents.Open, () => {

examples/node-prerecorded/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const transcribeUrl = async () => {
1111
url: "https://dpgr.am/spacewalk.wav",
1212
},
1313
{
14-
model: "nova-2",
14+
model: "nova-3",
15+
keyterms: ["spacewalk"],
1516
}
1617
);
1718

@@ -28,7 +29,8 @@ const transcribeFile = async () => {
2829

2930
console.log("Transcribing file", file);
3031
const { result, error } = await deepgram.listen.prerecorded.transcribeFile(file, {
31-
model: "nova-2",
32+
model: "nova-3",
33+
keyterms: ["spacewalk"],
3234
});
3335

3436
if (error) console.error(error);

src/lib/types/TranscriptionSchema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ interface TranscriptionSchema extends Record<string, unknown> {
9494
*/
9595
keywords?: string[] | string;
9696

97+
/**
98+
* @see https://developers.deepgram.com/docs/keyterm
99+
*/
100+
keyterms?: string[] | string;
101+
97102
/**
98103
* @see https://developers.deepgram.com/docs/tagging
99104
*/

src/packages/ListenLiveClient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AbstractLiveClient } from "./AbstractLiveClient";
22
import { LiveTranscriptionEvents } from "../lib/enums";
33
import type { LiveSchema, LiveConfigOptions, DeepgramClientOptions } from "../lib/types";
4+
import { DeepgramError } from "../lib/errors";
45

56
/**
67
* The `ListenLiveClient` class extends the `AbstractLiveClient` class and provides functionality for setting up and managing a WebSocket connection for live transcription.
@@ -34,6 +35,13 @@ export class ListenLiveClient extends AbstractLiveClient {
3435
) {
3536
super(options);
3637

38+
if (
39+
transcriptionOptions.keyterms?.length &&
40+
!transcriptionOptions.model?.startsWith("nova-3")
41+
) {
42+
throw new DeepgramError("Keyterms are only supported with the Nova 3 models.");
43+
}
44+
3745
this.connect(transcriptionOptions, endpoint);
3846
}
3947

src/packages/ListenRestClient.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class ListenRestClient extends AbstractRestClient {
5252
);
5353
}
5454

55+
if (options?.keyterms?.length && !options.model?.startsWith("nova-3")) {
56+
throw new DeepgramError("Keyterms are only supported with the Nova 3 models.");
57+
}
58+
5559
const requestUrl = this.getRequestUrl(endpoint, {}, { ...{}, ...options });
5660
const result: SyncPrerecordedResponse = await this.post(requestUrl, body).then((result) =>
5761
result.json()

0 commit comments

Comments
 (0)