@ai-sdk/deepgram 3.1.21 → 3.1.23
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/CHANGELOG.md +17 -0
- package/dist/index.d.ts +128 -120
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +622 -707
- package/dist/index.js.map +1 -1
- package/docs/110-deepgram.mdx +1 -1
- package/package.json +8 -8
- package/src/deepgram-provider.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,718 +1,633 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
NoSuchModelError
|
|
4
|
-
} from "@ai-sdk/provider";
|
|
5
|
-
import {
|
|
6
|
-
loadApiKey,
|
|
7
|
-
withUserAgentSuffix
|
|
8
|
-
} from "@ai-sdk/provider-utils";
|
|
9
|
-
|
|
10
|
-
// src/deepgram-transcription-model.ts
|
|
11
|
-
import {
|
|
12
|
-
combineHeaders,
|
|
13
|
-
createJsonResponseHandler,
|
|
14
|
-
parseProviderOptions,
|
|
15
|
-
postToApi,
|
|
16
|
-
serializeModelOptions,
|
|
17
|
-
WORKFLOW_SERIALIZE,
|
|
18
|
-
WORKFLOW_DESERIALIZE
|
|
19
|
-
} from "@ai-sdk/provider-utils";
|
|
20
|
-
import { z as z3 } from "zod/v4";
|
|
21
|
-
|
|
22
|
-
// src/deepgram-error.ts
|
|
1
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, createBinaryResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, loadApiKey, parseProviderOptions, postJsonToApi, postToApi, serializeModelOptions, withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
23
3
|
import { z } from "zod/v4";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
//#region src/deepgram-error.ts
|
|
5
|
+
const deepgramErrorDataSchema = z.object({
|
|
6
|
+
err_code: z.string(),
|
|
7
|
+
err_msg: z.string(),
|
|
8
|
+
request_id: z.string().optional()
|
|
29
9
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
const deepgramFailedResponseHandler = createJsonErrorResponseHandler({
|
|
11
|
+
errorSchema: deepgramErrorDataSchema,
|
|
12
|
+
errorToMessage: (data) => data.err_msg
|
|
33
13
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
fillerWords: z2.boolean().nullish()
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/deepgram-transcription-model-options.ts
|
|
16
|
+
const deepgramTranscriptionModelOptionsSchema = z.object({
|
|
17
|
+
/** Language to use for transcription. If not specified, Deepgram defaults to English. Use `detectLanguage: true` to enable automatic language detection. */
|
|
18
|
+
language: z.string().nullish(),
|
|
19
|
+
/** Whether to enable automatic language detection. When true, Deepgram will detect the language of the audio. */
|
|
20
|
+
detectLanguage: z.boolean().nullish(),
|
|
21
|
+
/** Whether to use smart formatting, which formats written-out numbers, dates, times, etc. */
|
|
22
|
+
smartFormat: z.boolean().nullish(),
|
|
23
|
+
/** Whether to add punctuation to the transcript. */
|
|
24
|
+
punctuate: z.boolean().nullish(),
|
|
25
|
+
/** Whether to format the transcript into paragraphs. */
|
|
26
|
+
paragraphs: z.boolean().nullish(),
|
|
27
|
+
/** Whether to generate a summary of the transcript. Use 'v2' for the latest version or false to disable. */
|
|
28
|
+
summarize: z.union([z.literal("v2"), z.literal(false)]).nullish(),
|
|
29
|
+
/** Whether to identify topics in the transcript. */
|
|
30
|
+
topics: z.boolean().nullish(),
|
|
31
|
+
/** Whether to identify intents in the transcript. */
|
|
32
|
+
intents: z.boolean().nullish(),
|
|
33
|
+
/** Whether to analyze sentiment in the transcript. */
|
|
34
|
+
sentiment: z.boolean().nullish(),
|
|
35
|
+
/** Whether to detect and tag named entities in the transcript. */
|
|
36
|
+
detectEntities: z.boolean().nullish(),
|
|
37
|
+
/** Specify terms or patterns to redact from the transcript. Can be a string or array of strings. */
|
|
38
|
+
redact: z.union([z.string(), z.array(z.string())]).nullish(),
|
|
39
|
+
/** String to replace redacted content with. */
|
|
40
|
+
replace: z.string().nullish(),
|
|
41
|
+
/** Term or phrase to search for in the transcript. */
|
|
42
|
+
search: z.string().nullish(),
|
|
43
|
+
/** Key term to identify in the transcript. */
|
|
44
|
+
keyterm: z.string().nullish(),
|
|
45
|
+
/** Whether to identify different speakers in the audio. */
|
|
46
|
+
diarize: z.boolean().nullish(),
|
|
47
|
+
/** Whether to segment the transcript into utterances. */
|
|
48
|
+
utterances: z.boolean().nullish(),
|
|
49
|
+
/** Minimum duration of silence (in seconds) to trigger a new utterance. */
|
|
50
|
+
uttSplit: z.number().nullish(),
|
|
51
|
+
/** Whether to include filler words (um, uh, etc.) in the transcript. */
|
|
52
|
+
fillerWords: z.boolean().nullish()
|
|
74
53
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var DeepgramTranscriptionModel = class
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
startSecond: word.start,
|
|
170
|
-
endSecond: word.end
|
|
171
|
-
})) ?? [],
|
|
172
|
-
language: response.results?.channels.at(0)?.detected_language ?? void 0,
|
|
173
|
-
durationInSeconds: response.metadata?.duration ?? void 0,
|
|
174
|
-
warnings,
|
|
175
|
-
response: {
|
|
176
|
-
timestamp: currentDate,
|
|
177
|
-
modelId: this.modelId,
|
|
178
|
-
headers: responseHeaders,
|
|
179
|
-
body: rawResponse
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/deepgram-transcription-model.ts
|
|
56
|
+
var DeepgramTranscriptionModel = class DeepgramTranscriptionModel {
|
|
57
|
+
get provider() {
|
|
58
|
+
return this.config.provider;
|
|
59
|
+
}
|
|
60
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
61
|
+
return serializeModelOptions({
|
|
62
|
+
modelId: model.modelId,
|
|
63
|
+
config: model.config
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
67
|
+
return new DeepgramTranscriptionModel(options.modelId, options.config);
|
|
68
|
+
}
|
|
69
|
+
constructor(modelId, config) {
|
|
70
|
+
this.modelId = modelId;
|
|
71
|
+
this.config = config;
|
|
72
|
+
this.specificationVersion = "v4";
|
|
73
|
+
}
|
|
74
|
+
async getArgs({ providerOptions }) {
|
|
75
|
+
const warnings = [];
|
|
76
|
+
const deepgramOptions = await parseProviderOptions({
|
|
77
|
+
provider: "deepgram",
|
|
78
|
+
providerOptions,
|
|
79
|
+
schema: deepgramTranscriptionModelOptionsSchema
|
|
80
|
+
});
|
|
81
|
+
const body = { model: this.modelId };
|
|
82
|
+
if (deepgramOptions) {
|
|
83
|
+
body.detect_entities = deepgramOptions.detectEntities ?? void 0;
|
|
84
|
+
body.detect_language = deepgramOptions.detectLanguage ?? void 0;
|
|
85
|
+
body.diarize = deepgramOptions.diarize ?? void 0;
|
|
86
|
+
body.filler_words = deepgramOptions.fillerWords ?? void 0;
|
|
87
|
+
body.intents = deepgramOptions.intents ?? void 0;
|
|
88
|
+
body.keyterm = deepgramOptions.keyterm ?? void 0;
|
|
89
|
+
body.language = deepgramOptions.language ?? void 0;
|
|
90
|
+
body.paragraphs = deepgramOptions.paragraphs ?? void 0;
|
|
91
|
+
body.punctuate = deepgramOptions.punctuate ?? void 0;
|
|
92
|
+
body.redact = deepgramOptions.redact ?? void 0;
|
|
93
|
+
body.replace = deepgramOptions.replace ?? void 0;
|
|
94
|
+
body.search = deepgramOptions.search ?? void 0;
|
|
95
|
+
body.sentiment = deepgramOptions.sentiment ?? void 0;
|
|
96
|
+
body.smart_format = deepgramOptions.smartFormat ?? void 0;
|
|
97
|
+
body.summarize = deepgramOptions.summarize ?? void 0;
|
|
98
|
+
body.topics = deepgramOptions.topics ?? void 0;
|
|
99
|
+
body.utterances = deepgramOptions.utterances ?? void 0;
|
|
100
|
+
body.utt_split = deepgramOptions.uttSplit ?? void 0;
|
|
101
|
+
}
|
|
102
|
+
const queryParams = new URLSearchParams();
|
|
103
|
+
for (const [key, value] of Object.entries(body)) if (value !== void 0) queryParams.append(key, String(value));
|
|
104
|
+
return {
|
|
105
|
+
queryParams,
|
|
106
|
+
warnings
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async doGenerate(options) {
|
|
110
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
111
|
+
const { queryParams, warnings } = await this.getArgs(options);
|
|
112
|
+
const { value: response, responseHeaders, rawValue: rawResponse } = await postToApi({
|
|
113
|
+
url: this.config.url({
|
|
114
|
+
path: "/v1/listen",
|
|
115
|
+
modelId: this.modelId
|
|
116
|
+
}) + "?" + queryParams.toString(),
|
|
117
|
+
headers: {
|
|
118
|
+
...combineHeaders(this.config.headers?.(), options.headers),
|
|
119
|
+
"Content-Type": options.mediaType
|
|
120
|
+
},
|
|
121
|
+
body: {
|
|
122
|
+
content: options.audio,
|
|
123
|
+
values: options.audio
|
|
124
|
+
},
|
|
125
|
+
failedResponseHandler: deepgramFailedResponseHandler,
|
|
126
|
+
successfulResponseHandler: createJsonResponseHandler(deepgramTranscriptionResponseSchema),
|
|
127
|
+
abortSignal: options.abortSignal,
|
|
128
|
+
fetch: this.config.fetch
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
text: response.results?.channels.at(0)?.alternatives.at(0)?.transcript ?? "",
|
|
132
|
+
segments: response.results?.channels[0].alternatives[0].words?.map((word) => ({
|
|
133
|
+
text: word.word,
|
|
134
|
+
startSecond: word.start,
|
|
135
|
+
endSecond: word.end
|
|
136
|
+
})) ?? [],
|
|
137
|
+
language: response.results?.channels.at(0)?.detected_language ?? void 0,
|
|
138
|
+
durationInSeconds: response.metadata?.duration ?? void 0,
|
|
139
|
+
warnings,
|
|
140
|
+
response: {
|
|
141
|
+
timestamp: currentDate,
|
|
142
|
+
modelId: this.modelId,
|
|
143
|
+
headers: responseHeaders,
|
|
144
|
+
body: rawResponse
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
183
148
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
word: z3.string(),
|
|
198
|
-
start: z3.number(),
|
|
199
|
-
end: z3.number()
|
|
200
|
-
})
|
|
201
|
-
)
|
|
202
|
-
})
|
|
203
|
-
)
|
|
204
|
-
})
|
|
205
|
-
)
|
|
206
|
-
}).nullish()
|
|
149
|
+
const deepgramTranscriptionResponseSchema = z.object({
|
|
150
|
+
metadata: z.object({ duration: z.number() }).nullish(),
|
|
151
|
+
results: z.object({ channels: z.array(z.object({
|
|
152
|
+
detected_language: z.string().nullish(),
|
|
153
|
+
alternatives: z.array(z.object({
|
|
154
|
+
transcript: z.string(),
|
|
155
|
+
words: z.array(z.object({
|
|
156
|
+
word: z.string(),
|
|
157
|
+
start: z.number(),
|
|
158
|
+
end: z.number()
|
|
159
|
+
}))
|
|
160
|
+
}))
|
|
161
|
+
})) }).nullish()
|
|
207
162
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/** Encoding type for the audio output (linear16, mulaw, alaw, etc.). */
|
|
228
|
-
encoding: z4.string().nullish(),
|
|
229
|
-
/** Sample rate for the output audio in Hz (8000, 16000, 24000, 44100, 48000). */
|
|
230
|
-
sampleRate: z4.number().nullish(),
|
|
231
|
-
/** URL to which we'll make the callback request. */
|
|
232
|
-
callback: z4.string().url().nullish(),
|
|
233
|
-
/** HTTP method by which the callback request will be made (POST or PUT). */
|
|
234
|
-
callbackMethod: z4.enum(["POST", "PUT"]).nullish(),
|
|
235
|
-
/** Opts out requests from the Deepgram Model Improvement Program. */
|
|
236
|
-
mipOptOut: z4.boolean().nullish(),
|
|
237
|
-
/** Label your requests for the purpose of identification during usage reporting. */
|
|
238
|
-
tag: z4.union([z4.string(), z4.array(z4.string())]).nullish()
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/deepgram-speech-model-options.ts
|
|
165
|
+
const deepgramSpeechModelOptionsSchema = z.object({
|
|
166
|
+
/** Bitrate of the audio in bits per second. Can be a number or predefined enum value. */
|
|
167
|
+
bitRate: z.union([z.number(), z.string()]).nullish(),
|
|
168
|
+
/** Container format for the output audio (mp3, wav, etc.). */
|
|
169
|
+
container: z.string().nullish(),
|
|
170
|
+
/** Encoding type for the audio output (linear16, mulaw, alaw, etc.). */
|
|
171
|
+
encoding: z.string().nullish(),
|
|
172
|
+
/** Sample rate for the output audio in Hz (8000, 16000, 24000, 44100, 48000). */
|
|
173
|
+
sampleRate: z.number().nullish(),
|
|
174
|
+
/** URL to which we'll make the callback request. */
|
|
175
|
+
callback: z.string().url().nullish(),
|
|
176
|
+
/** HTTP method by which the callback request will be made (POST or PUT). */
|
|
177
|
+
callbackMethod: z.enum(["POST", "PUT"]).nullish(),
|
|
178
|
+
/** Opts out requests from the Deepgram Model Improvement Program. */
|
|
179
|
+
mipOptOut: z.boolean().nullish(),
|
|
180
|
+
/** Label your requests for the purpose of identification during usage reporting. */
|
|
181
|
+
tag: z.union([z.string(), z.array(z.string())]).nullish()
|
|
239
182
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var DeepgramSpeechModel = class
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
warnings,
|
|
622
|
-
request: {
|
|
623
|
-
body: JSON.stringify(requestBody)
|
|
624
|
-
},
|
|
625
|
-
response: {
|
|
626
|
-
timestamp: currentDate,
|
|
627
|
-
modelId: this.modelId,
|
|
628
|
-
headers: responseHeaders,
|
|
629
|
-
body: rawResponse
|
|
630
|
-
},
|
|
631
|
-
providerMetadata: {
|
|
632
|
-
deepgram: {
|
|
633
|
-
...responseHeaders?.["dg-model-name"] ? { modelName: responseHeaders["dg-model-name"] } : {},
|
|
634
|
-
...responseHeaders?.["dg-model-uuid"] ? { modelUuid: responseHeaders["dg-model-uuid"] } : {},
|
|
635
|
-
...additionalModelUuids ? { additionalModelUuids } : {},
|
|
636
|
-
...charCount != null ? { charCount } : {},
|
|
637
|
-
...breaksApplied != null ? { breaksApplied } : {},
|
|
638
|
-
...pronunciationsApplied != null ? { pronunciationsApplied } : {},
|
|
639
|
-
...responseHeaders?.["dg-pronunciation-warnings"] ? {
|
|
640
|
-
pronunciationWarnings: responseHeaders["dg-pronunciation-warnings"]
|
|
641
|
-
} : {},
|
|
642
|
-
...responseHeaders?.["dg-request-id"] ? { requestId: responseHeaders["dg-request-id"] } : {}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/deepgram-speech-model.ts
|
|
185
|
+
const VOICE_FAMILY_IDS = /* @__PURE__ */ new Set(["aura", "aura-2"]);
|
|
186
|
+
var DeepgramSpeechModel = class DeepgramSpeechModel {
|
|
187
|
+
get provider() {
|
|
188
|
+
return this.config.provider;
|
|
189
|
+
}
|
|
190
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
191
|
+
return serializeModelOptions({
|
|
192
|
+
modelId: model.modelId,
|
|
193
|
+
config: model.config
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
197
|
+
return new DeepgramSpeechModel(options.modelId, options.config);
|
|
198
|
+
}
|
|
199
|
+
constructor(modelId, config) {
|
|
200
|
+
this.modelId = modelId;
|
|
201
|
+
this.config = config;
|
|
202
|
+
this.specificationVersion = "v4";
|
|
203
|
+
}
|
|
204
|
+
async getArgs({ text, voice, outputFormat = "mp3", speed, language, instructions, providerOptions }) {
|
|
205
|
+
const warnings = [];
|
|
206
|
+
const deepgramOptions = await parseProviderOptions({
|
|
207
|
+
provider: "deepgram",
|
|
208
|
+
providerOptions,
|
|
209
|
+
schema: deepgramSpeechModelOptionsSchema
|
|
210
|
+
});
|
|
211
|
+
let upstreamModelId = this.modelId;
|
|
212
|
+
if (VOICE_FAMILY_IDS.has(this.modelId)) {
|
|
213
|
+
const trimmedVoice = voice?.trim();
|
|
214
|
+
if (!trimmedVoice) throw new Error(`Deepgram speech model "${this.modelId}" requires a \`voice\` to be set (e.g. voice: 'thalia').`);
|
|
215
|
+
if (language === "auto") warnings.push({
|
|
216
|
+
type: "compatibility",
|
|
217
|
+
feature: "language",
|
|
218
|
+
details: `Deepgram TTS models do not support automatic language detection. Language "en" was used instead.`
|
|
219
|
+
});
|
|
220
|
+
upstreamModelId = `${this.modelId}-${trimmedVoice}-${language && language !== "auto" ? language : "en"}`;
|
|
221
|
+
}
|
|
222
|
+
const requestBody = { text };
|
|
223
|
+
const queryParams = { model: upstreamModelId };
|
|
224
|
+
if (outputFormat) {
|
|
225
|
+
const formatLower = outputFormat.toLowerCase();
|
|
226
|
+
const mappedFormat = {
|
|
227
|
+
mp3: { encoding: "mp3" },
|
|
228
|
+
wav: {
|
|
229
|
+
container: "wav",
|
|
230
|
+
encoding: "linear16"
|
|
231
|
+
},
|
|
232
|
+
linear16: {
|
|
233
|
+
encoding: "linear16",
|
|
234
|
+
container: "wav"
|
|
235
|
+
},
|
|
236
|
+
mulaw: {
|
|
237
|
+
encoding: "mulaw",
|
|
238
|
+
container: "wav"
|
|
239
|
+
},
|
|
240
|
+
alaw: {
|
|
241
|
+
encoding: "alaw",
|
|
242
|
+
container: "wav"
|
|
243
|
+
},
|
|
244
|
+
opus: {
|
|
245
|
+
encoding: "opus",
|
|
246
|
+
container: "ogg"
|
|
247
|
+
},
|
|
248
|
+
ogg: {
|
|
249
|
+
encoding: "opus",
|
|
250
|
+
container: "ogg"
|
|
251
|
+
},
|
|
252
|
+
flac: { encoding: "flac" },
|
|
253
|
+
aac: { encoding: "aac" },
|
|
254
|
+
pcm: {
|
|
255
|
+
encoding: "linear16",
|
|
256
|
+
container: "none"
|
|
257
|
+
}
|
|
258
|
+
}[formatLower];
|
|
259
|
+
if (mappedFormat) {
|
|
260
|
+
if (mappedFormat.encoding) queryParams.encoding = mappedFormat.encoding;
|
|
261
|
+
if (mappedFormat.container) queryParams.container = mappedFormat.container;
|
|
262
|
+
if (mappedFormat.sampleRate) queryParams.sample_rate = String(mappedFormat.sampleRate);
|
|
263
|
+
if (mappedFormat.bitRate) queryParams.bit_rate = String(mappedFormat.bitRate);
|
|
264
|
+
} else {
|
|
265
|
+
const parts = formatLower.split("_");
|
|
266
|
+
if (parts.length >= 2) {
|
|
267
|
+
const firstPart = parts[0];
|
|
268
|
+
const secondPart = parts[1];
|
|
269
|
+
const sampleRate = parseInt(secondPart, 10);
|
|
270
|
+
if ([
|
|
271
|
+
"linear16",
|
|
272
|
+
"mulaw",
|
|
273
|
+
"alaw",
|
|
274
|
+
"mp3",
|
|
275
|
+
"opus",
|
|
276
|
+
"flac",
|
|
277
|
+
"aac"
|
|
278
|
+
].includes(firstPart)) {
|
|
279
|
+
queryParams.encoding = firstPart;
|
|
280
|
+
if ([
|
|
281
|
+
"linear16",
|
|
282
|
+
"mulaw",
|
|
283
|
+
"alaw"
|
|
284
|
+
].includes(firstPart)) queryParams.container = "wav";
|
|
285
|
+
else if (firstPart === "opus") queryParams.container = "ogg";
|
|
286
|
+
if (!isNaN(sampleRate)) {
|
|
287
|
+
if (firstPart === "linear16" && [
|
|
288
|
+
8e3,
|
|
289
|
+
16e3,
|
|
290
|
+
24e3,
|
|
291
|
+
32e3,
|
|
292
|
+
48e3
|
|
293
|
+
].includes(sampleRate)) queryParams.sample_rate = String(sampleRate);
|
|
294
|
+
else if (firstPart === "mulaw" && [8e3, 16e3].includes(sampleRate)) queryParams.sample_rate = String(sampleRate);
|
|
295
|
+
else if (firstPart === "alaw" && [8e3, 16e3].includes(sampleRate)) queryParams.sample_rate = String(sampleRate);
|
|
296
|
+
else if (firstPart === "flac" && [
|
|
297
|
+
8e3,
|
|
298
|
+
16e3,
|
|
299
|
+
22050,
|
|
300
|
+
32e3,
|
|
301
|
+
48e3
|
|
302
|
+
].includes(sampleRate)) queryParams.sample_rate = String(sampleRate);
|
|
303
|
+
}
|
|
304
|
+
} else if (["wav", "ogg"].includes(firstPart)) {
|
|
305
|
+
if (firstPart === "wav") {
|
|
306
|
+
queryParams.container = "wav";
|
|
307
|
+
queryParams.encoding = "linear16";
|
|
308
|
+
} else if (firstPart === "ogg") {
|
|
309
|
+
queryParams.container = "ogg";
|
|
310
|
+
queryParams.encoding = "opus";
|
|
311
|
+
}
|
|
312
|
+
if (!isNaN(sampleRate)) queryParams.sample_rate = String(sampleRate);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (deepgramOptions) {
|
|
318
|
+
if (deepgramOptions.encoding) {
|
|
319
|
+
const newEncoding = deepgramOptions.encoding.toLowerCase();
|
|
320
|
+
queryParams.encoding = newEncoding;
|
|
321
|
+
if (deepgramOptions.container) {
|
|
322
|
+
if ([
|
|
323
|
+
"linear16",
|
|
324
|
+
"mulaw",
|
|
325
|
+
"alaw"
|
|
326
|
+
].includes(newEncoding)) {
|
|
327
|
+
if (!["wav", "none"].includes(deepgramOptions.container.toLowerCase())) warnings.push({
|
|
328
|
+
type: "unsupported",
|
|
329
|
+
feature: "providerOptions",
|
|
330
|
+
details: `Encoding "${newEncoding}" only supports containers "wav" or "none". Container "${deepgramOptions.container}" was ignored.`
|
|
331
|
+
});
|
|
332
|
+
else queryParams.container = deepgramOptions.container.toLowerCase();
|
|
333
|
+
} else if (newEncoding === "opus") queryParams.container = "ogg";
|
|
334
|
+
else if ([
|
|
335
|
+
"mp3",
|
|
336
|
+
"flac",
|
|
337
|
+
"aac"
|
|
338
|
+
].includes(newEncoding)) {
|
|
339
|
+
warnings.push({
|
|
340
|
+
type: "unsupported",
|
|
341
|
+
feature: "providerOptions",
|
|
342
|
+
details: `Encoding "${newEncoding}" does not support container parameter. Container "${deepgramOptions.container}" was ignored.`
|
|
343
|
+
});
|
|
344
|
+
delete queryParams.container;
|
|
345
|
+
}
|
|
346
|
+
} else if ([
|
|
347
|
+
"mp3",
|
|
348
|
+
"flac",
|
|
349
|
+
"aac"
|
|
350
|
+
].includes(newEncoding)) delete queryParams.container;
|
|
351
|
+
else if ([
|
|
352
|
+
"linear16",
|
|
353
|
+
"mulaw",
|
|
354
|
+
"alaw"
|
|
355
|
+
].includes(newEncoding)) {
|
|
356
|
+
if (!queryParams.container) queryParams.container = "wav";
|
|
357
|
+
} else if (newEncoding === "opus") queryParams.container = "ogg";
|
|
358
|
+
if ([
|
|
359
|
+
"mp3",
|
|
360
|
+
"opus",
|
|
361
|
+
"aac"
|
|
362
|
+
].includes(newEncoding)) delete queryParams.sample_rate;
|
|
363
|
+
if ([
|
|
364
|
+
"linear16",
|
|
365
|
+
"mulaw",
|
|
366
|
+
"alaw",
|
|
367
|
+
"flac"
|
|
368
|
+
].includes(newEncoding)) delete queryParams.bit_rate;
|
|
369
|
+
} else if (deepgramOptions.container) {
|
|
370
|
+
const container = deepgramOptions.container.toLowerCase();
|
|
371
|
+
const oldEncoding = queryParams.encoding?.toLowerCase();
|
|
372
|
+
let newEncoding;
|
|
373
|
+
if (container === "wav") {
|
|
374
|
+
queryParams.container = "wav";
|
|
375
|
+
newEncoding = "linear16";
|
|
376
|
+
} else if (container === "ogg") {
|
|
377
|
+
queryParams.container = "ogg";
|
|
378
|
+
newEncoding = "opus";
|
|
379
|
+
} else if (container === "none") {
|
|
380
|
+
queryParams.container = "none";
|
|
381
|
+
newEncoding = "linear16";
|
|
382
|
+
}
|
|
383
|
+
if (newEncoding && newEncoding !== oldEncoding) {
|
|
384
|
+
queryParams.encoding = newEncoding;
|
|
385
|
+
if ([
|
|
386
|
+
"mp3",
|
|
387
|
+
"opus",
|
|
388
|
+
"aac"
|
|
389
|
+
].includes(newEncoding)) delete queryParams.sample_rate;
|
|
390
|
+
if ([
|
|
391
|
+
"linear16",
|
|
392
|
+
"mulaw",
|
|
393
|
+
"alaw",
|
|
394
|
+
"flac"
|
|
395
|
+
].includes(newEncoding)) delete queryParams.bit_rate;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (deepgramOptions.sampleRate != null) {
|
|
399
|
+
const encoding = queryParams.encoding?.toLowerCase() || "";
|
|
400
|
+
const sampleRate = deepgramOptions.sampleRate;
|
|
401
|
+
if (encoding === "linear16") {
|
|
402
|
+
if (![
|
|
403
|
+
8e3,
|
|
404
|
+
16e3,
|
|
405
|
+
24e3,
|
|
406
|
+
32e3,
|
|
407
|
+
48e3
|
|
408
|
+
].includes(sampleRate)) warnings.push({
|
|
409
|
+
type: "unsupported",
|
|
410
|
+
feature: "providerOptions",
|
|
411
|
+
details: `Encoding "linear16" only supports sample rates: 8000, 16000, 24000, 32000, 48000. Sample rate ${sampleRate} was ignored.`
|
|
412
|
+
});
|
|
413
|
+
else queryParams.sample_rate = String(sampleRate);
|
|
414
|
+
} else if (encoding === "mulaw" || encoding === "alaw") {
|
|
415
|
+
if (![8e3, 16e3].includes(sampleRate)) warnings.push({
|
|
416
|
+
type: "unsupported",
|
|
417
|
+
feature: "providerOptions",
|
|
418
|
+
details: `Encoding "${encoding}" only supports sample rates: 8000, 16000. Sample rate ${sampleRate} was ignored.`
|
|
419
|
+
});
|
|
420
|
+
else queryParams.sample_rate = String(sampleRate);
|
|
421
|
+
} else if (encoding === "flac") {
|
|
422
|
+
if (![
|
|
423
|
+
8e3,
|
|
424
|
+
16e3,
|
|
425
|
+
22050,
|
|
426
|
+
32e3,
|
|
427
|
+
48e3
|
|
428
|
+
].includes(sampleRate)) warnings.push({
|
|
429
|
+
type: "unsupported",
|
|
430
|
+
feature: "providerOptions",
|
|
431
|
+
details: `Encoding "flac" only supports sample rates: 8000, 16000, 22050, 32000, 48000. Sample rate ${sampleRate} was ignored.`
|
|
432
|
+
});
|
|
433
|
+
else queryParams.sample_rate = String(sampleRate);
|
|
434
|
+
} else if ([
|
|
435
|
+
"mp3",
|
|
436
|
+
"opus",
|
|
437
|
+
"aac"
|
|
438
|
+
].includes(encoding)) warnings.push({
|
|
439
|
+
type: "unsupported",
|
|
440
|
+
feature: "providerOptions",
|
|
441
|
+
details: `Encoding "${encoding}" has a fixed sample rate and does not support sample_rate parameter. Sample rate ${sampleRate} was ignored.`
|
|
442
|
+
});
|
|
443
|
+
else queryParams.sample_rate = String(sampleRate);
|
|
444
|
+
}
|
|
445
|
+
if (deepgramOptions.bitRate != null) {
|
|
446
|
+
const encoding = queryParams.encoding?.toLowerCase() || "";
|
|
447
|
+
const bitRate = deepgramOptions.bitRate;
|
|
448
|
+
if (encoding === "mp3") {
|
|
449
|
+
if (![32e3, 48e3].includes(Number(bitRate))) warnings.push({
|
|
450
|
+
type: "unsupported",
|
|
451
|
+
feature: "providerOptions",
|
|
452
|
+
details: `Encoding "mp3" only supports bit rates: 32000, 48000. Bit rate ${bitRate} was ignored.`
|
|
453
|
+
});
|
|
454
|
+
else queryParams.bit_rate = String(bitRate);
|
|
455
|
+
} else if (encoding === "opus") {
|
|
456
|
+
const bitRateNum = Number(bitRate);
|
|
457
|
+
if (bitRateNum < 4e3 || bitRateNum > 65e4) warnings.push({
|
|
458
|
+
type: "unsupported",
|
|
459
|
+
feature: "providerOptions",
|
|
460
|
+
details: `Encoding "opus" supports bit rates between 4000 and 650000. Bit rate ${bitRate} was ignored.`
|
|
461
|
+
});
|
|
462
|
+
else queryParams.bit_rate = String(bitRate);
|
|
463
|
+
} else if (encoding === "aac") {
|
|
464
|
+
const bitRateNum = Number(bitRate);
|
|
465
|
+
if (bitRateNum < 4e3 || bitRateNum > 192e3) warnings.push({
|
|
466
|
+
type: "unsupported",
|
|
467
|
+
feature: "providerOptions",
|
|
468
|
+
details: `Encoding "aac" supports bit rates between 4000 and 192000. Bit rate ${bitRate} was ignored.`
|
|
469
|
+
});
|
|
470
|
+
else queryParams.bit_rate = String(bitRate);
|
|
471
|
+
} else if ([
|
|
472
|
+
"linear16",
|
|
473
|
+
"mulaw",
|
|
474
|
+
"alaw",
|
|
475
|
+
"flac"
|
|
476
|
+
].includes(encoding)) warnings.push({
|
|
477
|
+
type: "unsupported",
|
|
478
|
+
feature: "providerOptions",
|
|
479
|
+
details: `Encoding "${encoding}" does not support bit_rate parameter. Bit rate ${bitRate} was ignored.`
|
|
480
|
+
});
|
|
481
|
+
else queryParams.bit_rate = String(bitRate);
|
|
482
|
+
}
|
|
483
|
+
if (deepgramOptions.callback) queryParams.callback = deepgramOptions.callback;
|
|
484
|
+
if (deepgramOptions.callbackMethod) queryParams.callback_method = deepgramOptions.callbackMethod;
|
|
485
|
+
if (deepgramOptions.mipOptOut != null) queryParams.mip_opt_out = String(deepgramOptions.mipOptOut);
|
|
486
|
+
if (deepgramOptions.tag) {
|
|
487
|
+
if (Array.isArray(deepgramOptions.tag)) queryParams.tag = deepgramOptions.tag.join(",");
|
|
488
|
+
else queryParams.tag = deepgramOptions.tag;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (upstreamModelId === this.modelId && voice && voice !== this.modelId) warnings.push({
|
|
492
|
+
type: "unsupported",
|
|
493
|
+
feature: "voice",
|
|
494
|
+
details: `Deepgram TTS models embed the voice in the model ID. The voice parameter "${voice}" was ignored. Use the model ID to select a voice (e.g., "aura-2-helena-en").`
|
|
495
|
+
});
|
|
496
|
+
if (speed != null) queryParams.speed = String(speed);
|
|
497
|
+
if (upstreamModelId === this.modelId && language) warnings.push({
|
|
498
|
+
type: "unsupported",
|
|
499
|
+
feature: "language",
|
|
500
|
+
details: `Deepgram TTS models are language-specific via the model ID. Language parameter "${language}" was ignored. Select a model with the appropriate language suffix (e.g., "-en" for English).`
|
|
501
|
+
});
|
|
502
|
+
if (instructions) warnings.push({
|
|
503
|
+
type: "unsupported",
|
|
504
|
+
feature: "instructions",
|
|
505
|
+
details: `Deepgram TTS REST API does not support instructions. Instructions parameter was ignored.`
|
|
506
|
+
});
|
|
507
|
+
return {
|
|
508
|
+
requestBody,
|
|
509
|
+
queryParams,
|
|
510
|
+
warnings
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
async doGenerate(options) {
|
|
514
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
515
|
+
const { requestBody, queryParams, warnings } = await this.getArgs(options);
|
|
516
|
+
const { value: audio, responseHeaders, rawValue: rawResponse } = await postJsonToApi({
|
|
517
|
+
url: (() => {
|
|
518
|
+
const baseUrl = this.config.url({
|
|
519
|
+
path: "/v1/speak",
|
|
520
|
+
modelId: this.modelId
|
|
521
|
+
});
|
|
522
|
+
const queryString = new URLSearchParams(queryParams).toString();
|
|
523
|
+
return queryString ? `${baseUrl}?${queryString}` : baseUrl;
|
|
524
|
+
})(),
|
|
525
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
526
|
+
body: requestBody,
|
|
527
|
+
failedResponseHandler: deepgramFailedResponseHandler,
|
|
528
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
529
|
+
abortSignal: options.abortSignal,
|
|
530
|
+
fetch: this.config.fetch
|
|
531
|
+
});
|
|
532
|
+
const headerNumber = (name) => {
|
|
533
|
+
const value = responseHeaders?.[name];
|
|
534
|
+
if (value == null) return;
|
|
535
|
+
const parsed = Number(value);
|
|
536
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
537
|
+
};
|
|
538
|
+
const charCount = headerNumber("dg-char-count");
|
|
539
|
+
const breaksApplied = headerNumber("dg-breaks-applied");
|
|
540
|
+
const pronunciationsApplied = headerNumber("dg-pronunciations-applied");
|
|
541
|
+
const additionalModelUuids = responseHeaders?.["dg-additional-model-uuids"]?.split(",");
|
|
542
|
+
return {
|
|
543
|
+
audio,
|
|
544
|
+
warnings,
|
|
545
|
+
request: { body: JSON.stringify(requestBody) },
|
|
546
|
+
response: {
|
|
547
|
+
timestamp: currentDate,
|
|
548
|
+
modelId: this.modelId,
|
|
549
|
+
headers: responseHeaders,
|
|
550
|
+
body: rawResponse
|
|
551
|
+
},
|
|
552
|
+
providerMetadata: { deepgram: {
|
|
553
|
+
...responseHeaders?.["dg-model-name"] ? { modelName: responseHeaders["dg-model-name"] } : {},
|
|
554
|
+
...responseHeaders?.["dg-model-uuid"] ? { modelUuid: responseHeaders["dg-model-uuid"] } : {},
|
|
555
|
+
...additionalModelUuids ? { additionalModelUuids } : {},
|
|
556
|
+
...charCount != null ? { charCount } : {},
|
|
557
|
+
...breaksApplied != null ? { breaksApplied } : {},
|
|
558
|
+
...pronunciationsApplied != null ? { pronunciationsApplied } : {},
|
|
559
|
+
...responseHeaders?.["dg-pronunciation-warnings"] ? { pronunciationWarnings: responseHeaders["dg-pronunciation-warnings"] } : {},
|
|
560
|
+
...responseHeaders?.["dg-request-id"] ? { requestId: responseHeaders["dg-request-id"] } : {}
|
|
561
|
+
} }
|
|
562
|
+
};
|
|
563
|
+
}
|
|
647
564
|
};
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/version.ts
|
|
567
|
+
const VERSION = "3.1.23";
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/deepgram-provider.ts
|
|
570
|
+
/**
|
|
571
|
+
* Create an Deepgram provider instance.
|
|
572
|
+
*/
|
|
653
573
|
function createDeepgram(options = {}) {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
modelType: "imageModel",
|
|
706
|
-
message: "Deepgram does not provide image models"
|
|
707
|
-
});
|
|
708
|
-
};
|
|
709
|
-
return provider;
|
|
574
|
+
const getHeaders = () => withUserAgentSuffix({
|
|
575
|
+
authorization: `Token ${loadApiKey({
|
|
576
|
+
apiKey: options.apiKey,
|
|
577
|
+
environmentVariableName: "DEEPGRAM_API_KEY",
|
|
578
|
+
description: "Deepgram"
|
|
579
|
+
})}`,
|
|
580
|
+
...options.headers
|
|
581
|
+
}, `ai-sdk-deepgram/${VERSION}`);
|
|
582
|
+
const createTranscriptionModel = (modelId) => new DeepgramTranscriptionModel(modelId, {
|
|
583
|
+
provider: `deepgram.transcription`,
|
|
584
|
+
url: ({ path }) => `https://api.deepgram.com${path}`,
|
|
585
|
+
headers: getHeaders,
|
|
586
|
+
fetch: options.fetch
|
|
587
|
+
});
|
|
588
|
+
const createSpeechModel = (modelId) => new DeepgramSpeechModel(modelId, {
|
|
589
|
+
provider: `deepgram.speech`,
|
|
590
|
+
url: ({ path }) => `https://api.deepgram.com${path}`,
|
|
591
|
+
headers: getHeaders,
|
|
592
|
+
fetch: options.fetch
|
|
593
|
+
});
|
|
594
|
+
const provider = function(modelId) {
|
|
595
|
+
return { transcription: createTranscriptionModel(modelId) };
|
|
596
|
+
};
|
|
597
|
+
provider.specificationVersion = "v4";
|
|
598
|
+
provider.transcription = createTranscriptionModel;
|
|
599
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
600
|
+
provider.speech = createSpeechModel;
|
|
601
|
+
provider.speechModel = createSpeechModel;
|
|
602
|
+
provider.languageModel = (modelId) => {
|
|
603
|
+
throw new NoSuchModelError({
|
|
604
|
+
modelId,
|
|
605
|
+
modelType: "languageModel",
|
|
606
|
+
message: "Deepgram does not provide language models"
|
|
607
|
+
});
|
|
608
|
+
};
|
|
609
|
+
provider.embeddingModel = (modelId) => {
|
|
610
|
+
throw new NoSuchModelError({
|
|
611
|
+
modelId,
|
|
612
|
+
modelType: "embeddingModel",
|
|
613
|
+
message: "Deepgram does not provide text embedding models"
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
617
|
+
provider.imageModel = (modelId) => {
|
|
618
|
+
throw new NoSuchModelError({
|
|
619
|
+
modelId,
|
|
620
|
+
modelType: "imageModel",
|
|
621
|
+
message: "Deepgram does not provide image models"
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
return provider;
|
|
710
625
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
626
|
+
/**
|
|
627
|
+
* Default Deepgram provider instance.
|
|
628
|
+
*/
|
|
629
|
+
const deepgram = createDeepgram();
|
|
630
|
+
//#endregion
|
|
631
|
+
export { DeepgramSpeechModel, VERSION, createDeepgram, deepgram };
|
|
632
|
+
|
|
718
633
|
//# sourceMappingURL=index.js.map
|