@deepgram/sdk 3.3.5 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -9
- package/dist/main/DeepgramClient.d.ts +65 -12
- package/dist/main/DeepgramClient.d.ts.map +1 -1
- package/dist/main/DeepgramClient.js +73 -18
- package/dist/main/DeepgramClient.js.map +1 -1
- package/dist/main/index.d.ts +13 -4
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +18 -8
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/constants.d.ts +16 -7
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +26 -9
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/enums/LiveConnectionState.d.ts +5 -0
- package/dist/main/lib/enums/LiveConnectionState.d.ts.map +1 -1
- package/dist/main/lib/enums/LiveConnectionState.js +5 -0
- package/dist/main/lib/enums/LiveConnectionState.js.map +1 -1
- package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
- package/dist/main/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
- package/dist/main/lib/enums/LiveTranscriptionEvents.js +23 -2
- package/dist/main/lib/enums/LiveTranscriptionEvents.js.map +1 -1
- package/dist/main/lib/enums/index.d.ts +2 -2
- package/dist/main/lib/enums/index.d.ts.map +1 -1
- package/dist/main/lib/enums/index.js +16 -5
- package/dist/main/lib/enums/index.js.map +1 -1
- package/dist/main/lib/fetch.d.ts +19 -1
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +19 -1
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +9 -5
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +82 -7
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/types/CreateProjectKeySchema.d.ts +0 -1
- package/dist/main/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
- package/dist/main/lib/types/DeepgramClientOptions.d.ts +75 -8
- package/dist/main/lib/types/DeepgramClientOptions.d.ts.map +1 -1
- package/dist/main/lib/types/Fetch.d.ts +3 -13
- package/dist/main/lib/types/Fetch.d.ts.map +1 -1
- package/dist/main/lib/types/LiveConfigOptions.d.ts +6 -3
- package/dist/main/lib/types/LiveConfigOptions.d.ts.map +1 -1
- package/dist/main/lib/types/TranscriptionSchema.d.ts +0 -1
- package/dist/main/lib/types/TranscriptionSchema.d.ts.map +1 -1
- package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
- package/dist/main/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
- package/dist/main/lib/types/UpdateProjectSchema.d.ts +0 -1
- package/dist/main/lib/types/UpdateProjectSchema.d.ts.map +1 -1
- package/dist/main/lib/types/index.d.ts +39 -39
- package/dist/main/lib/types/index.d.ts.map +1 -1
- package/dist/main/lib/types/index.js +53 -0
- package/dist/main/lib/types/index.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/packages/AbstractClient.d.ts +63 -10
- package/dist/main/packages/AbstractClient.d.ts.map +1 -1
- package/dist/main/packages/AbstractClient.js +103 -50
- package/dist/main/packages/AbstractClient.js.map +1 -1
- package/dist/main/packages/AbstractLiveClient.d.ts +114 -0
- package/dist/main/packages/AbstractLiveClient.d.ts.map +1 -0
- package/dist/main/packages/AbstractLiveClient.js +238 -0
- package/dist/main/packages/AbstractLiveClient.js.map +1 -0
- package/dist/main/packages/AbstractRestClient.d.ts +105 -0
- package/dist/main/packages/AbstractRestClient.d.ts.map +1 -0
- package/dist/main/packages/AbstractRestClient.js +185 -0
- package/dist/main/packages/AbstractRestClient.js.map +1 -0
- package/dist/main/packages/ListenClient.d.ts +21 -4
- package/dist/main/packages/ListenClient.d.ts.map +1 -1
- package/dist/main/packages/ListenClient.js +25 -5
- package/dist/main/packages/ListenClient.js.map +1 -1
- package/dist/main/packages/ListenLiveClient.d.ts +58 -0
- package/dist/main/packages/ListenLiveClient.d.ts.map +1 -0
- package/dist/main/packages/ListenLiveClient.js +119 -0
- package/dist/main/packages/ListenLiveClient.js.map +1 -0
- package/dist/main/packages/ListenRestClient.d.ts +57 -0
- package/dist/main/packages/ListenRestClient.d.ts.map +1 -0
- package/dist/main/packages/ListenRestClient.js +167 -0
- package/dist/main/packages/ListenRestClient.js.map +1 -0
- package/dist/main/packages/ManageRestClient.d.ts +286 -0
- package/dist/main/packages/ManageRestClient.d.ts.map +1 -0
- package/dist/main/packages/ManageRestClient.js +628 -0
- package/dist/main/packages/ManageRestClient.js.map +1 -0
- package/dist/main/packages/ReadRestClient.d.ts +57 -0
- package/dist/main/packages/ReadRestClient.d.ts.map +1 -0
- package/dist/main/packages/ReadRestClient.js +165 -0
- package/dist/main/packages/ReadRestClient.js.map +1 -0
- package/dist/main/packages/SelfHostedRestClient.d.ts +47 -0
- package/dist/main/packages/SelfHostedRestClient.d.ts.map +1 -0
- package/dist/main/packages/SelfHostedRestClient.js +120 -0
- package/dist/main/packages/SelfHostedRestClient.js.map +1 -0
- package/dist/main/packages/SpeakRestClient.d.ts +36 -0
- package/dist/main/packages/SpeakRestClient.d.ts.map +1 -0
- package/dist/main/packages/SpeakRestClient.js +84 -0
- package/dist/main/packages/SpeakRestClient.js.map +1 -0
- package/dist/main/packages/index.d.ts +10 -8
- package/dist/main/packages/index.d.ts.map +1 -1
- package/dist/main/packages/index.js +24 -17
- package/dist/main/packages/index.js.map +1 -1
- package/dist/module/DeepgramClient.d.ts +65 -12
- package/dist/module/DeepgramClient.d.ts.map +1 -1
- package/dist/module/DeepgramClient.js +72 -17
- package/dist/module/DeepgramClient.js.map +1 -1
- package/dist/module/index.d.ts +13 -4
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +18 -8
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/constants.d.ts +16 -7
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +26 -9
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/enums/LiveConnectionState.d.ts +5 -0
- package/dist/module/lib/enums/LiveConnectionState.d.ts.map +1 -1
- package/dist/module/lib/enums/LiveConnectionState.js +5 -0
- package/dist/module/lib/enums/LiveConnectionState.js.map +1 -1
- package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts +24 -3
- package/dist/module/lib/enums/LiveTranscriptionEvents.d.ts.map +1 -1
- package/dist/module/lib/enums/LiveTranscriptionEvents.js +23 -2
- package/dist/module/lib/enums/LiveTranscriptionEvents.js.map +1 -1
- package/dist/module/lib/enums/index.d.ts +2 -2
- package/dist/module/lib/enums/index.d.ts.map +1 -1
- package/dist/module/lib/enums/index.js +2 -2
- package/dist/module/lib/enums/index.js.map +1 -1
- package/dist/module/lib/fetch.d.ts +19 -1
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +19 -1
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +9 -5
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +75 -4
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/types/CreateProjectKeySchema.d.ts +0 -1
- package/dist/module/lib/types/CreateProjectKeySchema.d.ts.map +1 -1
- package/dist/module/lib/types/DeepgramClientOptions.d.ts +75 -8
- package/dist/module/lib/types/DeepgramClientOptions.d.ts.map +1 -1
- package/dist/module/lib/types/Fetch.d.ts +3 -13
- package/dist/module/lib/types/Fetch.d.ts.map +1 -1
- package/dist/module/lib/types/LiveConfigOptions.d.ts +6 -3
- package/dist/module/lib/types/LiveConfigOptions.d.ts.map +1 -1
- package/dist/module/lib/types/TranscriptionSchema.d.ts +0 -1
- package/dist/module/lib/types/TranscriptionSchema.d.ts.map +1 -1
- package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts +1 -1
- package/dist/module/lib/types/UpdateProjectMemberScopeSchema.d.ts.map +1 -1
- package/dist/module/lib/types/UpdateProjectSchema.d.ts +0 -1
- package/dist/module/lib/types/UpdateProjectSchema.d.ts.map +1 -1
- package/dist/module/lib/types/index.d.ts +39 -39
- package/dist/module/lib/types/index.d.ts.map +1 -1
- package/dist/module/lib/types/index.js +39 -1
- package/dist/module/lib/types/index.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/packages/AbstractClient.d.ts +63 -10
- package/dist/module/packages/AbstractClient.d.ts.map +1 -1
- package/dist/module/packages/AbstractClient.js +99 -50
- package/dist/module/packages/AbstractClient.js.map +1 -1
- package/dist/module/packages/AbstractLiveClient.d.ts +114 -0
- package/dist/module/packages/AbstractLiveClient.d.ts.map +1 -0
- package/dist/module/packages/AbstractLiveClient.js +211 -0
- package/dist/module/packages/AbstractLiveClient.js.map +1 -0
- package/dist/module/packages/AbstractRestClient.d.ts +105 -0
- package/dist/module/packages/AbstractRestClient.d.ts.map +1 -0
- package/dist/module/packages/AbstractRestClient.js +178 -0
- package/dist/module/packages/AbstractRestClient.js.map +1 -0
- package/dist/module/packages/ListenClient.d.ts +21 -4
- package/dist/module/packages/ListenClient.d.ts.map +1 -1
- package/dist/module/packages/ListenClient.js +25 -5
- package/dist/module/packages/ListenClient.js.map +1 -1
- package/dist/module/packages/ListenLiveClient.d.ts +58 -0
- package/dist/module/packages/ListenLiveClient.d.ts.map +1 -0
- package/dist/module/packages/ListenLiveClient.js +115 -0
- package/dist/module/packages/ListenLiveClient.js.map +1 -0
- package/dist/module/packages/ListenRestClient.d.ts +57 -0
- package/dist/module/packages/ListenRestClient.d.ts.map +1 -0
- package/dist/module/packages/ListenRestClient.js +163 -0
- package/dist/module/packages/ListenRestClient.js.map +1 -0
- package/dist/module/packages/ManageRestClient.d.ts +286 -0
- package/dist/module/packages/ManageRestClient.d.ts.map +1 -0
- package/dist/module/packages/ManageRestClient.js +624 -0
- package/dist/module/packages/ManageRestClient.js.map +1 -0
- package/dist/module/packages/ReadRestClient.d.ts +57 -0
- package/dist/module/packages/ReadRestClient.d.ts.map +1 -0
- package/dist/module/packages/ReadRestClient.js +161 -0
- package/dist/module/packages/ReadRestClient.js.map +1 -0
- package/dist/module/packages/SelfHostedRestClient.d.ts +47 -0
- package/dist/module/packages/SelfHostedRestClient.d.ts.map +1 -0
- package/dist/module/packages/SelfHostedRestClient.js +116 -0
- package/dist/module/packages/SelfHostedRestClient.js.map +1 -0
- package/dist/module/packages/SpeakRestClient.d.ts +36 -0
- package/dist/module/packages/SpeakRestClient.d.ts.map +1 -0
- package/dist/module/packages/SpeakRestClient.js +80 -0
- package/dist/module/packages/SpeakRestClient.js.map +1 -0
- package/dist/module/packages/index.d.ts +10 -8
- package/dist/module/packages/index.d.ts.map +1 -1
- package/dist/module/packages/index.js +10 -8
- package/dist/module/packages/index.js.map +1 -1
- package/dist/umd/deepgram.js +1 -1
- package/package.json +8 -6
- package/src/DeepgramClient.ts +81 -17
- package/src/index.ts +32 -7
- package/src/lib/constants.ts +33 -13
- package/src/lib/enums/LiveConnectionState.ts +11 -4
- package/src/lib/enums/LiveTranscriptionEvents.ts +27 -4
- package/src/lib/enums/index.ts +2 -2
- package/src/lib/fetch.ts +22 -2
- package/src/lib/helpers.ts +98 -9
- package/src/lib/types/CreateProjectKeySchema.ts +0 -1
- package/src/lib/types/DeepgramClientOptions.ts +75 -11
- package/src/lib/types/Fetch.ts +2 -24
- package/src/lib/types/LiveConfigOptions.ts +7 -3
- package/src/lib/types/TranscriptionSchema.ts +0 -2
- package/src/lib/types/UpdateProjectMemberScopeSchema.ts +1 -1
- package/src/lib/types/UpdateProjectSchema.ts +0 -1
- package/src/lib/types/index.ts +39 -54
- package/src/lib/version.ts +1 -1
- package/src/packages/AbstractClient.ts +129 -61
- package/src/packages/AbstractLiveClient.ts +280 -0
- package/src/packages/AbstractRestClient.ts +221 -0
- package/src/packages/ListenClient.ts +26 -5
- package/src/packages/ListenLiveClient.ts +133 -0
- package/src/packages/ListenRestClient.ts +201 -0
- package/src/packages/ManageRestClient.ts +760 -0
- package/src/packages/ReadRestClient.ts +200 -0
- package/src/packages/SelfHostedRestClient.ts +134 -0
- package/src/packages/SpeakRestClient.ts +79 -0
- package/src/packages/index.ts +10 -8
- package/dist/main/packages/AbstractRestfulClient.d.ts +0 -26
- package/dist/main/packages/AbstractRestfulClient.d.ts.map +0 -1
- package/dist/main/packages/AbstractRestfulClient.js +0 -118
- package/dist/main/packages/AbstractRestfulClient.js.map +0 -1
- package/dist/main/packages/AbstractWsClient.d.ts +0 -10
- package/dist/main/packages/AbstractWsClient.d.ts.map +0 -1
- package/dist/main/packages/AbstractWsClient.js +0 -33
- package/dist/main/packages/AbstractWsClient.js.map +0 -1
- package/dist/main/packages/LiveClient.d.ts +0 -28
- package/dist/main/packages/LiveClient.d.ts.map +0 -1
- package/dist/main/packages/LiveClient.js +0 -110
- package/dist/main/packages/LiveClient.js.map +0 -1
- package/dist/main/packages/ManageClient.d.ts +0 -97
- package/dist/main/packages/ManageClient.d.ts.map +0 -1
- package/dist/main/packages/ManageClient.js +0 -463
- package/dist/main/packages/ManageClient.js.map +0 -1
- package/dist/main/packages/OnPremClient.d.ts +0 -21
- package/dist/main/packages/OnPremClient.d.ts.map +0 -1
- package/dist/main/packages/OnPremClient.js +0 -99
- package/dist/main/packages/OnPremClient.js.map +0 -1
- package/dist/main/packages/PrerecordedClient.d.ts +0 -10
- package/dist/main/packages/PrerecordedClient.d.ts.map +0 -1
- package/dist/main/packages/PrerecordedClient.js +0 -125
- package/dist/main/packages/PrerecordedClient.js.map +0 -1
- package/dist/main/packages/ReadClient.d.ts +0 -10
- package/dist/main/packages/ReadClient.d.ts.map +0 -1
- package/dist/main/packages/ReadClient.js +0 -123
- package/dist/main/packages/ReadClient.js.map +0 -1
- package/dist/main/packages/SpeakClient.d.ts +0 -12
- package/dist/main/packages/SpeakClient.d.ts.map +0 -1
- package/dist/main/packages/SpeakClient.js +0 -57
- package/dist/main/packages/SpeakClient.js.map +0 -1
- package/dist/module/packages/AbstractRestfulClient.d.ts +0 -26
- package/dist/module/packages/AbstractRestfulClient.d.ts.map +0 -1
- package/dist/module/packages/AbstractRestfulClient.js +0 -114
- package/dist/module/packages/AbstractRestfulClient.js.map +0 -1
- package/dist/module/packages/AbstractWsClient.d.ts +0 -10
- package/dist/module/packages/AbstractWsClient.d.ts.map +0 -1
- package/dist/module/packages/AbstractWsClient.js +0 -29
- package/dist/module/packages/AbstractWsClient.js.map +0 -1
- package/dist/module/packages/LiveClient.d.ts +0 -28
- package/dist/module/packages/LiveClient.d.ts.map +0 -1
- package/dist/module/packages/LiveClient.js +0 -106
- package/dist/module/packages/LiveClient.js.map +0 -1
- package/dist/module/packages/ManageClient.d.ts +0 -97
- package/dist/module/packages/ManageClient.d.ts.map +0 -1
- package/dist/module/packages/ManageClient.js +0 -459
- package/dist/module/packages/ManageClient.js.map +0 -1
- package/dist/module/packages/OnPremClient.d.ts +0 -21
- package/dist/module/packages/OnPremClient.d.ts.map +0 -1
- package/dist/module/packages/OnPremClient.js +0 -95
- package/dist/module/packages/OnPremClient.js.map +0 -1
- package/dist/module/packages/PrerecordedClient.d.ts +0 -10
- package/dist/module/packages/PrerecordedClient.d.ts.map +0 -1
- package/dist/module/packages/PrerecordedClient.js +0 -121
- package/dist/module/packages/PrerecordedClient.js.map +0 -1
- package/dist/module/packages/ReadClient.d.ts +0 -10
- package/dist/module/packages/ReadClient.d.ts.map +0 -1
- package/dist/module/packages/ReadClient.js +0 -119
- package/dist/module/packages/ReadClient.js.map +0 -1
- package/dist/module/packages/SpeakClient.d.ts +0 -12
- package/dist/module/packages/SpeakClient.d.ts.map +0 -1
- package/dist/module/packages/SpeakClient.js +0 -53
- package/dist/module/packages/SpeakClient.js.map +0 -1
- package/src/packages/AbstractRestfulClient.ts +0 -160
- package/src/packages/AbstractWsClient.ts +0 -42
- package/src/packages/LiveClient.ts +0 -140
- package/src/packages/ManageClient.ts +0 -584
- package/src/packages/OnPremClient.ts +0 -113
- package/src/packages/PrerecordedClient.ts +0 -162
- package/src/packages/ReadClient.ts +0 -161
- package/src/packages/SpeakClient.ts +0 -50
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { AbstractRestfulClient } from "./AbstractRestfulClient";
|
|
2
|
-
import { CallbackUrl, appendSearchParams, isFileSource, isUrlSource } from "../lib/helpers";
|
|
3
|
-
import { DeepgramError, isDeepgramError } from "../lib/errors";
|
|
4
|
-
import type {
|
|
5
|
-
AsyncPrerecordedResponse,
|
|
6
|
-
DeepgramResponse,
|
|
7
|
-
Fetch,
|
|
8
|
-
FileSource,
|
|
9
|
-
PrerecordedSchema,
|
|
10
|
-
SyncPrerecordedResponse,
|
|
11
|
-
UrlSource,
|
|
12
|
-
} from "../lib/types";
|
|
13
|
-
|
|
14
|
-
export class PrerecordedClient extends AbstractRestfulClient {
|
|
15
|
-
async transcribeUrl(
|
|
16
|
-
source: UrlSource,
|
|
17
|
-
options?: PrerecordedSchema,
|
|
18
|
-
endpoint = "v1/listen"
|
|
19
|
-
): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
|
|
20
|
-
try {
|
|
21
|
-
let body;
|
|
22
|
-
|
|
23
|
-
if (isUrlSource(source)) {
|
|
24
|
-
body = JSON.stringify(source);
|
|
25
|
-
} else {
|
|
26
|
-
throw new DeepgramError("Unknown transcription source type");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (options !== undefined && "callback" in options) {
|
|
30
|
-
throw new DeepgramError(
|
|
31
|
-
"Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const transcriptionOptions: PrerecordedSchema = { ...{}, ...options };
|
|
36
|
-
|
|
37
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
38
|
-
appendSearchParams(url.searchParams, transcriptionOptions);
|
|
39
|
-
|
|
40
|
-
const result: SyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body);
|
|
41
|
-
|
|
42
|
-
return { result, error: null };
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (isDeepgramError(error)) {
|
|
45
|
-
return { result: null, error };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async transcribeFile(
|
|
53
|
-
source: FileSource,
|
|
54
|
-
options?: PrerecordedSchema,
|
|
55
|
-
endpoint = "v1/listen"
|
|
56
|
-
): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
|
|
57
|
-
try {
|
|
58
|
-
let body;
|
|
59
|
-
|
|
60
|
-
if (isFileSource(source)) {
|
|
61
|
-
body = source;
|
|
62
|
-
} else {
|
|
63
|
-
throw new DeepgramError("Unknown transcription source type");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (options !== undefined && "callback" in options) {
|
|
67
|
-
throw new DeepgramError(
|
|
68
|
-
"Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const transcriptionOptions: PrerecordedSchema = { ...{}, ...options };
|
|
73
|
-
|
|
74
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
75
|
-
appendSearchParams(url.searchParams, transcriptionOptions);
|
|
76
|
-
|
|
77
|
-
const result: SyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body, {
|
|
78
|
-
"Content-Type": "deepgram/audio+video",
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return { result, error: null };
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (isDeepgramError(error)) {
|
|
84
|
-
return { result: null, error };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async transcribeUrlCallback(
|
|
92
|
-
source: UrlSource,
|
|
93
|
-
callback: CallbackUrl,
|
|
94
|
-
options?: PrerecordedSchema,
|
|
95
|
-
endpoint = "v1/listen"
|
|
96
|
-
): Promise<DeepgramResponse<AsyncPrerecordedResponse>> {
|
|
97
|
-
try {
|
|
98
|
-
let body;
|
|
99
|
-
|
|
100
|
-
if (isUrlSource(source)) {
|
|
101
|
-
body = JSON.stringify(source);
|
|
102
|
-
} else {
|
|
103
|
-
throw new DeepgramError("Unknown transcription source type");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const transcriptionOptions: PrerecordedSchema = {
|
|
107
|
-
...options,
|
|
108
|
-
...{ callback: callback.toString() },
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
112
|
-
appendSearchParams(url.searchParams, transcriptionOptions);
|
|
113
|
-
|
|
114
|
-
const result: AsyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body);
|
|
115
|
-
|
|
116
|
-
return { result, error: null };
|
|
117
|
-
} catch (error) {
|
|
118
|
-
if (isDeepgramError(error)) {
|
|
119
|
-
return { result: null, error };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async transcribeFileCallback(
|
|
127
|
-
source: FileSource,
|
|
128
|
-
callback: CallbackUrl,
|
|
129
|
-
options?: PrerecordedSchema,
|
|
130
|
-
endpoint = "v1/listen"
|
|
131
|
-
): Promise<DeepgramResponse<AsyncPrerecordedResponse>> {
|
|
132
|
-
try {
|
|
133
|
-
let body;
|
|
134
|
-
|
|
135
|
-
if (isFileSource(source)) {
|
|
136
|
-
body = source;
|
|
137
|
-
} else {
|
|
138
|
-
throw new DeepgramError("Unknown transcription source type");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const transcriptionOptions: PrerecordedSchema = {
|
|
142
|
-
...options,
|
|
143
|
-
...{ callback: callback.toString() },
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
147
|
-
appendSearchParams(url.searchParams, transcriptionOptions);
|
|
148
|
-
|
|
149
|
-
const result: AsyncPrerecordedResponse = await this.post(this.fetch as Fetch, url, body, {
|
|
150
|
-
"Content-Type": "deepgram/audio+video",
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return { result, error: null };
|
|
154
|
-
} catch (error) {
|
|
155
|
-
if (isDeepgramError(error)) {
|
|
156
|
-
return { result: null, error };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { AbstractRestfulClient } from "./AbstractRestfulClient";
|
|
2
|
-
import { CallbackUrl, appendSearchParams, isTextSource, isUrlSource } from "../lib/helpers";
|
|
3
|
-
import { DeepgramError, isDeepgramError } from "../lib/errors";
|
|
4
|
-
import type {
|
|
5
|
-
AnalyzeSchema,
|
|
6
|
-
AsyncAnalyzeResponse,
|
|
7
|
-
DeepgramResponse,
|
|
8
|
-
Fetch,
|
|
9
|
-
PrerecordedSchema,
|
|
10
|
-
SyncAnalyzeResponse,
|
|
11
|
-
TextSource,
|
|
12
|
-
UrlSource,
|
|
13
|
-
} from "../lib/types";
|
|
14
|
-
|
|
15
|
-
export class ReadClient extends AbstractRestfulClient {
|
|
16
|
-
async analyzeUrl(
|
|
17
|
-
source: UrlSource,
|
|
18
|
-
options?: AnalyzeSchema,
|
|
19
|
-
endpoint = "v1/read"
|
|
20
|
-
): Promise<DeepgramResponse<SyncAnalyzeResponse>> {
|
|
21
|
-
try {
|
|
22
|
-
let body;
|
|
23
|
-
|
|
24
|
-
if (isUrlSource(source)) {
|
|
25
|
-
body = JSON.stringify(source);
|
|
26
|
-
} else {
|
|
27
|
-
throw new DeepgramError("Unknown source type");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (options !== undefined && "callback" in options) {
|
|
31
|
-
throw new DeepgramError(
|
|
32
|
-
"Callback cannot be provided as an option to a synchronous transcription. Use `analyzeUrlCallback` or `analyzeTextCallback` instead."
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const analyzeOptions: AnalyzeSchema = { ...{}, ...options };
|
|
37
|
-
|
|
38
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
39
|
-
appendSearchParams(url.searchParams, analyzeOptions);
|
|
40
|
-
|
|
41
|
-
const result: SyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body);
|
|
42
|
-
|
|
43
|
-
return { result, error: null };
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (isDeepgramError(error)) {
|
|
46
|
-
return { result: null, error };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async analyzeText(
|
|
54
|
-
source: TextSource,
|
|
55
|
-
options?: AnalyzeSchema,
|
|
56
|
-
endpoint = "v1/read"
|
|
57
|
-
): Promise<DeepgramResponse<SyncAnalyzeResponse>> {
|
|
58
|
-
try {
|
|
59
|
-
let body;
|
|
60
|
-
|
|
61
|
-
if (isTextSource(source)) {
|
|
62
|
-
body = JSON.stringify(source);
|
|
63
|
-
} else {
|
|
64
|
-
throw new DeepgramError("Unknown source type");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (options !== undefined && "callback" in options) {
|
|
68
|
-
throw new DeepgramError(
|
|
69
|
-
"Callback cannot be provided as an option to a synchronous requests. Use `analyzeUrlCallback` or `analyzeTextCallback` instead."
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const analyzeOptions: AnalyzeSchema = { ...{}, ...options };
|
|
74
|
-
|
|
75
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
76
|
-
appendSearchParams(url.searchParams, analyzeOptions);
|
|
77
|
-
|
|
78
|
-
const result: SyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body);
|
|
79
|
-
|
|
80
|
-
return { result, error: null };
|
|
81
|
-
} catch (error) {
|
|
82
|
-
if (isDeepgramError(error)) {
|
|
83
|
-
return { result: null, error };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async analyzeUrlCallback(
|
|
91
|
-
source: UrlSource,
|
|
92
|
-
callback: CallbackUrl,
|
|
93
|
-
options?: AnalyzeSchema,
|
|
94
|
-
endpoint = "v1/read"
|
|
95
|
-
): Promise<DeepgramResponse<AsyncAnalyzeResponse>> {
|
|
96
|
-
try {
|
|
97
|
-
let body;
|
|
98
|
-
|
|
99
|
-
if (isUrlSource(source)) {
|
|
100
|
-
body = JSON.stringify(source);
|
|
101
|
-
} else {
|
|
102
|
-
throw new DeepgramError("Unknown source type");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const transcriptionOptions: PrerecordedSchema = {
|
|
106
|
-
...options,
|
|
107
|
-
...{ callback: callback.toString() },
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
111
|
-
appendSearchParams(url.searchParams, transcriptionOptions);
|
|
112
|
-
|
|
113
|
-
const result: AsyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body);
|
|
114
|
-
|
|
115
|
-
return { result, error: null };
|
|
116
|
-
} catch (error) {
|
|
117
|
-
if (isDeepgramError(error)) {
|
|
118
|
-
return { result: null, error };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async analyzeTextCallback(
|
|
126
|
-
source: TextSource,
|
|
127
|
-
callback: CallbackUrl,
|
|
128
|
-
options?: AnalyzeSchema,
|
|
129
|
-
endpoint = "v1/read"
|
|
130
|
-
): Promise<DeepgramResponse<AsyncAnalyzeResponse>> {
|
|
131
|
-
try {
|
|
132
|
-
let body;
|
|
133
|
-
|
|
134
|
-
if (isTextSource(source)) {
|
|
135
|
-
body = JSON.stringify(source);
|
|
136
|
-
} else {
|
|
137
|
-
throw new DeepgramError("Unknown source type");
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const transcriptionOptions: PrerecordedSchema = {
|
|
141
|
-
...options,
|
|
142
|
-
...{ callback: callback.toString() },
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
146
|
-
appendSearchParams(url.searchParams, transcriptionOptions);
|
|
147
|
-
|
|
148
|
-
const result: AsyncAnalyzeResponse = await this.post(this.fetch as Fetch, url, body, {
|
|
149
|
-
"Content-Type": "deepgram/audio+video",
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
return { result, error: null };
|
|
153
|
-
} catch (error) {
|
|
154
|
-
if (isDeepgramError(error)) {
|
|
155
|
-
return { result: null, error };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { AbstractRestfulClient } from "./AbstractRestfulClient";
|
|
2
|
-
import { DeepgramError, DeepgramUnknownError, isDeepgramError } from "../lib/errors";
|
|
3
|
-
import { appendSearchParams, isTextSource } from "../lib/helpers";
|
|
4
|
-
import { Fetch, SpeakSchema, TextSource } from "../lib/types";
|
|
5
|
-
|
|
6
|
-
export class SpeakClient extends AbstractRestfulClient {
|
|
7
|
-
public result: undefined | Response;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @see https://developers.deepgram.com/reference/text-to-speech-api
|
|
11
|
-
*/
|
|
12
|
-
async request(
|
|
13
|
-
source: TextSource,
|
|
14
|
-
options?: SpeakSchema,
|
|
15
|
-
endpoint = "v1/speak"
|
|
16
|
-
): Promise<SpeakClient> {
|
|
17
|
-
try {
|
|
18
|
-
let body;
|
|
19
|
-
|
|
20
|
-
if (isTextSource(source)) {
|
|
21
|
-
body = JSON.stringify(source);
|
|
22
|
-
} else {
|
|
23
|
-
throw new DeepgramError("Unknown transcription source type");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const speakOptions: SpeakSchema = { ...{ model: "aura-asteria-en" }, ...options };
|
|
27
|
-
|
|
28
|
-
const url = new URL(endpoint, this.baseUrl);
|
|
29
|
-
appendSearchParams(url.searchParams, speakOptions);
|
|
30
|
-
this.result = await this._handleRawRequest(this.fetch as Fetch, "POST", url, {}, {}, body);
|
|
31
|
-
return this;
|
|
32
|
-
} catch (error) {
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async getStream(): Promise<ReadableStream<Uint8Array> | null> {
|
|
38
|
-
if (!this.result)
|
|
39
|
-
throw new DeepgramUnknownError("Tried to get stream before making request", "");
|
|
40
|
-
|
|
41
|
-
return this.result.body;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getHeaders(): Promise<Headers> {
|
|
45
|
-
if (!this.result)
|
|
46
|
-
throw new DeepgramUnknownError("Tried to get headers before making request", "");
|
|
47
|
-
|
|
48
|
-
return this.result.headers;
|
|
49
|
-
}
|
|
50
|
-
}
|