Skip to content

Commit fc6be4b

Browse files
committed
Adding paragraphs feature to SDK
1 parent 2242db7 commit fc6be4b

10 files changed

Lines changed: 9193 additions & 50 deletions

package-lock.json

Lines changed: 9095 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/types/alternatives.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ParagraphGroup } from "./paragraphGroup";
2+
import { WordBase } from "./wordBase";
3+
4+
export type Alternative = {
5+
/**
6+
* Text of speech identified by API
7+
*/
8+
transcript: string;
9+
/**
10+
* Confidence in transcript generated
11+
*/
12+
confidence: number;
13+
/**
14+
* Array of words included in the transcript
15+
*/
16+
words: Array<WordBase>;
17+
/**
18+
* Array of paragraph objects.
19+
*/
20+
paragraphs?: Array<ParagraphGroup>;
21+
};

src/types/channel.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { Alternative } from "./alternatives";
12
import { Search } from "./search";
2-
import { WordBase } from "./wordBase";
33

44
/**
55
* Channel of speech identified by Deepgram
@@ -9,18 +9,8 @@ export type Channel = {
99
* Searched terms & results
1010
*/
1111
search?: Array<Search>;
12-
alternatives: Array<{
13-
/**
14-
* Text of speech identified by API
15-
*/
16-
transcript: string;
17-
/**
18-
* Confidence in transcript generated
19-
*/
20-
confidence: number;
21-
/**
22-
* Array of words included in the transcript
23-
*/
24-
words: Array<WordBase>;
25-
}>;
12+
/**
13+
* Transcription alternatives
14+
*/
15+
alternatives: Array<Alternative>;
2616
};

src/types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./alternatives";
12
export * from "./balance";
23
export * from "./balanceList";
34
export * from "./channel";
@@ -13,13 +14,16 @@ export * from "./member";
1314
export * from "./memberList";
1415
export * from "./message";
1516
export * from "./metadata";
17+
export * from "./paragraph";
18+
export * from "./paragraphGroup";
1619
export * from "./prerecordedTranscriptionOptions";
1720
export * from "./prerecordedTranscriptionResponse";
1821
export * from "./project";
1922
export * from "./projectPatchResponse";
2023
export * from "./projectResponse";
2124
export * from "./scopeList";
2225
export * from "./search";
26+
export * from "./sentence";
2327
export * from "./transcriptionSource";
2428
export * from "./usageCallback";
2529
export * from "./usageField";

src/types/liveTranscriptionOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,11 @@ export type LiveTranscriptionOptions = {
175175
* @see https://developers.deepgram.com/api-reference/speech-recognition-api#operation/transcribeStreamingAudio/properties/sample_rate
176176
*/
177177
sample_rate?: number;
178+
179+
/**
180+
* Indicates whether Deepgram will split audio into paragraphs to improve transcript
181+
* readability. When paragraphs is set to true, you must also set either punctuate,
182+
* diarize, or multichannel to true.
183+
*/
184+
paragraphs?: boolean;
178185
};

src/types/paragraph.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Sentence } from "./sentence";
2+
3+
export type Paragraph = {
4+
/**
5+
* Sentences within the paragraph.
6+
*/
7+
sentences: Array<Sentence>;
8+
/**
9+
* Start time (in seconds) from the start of the audio to where the paragraph starts.
10+
*/
11+
start: number;
12+
/**
13+
* End time (in seconds) from the start of the audio to where the paragraph ends.
14+
*/
15+
end: number;
16+
/**
17+
* Number of words in the paragraph
18+
*/
19+
num_words: number;
20+
};

src/types/paragraphGroup.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Paragraph } from "./paragraph";
2+
3+
export type ParagraphGroup = {
4+
/**
5+
* Full transcript
6+
*/
7+
transcript: string;
8+
/**
9+
* Array of Paragraph objects.
10+
*/
11+
paragraphs: Array<Paragraph>;
12+
};

src/types/prerecordedTranscriptionOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,11 @@ export type PrerecordedTranscriptionOptions = {
153153
* @see https://developers.deepgram.com/api-reference/speech-recognition-api#operation/transcribeAudio/properties/utt_split
154154
*/
155155
utt_split?: number;
156+
157+
/**
158+
* Indicates whether Deepgram will split audio into paragraphs to improve transcript
159+
* readability. When paragraphs is set to true, you must also set either punctuate,
160+
* diarize, or multichannel to true.
161+
*/
162+
paragraphs?: boolean;
156163
};

src/types/sentence.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type Sentence = {
2+
/**
3+
* Text transcript of the sentence.
4+
*/
5+
text: string;
6+
/**
7+
* Start time (in seconds) from the start of the audio to where the sentence starts.
8+
*/
9+
start: number;
10+
/**
11+
* End time (in seconds) from the start of the audio to where the sentence ends.
12+
*/
13+
end: number;
14+
};

src/userAgent.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
/*
2-
* The following const is replaced during the CD
3-
* process to the version from package.json
4-
*/
2+
* The following const is replaced during the CD
3+
* process to the version from package.json
4+
*/
55
const sdkVersion = "DG_SDK_VERSION";
66

77
export function userAgent(): string {
88
let agent = "@deepgram/sdk/UNKNOWN node/UNKNOWN";
99
try {
10-
agent = `@deepgram/sdk/${sdkVersion} node/${process.version.replace("v", "")}`;
10+
agent = `@deepgram/sdk/${sdkVersion} node/${process.version.replace(
11+
"v",
12+
""
13+
)}`;
1114
} catch (e) {
1215
console.warn("Could not load package details");
1316
}
1417
return agent;
15-
}
18+
}

0 commit comments

Comments
 (0)