Skip to content

Commit d8de666

Browse files
authored
feat: sits for JS sdk (#233)
* feat: add audio sits features to JS sdk * fix: fix typos in sync+callback error * feat: sits analyze types and schema
1 parent 1ec3603 commit d8de666

10 files changed

Lines changed: 422 additions & 6 deletions

src/lib/helpers.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Headers as CrossFetchHeaders } from "cross-fetch";
2-
import { DeepgramClientOptions, FileSource, PrerecordedSource, UrlSource } from "./types";
2+
import {
3+
DeepgramClientOptions,
4+
FileSource,
5+
PrerecordedSource,
6+
UrlSource,
7+
TextSource,
8+
AnalyzeSource,
9+
} from "./types";
310
import { Readable } from "stream";
411
import merge from "deepmerge";
512

@@ -41,12 +48,22 @@ export const resolveHeadersConstructor = () => {
4148
return Headers;
4249
};
4350

44-
export const isUrlSource = (providedSource: PrerecordedSource): providedSource is UrlSource => {
51+
export const isUrlSource = (
52+
providedSource: PrerecordedSource | AnalyzeSource
53+
): providedSource is UrlSource => {
4554
if ((providedSource as UrlSource).url) return true;
4655

4756
return false;
4857
};
4958

59+
export const isTextSource = (
60+
providedSource: PrerecordedSource | AnalyzeSource
61+
): providedSource is TextSource => {
62+
if ((providedSource as TextSource).text) return true;
63+
64+
return false;
65+
};
66+
5067
export const isFileSource = (providedSource: PrerecordedSource): providedSource is FileSource => {
5168
if (isReadStreamSource(providedSource) || isBufferSource(providedSource)) return true;
5269

src/lib/types/AnalyzeSchema.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Options for read analysis
3+
*/
4+
interface AnalyzeSchema extends Record<string, unknown> {
5+
callback?: string;
6+
7+
callback_method?: string;
8+
9+
custom_intent?: string | string[];
10+
11+
custom_intent_mode?: "strict" | "extended";
12+
13+
custom_topic?: string | string[];
14+
15+
custom_topic_mode?: "strict" | "extended";
16+
17+
intents?: boolean;
18+
19+
language?: string;
20+
21+
summarize?: boolean;
22+
23+
sentiment?: boolean;
24+
25+
topics?: boolean;
26+
}
27+
28+
export type { AnalyzeSchema };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface AsyncAnalyzeResponse {
2+
request_id: string;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ export type FileSource = Buffer | Readable;
77
export interface UrlSource {
88
url: string;
99
}
10+
11+
export interface TextSource {
12+
text: string;
13+
}
14+
15+
export type AnalyzeSource = UrlSource | TextSource;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
export interface SyncAnalyzeResponse {
2+
model_uuid: string;
3+
metadata: Metadata;
4+
results: Results;
5+
}
6+
7+
interface IntentsInfo {
8+
model_uuid: string;
9+
input_tokens: number;
10+
output_tokens: number;
11+
}
12+
13+
interface SentimentInfo {
14+
model_uuid: string;
15+
input_tokens: number;
16+
output_tokens: number;
17+
}
18+
19+
interface SummaryInfo {
20+
model_uuid: string;
21+
input_tokens: number;
22+
output_tokens: number;
23+
}
24+
25+
interface TopicsInfo {
26+
model_uuid: string;
27+
input_tokens: number;
28+
output_tokens: number;
29+
}
30+
31+
interface Metadata {
32+
request_id: string;
33+
created: string;
34+
language: string;
35+
intents_info: IntentsInfo;
36+
sentiment_info: SentimentInfo;
37+
summary_info: SummaryInfo;
38+
topics_info: TopicsInfo;
39+
}
40+
41+
interface Average {
42+
sentiment: string;
43+
sentiment_score: number;
44+
}
45+
46+
interface Summary {
47+
text: string;
48+
}
49+
50+
interface Topic {
51+
topic: string;
52+
confidence_score: number;
53+
}
54+
55+
interface Intent {
56+
intent: string;
57+
confidence_score: number;
58+
}
59+
60+
interface Segment {
61+
text: string;
62+
start_word: number;
63+
end_word: number;
64+
sentiment: "positive" | "neutral" | "negative";
65+
sentiment_score?: number;
66+
topics?: Topic[];
67+
intents?: Intent[];
68+
}
69+
70+
interface Sentiments {
71+
segments: Segment[];
72+
average: Average;
73+
}
74+
75+
interface Topics {
76+
segments: Segment[];
77+
}
78+
79+
interface Intents {
80+
segments: Segment[];
81+
}
82+
83+
interface Results {
84+
sentiments?: Sentiments;
85+
summary?: Summary;
86+
topics?: Topics;
87+
intents?: Intents;
88+
}

src/lib/types/SyncPrerecordedResponse.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ interface Metadata {
4444
duration: number;
4545
channels: number;
4646
models: string[];
47-
model_info: Record<string, ModelInfo>;
4847
warnings?: Warning[];
48+
model_info: Record<string, ModelInfo>;
49+
summary_info?: SummaryInfo;
50+
intents_info?: IntentsInfo;
51+
sentiment_info?: SentimentInfo;
52+
topics_info?: TopicsInfo;
4953
}
5054

5155
interface ModelInfo {
@@ -54,6 +58,30 @@ interface ModelInfo {
5458
arch: string;
5559
}
5660

61+
interface SummaryInfo {
62+
input_tokens: number;
63+
output_tokens: number;
64+
model_uuid: string;
65+
}
66+
67+
interface IntentsInfo {
68+
model_uuid: string;
69+
input_tokens: number;
70+
output_tokens: number;
71+
}
72+
73+
interface SentimentInfo {
74+
model_uuid: string;
75+
input_tokens: number;
76+
output_tokens: number;
77+
}
78+
79+
interface TopicsInfo {
80+
model_uuid: string;
81+
input_tokens: number;
82+
output_tokens: number;
83+
}
84+
5785
interface Paragraph {
5886
sentences: Sentence[];
5987
start: number;
@@ -70,6 +98,47 @@ interface Result {
7098
channels: Channel[];
7199
utterances?: Utterance[];
72100
summary?: TranscriptionSummary;
101+
sentiments?: Sentiments;
102+
topics?: Topics;
103+
intents?: Intents;
104+
}
105+
106+
interface Sentiments {
107+
segments: Segment[];
108+
average: Average;
109+
}
110+
111+
interface Topics {
112+
segments: Segment[];
113+
}
114+
115+
interface Intents {
116+
segments: Segment[];
117+
}
118+
119+
interface Intent {
120+
intent: string;
121+
confidence_score: number;
122+
}
123+
124+
interface Average {
125+
sentiment: string;
126+
sentiment_score: number;
127+
}
128+
129+
interface Topic {
130+
topic: string;
131+
confidence_score: number;
132+
}
133+
134+
interface Segment {
135+
text: string;
136+
start_word: number;
137+
end_word: number;
138+
sentiment?: string;
139+
sentiment_score?: number;
140+
topics?: Topic[];
141+
intents?: Intent[];
73142
}
74143

75144
interface Search {

src/lib/types/TranscriptionSchema.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,41 @@ interface TranscriptionSchema extends Record<string, unknown> {
8383
*/
8484
tag?: string[];
8585

86+
/**
87+
* As yet unreleased.
88+
*/
89+
sentiment?: boolean;
90+
91+
/**
92+
* As yet unreleased.
93+
*/
94+
intents?: boolean;
95+
96+
/**
97+
* As yet unreleased.
98+
*/
99+
custom_intent?: string[] | string;
100+
101+
/**
102+
* As yet unreleased.
103+
*/
104+
custom_intent_mode?: "strict" | "extended";
105+
106+
/**
107+
* As yet unreleased.
108+
*/
109+
topics?: boolean;
110+
111+
/**
112+
* As yet unreleased.
113+
*/
114+
custom_topic?: string[] | string;
115+
116+
/**
117+
* As yet unreleased.
118+
*/
119+
custom_topic_mode?: "strict" | "extended";
120+
86121
[key: string]: unknown;
87122
}
88123

src/lib/types/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
export type { AnalyzeSchema } from "./AnalyzeSchema";
12
export type { AsyncPrerecordedResponse } from "./AsyncPrerecordedResponse";
3+
export type { AsyncAnalyzeResponse } from "./AsyncAnalyzeResponse";
24
export type { CreateOnPremCredentialsSchema } from "./CreateOnPremCredentialsSchema";
35
export type { CreateProjectKeySchema } from "./CreateProjectKeySchema";
46
export type { CreateProjectKeyResponse } from "./CreateProjectKeyResponse";
@@ -32,9 +34,16 @@ export type { LiveConfigOptions } from "./LiveConfigOptions";
3234
export type { LiveMetadataEvent } from "./LiveMetadataEvent";
3335
export type { LiveTranscriptionEvent } from "./LiveTranscriptionEvent";
3436
export type { MessageResponse } from "./MessageResponse";
35-
export type { FileSource, PrerecordedSource, UrlSource } from "./PrerecordedSource";
37+
export type {
38+
FileSource,
39+
PrerecordedSource,
40+
UrlSource,
41+
TextSource,
42+
AnalyzeSource,
43+
} from "./DeepgramSource";
3644
export type { SendProjectInviteSchema } from "./SendProjectInviteSchema";
3745
export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse";
46+
export type { SyncAnalyzeResponse } from "./SyncAnalyzeResponse";
3847
export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema";
3948
export type { UpdateProjectMemberScopeSchema } from "./UpdateProjectMemberScopeSchema";
4049
export type { UpdateProjectSchema } from "./UpdateProjectSchema";

src/packages/PrerecordedClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class PrerecordedClient extends AbstractRestfulClient {
2828

2929
if (options !== undefined && "callback" in options) {
3030
throw new DeepgramError(
31-
"Callback cannot be provided as an option to a synchronous transcription. Use `asyncPrerecordedUrl` or `asyncPrerecordedFile` instead."
31+
"Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
3232
);
3333
}
3434

@@ -65,7 +65,7 @@ export class PrerecordedClient extends AbstractRestfulClient {
6565

6666
if (options !== undefined && "callback" in options) {
6767
throw new DeepgramError(
68-
"Callback cannot be provided as an option to a synchronous transcription. Use `asyncPrerecordedUrl` or `asyncPrerecordedFile` instead."
68+
"Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
6969
);
7070
}
7171

0 commit comments

Comments
 (0)