Skip to content

Commit f598162

Browse files
authored
feat: Merge pull request #238 from deepgram/release/jan-minor-1
- feat: add missing feature toggles from q1 feature audit (#237) - feat: add speechstarted event to sdk (#235) - fix: allows endpointing to be disabled with a value of false (#236) - feat: add UtteranceEnd event to sdk (#234) - feat: sits for JS sdk (#233) - chore: update live example to include error event (#231) - feat: improve experience around usage of custom API endpoints (#230) - feat: throw errors when using v2 callstack on the v3 SDK (#226)
2 parents 7c41660 + 7f972d1 commit f598162

21 files changed

Lines changed: 711 additions & 16 deletions

examples/node-live/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const live = async () => {
2121
console.log(data);
2222
});
2323

24+
connection.on(LiveTranscriptionEvents.Error, (err) => {
25+
console.error(err);
26+
});
27+
2428
fetch(url)
2529
.then((r) => r.body)
2630
.then((res) => {

src/DeepgramClient.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DeepgramVersionError } from "./lib/errors";
12
import { AbstractClient } from "./packages/AbstractClient";
23
import { ListenClient } from "./packages/ListenClient";
34
import { ManageClient } from "./packages/ManageClient";
@@ -21,4 +22,40 @@ export default class DeepgramClient extends AbstractClient {
2122
get onprem(): OnPremClient {
2223
return new OnPremClient(this.key, this.options);
2324
}
25+
26+
/**
27+
* Major version fallback errors are below
28+
*/
29+
30+
get transcription(): any {
31+
throw new DeepgramVersionError();
32+
}
33+
34+
get projects(): any {
35+
throw new DeepgramVersionError();
36+
}
37+
38+
get keys(): any {
39+
throw new DeepgramVersionError();
40+
}
41+
42+
get members(): any {
43+
throw new DeepgramVersionError();
44+
}
45+
46+
get scopes(): any {
47+
throw new DeepgramVersionError();
48+
}
49+
50+
get invitation(): any {
51+
throw new DeepgramVersionError();
52+
}
53+
54+
get usage(): any {
55+
throw new DeepgramVersionError();
56+
}
57+
58+
get billing(): any {
59+
throw new DeepgramVersionError();
60+
}
2461
}

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import DeepgramClient from "./DeepgramClient";
2+
import { DeepgramVersionError } from "./lib/errors";
23
import type { DeepgramClientOptions } from "./lib/types";
34

5+
/**
6+
* Major version fallback error
7+
*/
8+
class Deepgram {
9+
constructor(protected apiKey: string, protected apiUrl?: string, protected requireSSL?: boolean) {
10+
throw new DeepgramVersionError();
11+
}
12+
}
13+
414
/**
515
* Creates a new Deepgram Client.
616
*/
717
const createClient = (apiKey: string, options: DeepgramClientOptions = {}): DeepgramClient => {
818
return new DeepgramClient(apiKey, options);
919
};
1020

11-
export { createClient, DeepgramClient };
21+
export { createClient, DeepgramClient, Deepgram };
1222

1323
/**
1424
* Helpful exports.

src/lib/enums/LiveTranscriptionEvents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export enum LiveTranscriptionEvents {
55
Metadata = "Metadata", // exact match to data type from API
66
Error = "error",
77
Warning = "warning",
8+
UtteranceEnd = "UtteranceEnd", // exact match to data type from API
9+
SpeechStarted = "SpeechStarted",
810
}

src/lib/errors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ export class DeepgramUnknownError extends DeepgramError {
3838
this.originalError = originalError;
3939
}
4040
}
41+
42+
export class DeepgramVersionError extends DeepgramError {
43+
constructor() {
44+
super(
45+
`You are attempting to use an old format for a newer SDK version. Read more here: https://dpgr.am/js-v3`
46+
);
47+
48+
this.name = "DeepgramVersionError";
49+
}
50+
}

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface SpeechStartedEvent {
2+
type: "SpeechStarted";
3+
channel: number[];
4+
timestamp: number;
5+
}

0 commit comments

Comments
 (0)