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