@ai-sdk/hume 3.0.0-beta.5 → 3.0.0-beta.50
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 +370 -0
- package/README.md +3 -1
- package/dist/index.d.ts +39 -29
- package/dist/index.js +85 -67
- package/dist/index.js.map +1 -1
- package/docs/150-hume.mdx +2 -3
- package/package.json +15 -15
- package/src/hume-config.ts +2 -2
- package/src/hume-provider.ts +33 -4
- package/src/hume-speech-model-options.ts +77 -0
- package/src/hume-speech-model.ts +22 -81
- package/src/index.ts +1 -1
- package/dist/index.d.mts +0 -92
- package/dist/index.mjs +0 -255
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,110 +1,96 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createHume: () => createHume,
|
|
25
|
-
hume: () => hume
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/hume-provider.ts
|
|
30
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withUserAgentSuffix
|
|
8
|
+
} from "@ai-sdk/provider-utils";
|
|
31
9
|
|
|
32
10
|
// src/hume-speech-model.ts
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
import {
|
|
12
|
+
combineHeaders,
|
|
13
|
+
createBinaryResponseHandler,
|
|
14
|
+
parseProviderOptions,
|
|
15
|
+
postJsonToApi,
|
|
16
|
+
serializeModelOptions,
|
|
17
|
+
WORKFLOW_SERIALIZE,
|
|
18
|
+
WORKFLOW_DESERIALIZE
|
|
19
|
+
} from "@ai-sdk/provider-utils";
|
|
35
20
|
|
|
36
21
|
// src/hume-error.ts
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var humeErrorDataSchema =
|
|
40
|
-
error:
|
|
41
|
-
message:
|
|
42
|
-
code:
|
|
22
|
+
import { z } from "zod/v4";
|
|
23
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
24
|
+
var humeErrorDataSchema = z.object({
|
|
25
|
+
error: z.object({
|
|
26
|
+
message: z.string(),
|
|
27
|
+
code: z.number()
|
|
43
28
|
})
|
|
44
29
|
});
|
|
45
|
-
var humeFailedResponseHandler =
|
|
30
|
+
var humeFailedResponseHandler = createJsonErrorResponseHandler({
|
|
46
31
|
errorSchema: humeErrorDataSchema,
|
|
47
32
|
errorToMessage: (data) => data.error.message
|
|
48
33
|
});
|
|
49
34
|
|
|
50
|
-
// src/hume-speech-model.ts
|
|
51
|
-
|
|
35
|
+
// src/hume-speech-model-options.ts
|
|
36
|
+
import { z as z2 } from "zod/v4";
|
|
37
|
+
var humeSpeechModelOptionsSchema = z2.object({
|
|
52
38
|
/**
|
|
53
39
|
* Context for the speech synthesis request.
|
|
54
40
|
* Can be either a generationId for retrieving a previous generation,
|
|
55
41
|
* or a list of utterances to synthesize.
|
|
56
42
|
*/
|
|
57
|
-
context:
|
|
43
|
+
context: z2.object({
|
|
58
44
|
/**
|
|
59
45
|
* ID of a previously generated speech synthesis to retrieve.
|
|
60
46
|
*/
|
|
61
|
-
generationId:
|
|
47
|
+
generationId: z2.string()
|
|
62
48
|
}).or(
|
|
63
|
-
|
|
49
|
+
z2.object({
|
|
64
50
|
/**
|
|
65
51
|
* List of utterances to synthesize into speech.
|
|
66
52
|
*/
|
|
67
|
-
utterances:
|
|
68
|
-
|
|
53
|
+
utterances: z2.array(
|
|
54
|
+
z2.object({
|
|
69
55
|
/**
|
|
70
56
|
* The text content to convert to speech.
|
|
71
57
|
*/
|
|
72
|
-
text:
|
|
58
|
+
text: z2.string(),
|
|
73
59
|
/**
|
|
74
60
|
* Optional description or instructions for how the text should be spoken.
|
|
75
61
|
*/
|
|
76
|
-
description:
|
|
62
|
+
description: z2.string().optional(),
|
|
77
63
|
/**
|
|
78
64
|
* Optional speech rate multiplier.
|
|
79
65
|
*/
|
|
80
|
-
speed:
|
|
66
|
+
speed: z2.number().optional(),
|
|
81
67
|
/**
|
|
82
68
|
* Optional duration of silence to add after the utterance in seconds.
|
|
83
69
|
*/
|
|
84
|
-
trailingSilence:
|
|
70
|
+
trailingSilence: z2.number().optional(),
|
|
85
71
|
/**
|
|
86
72
|
* Voice configuration for the utterance.
|
|
87
73
|
* Can be specified by ID or name.
|
|
88
74
|
*/
|
|
89
|
-
voice:
|
|
75
|
+
voice: z2.object({
|
|
90
76
|
/**
|
|
91
77
|
* ID of the voice to use.
|
|
92
78
|
*/
|
|
93
|
-
id:
|
|
79
|
+
id: z2.string(),
|
|
94
80
|
/**
|
|
95
81
|
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
96
82
|
*/
|
|
97
|
-
provider:
|
|
83
|
+
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
98
84
|
}).or(
|
|
99
|
-
|
|
85
|
+
z2.object({
|
|
100
86
|
/**
|
|
101
87
|
* Name of the voice to use.
|
|
102
88
|
*/
|
|
103
|
-
name:
|
|
89
|
+
name: z2.string(),
|
|
104
90
|
/**
|
|
105
91
|
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
106
92
|
*/
|
|
107
|
-
provider:
|
|
93
|
+
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
108
94
|
})
|
|
109
95
|
).optional()
|
|
110
96
|
})
|
|
@@ -112,7 +98,9 @@ var humeSpeechModelOptionsSchema = import_v42.z.object({
|
|
|
112
98
|
})
|
|
113
99
|
).nullish()
|
|
114
100
|
});
|
|
115
|
-
|
|
101
|
+
|
|
102
|
+
// src/hume-speech-model.ts
|
|
103
|
+
var HumeSpeechModel = class _HumeSpeechModel {
|
|
116
104
|
constructor(modelId, config) {
|
|
117
105
|
this.modelId = modelId;
|
|
118
106
|
this.config = config;
|
|
@@ -121,6 +109,15 @@ var HumeSpeechModel = class {
|
|
|
121
109
|
get provider() {
|
|
122
110
|
return this.config.provider;
|
|
123
111
|
}
|
|
112
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
113
|
+
return serializeModelOptions({
|
|
114
|
+
modelId: model.modelId,
|
|
115
|
+
config: model.config
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
119
|
+
return new _HumeSpeechModel(options.modelId, options.config);
|
|
120
|
+
}
|
|
124
121
|
async getArgs({
|
|
125
122
|
text,
|
|
126
123
|
voice = "d8ab67c6-953d-4bd8-9370-8fa53a0f1453",
|
|
@@ -131,7 +128,7 @@ var HumeSpeechModel = class {
|
|
|
131
128
|
providerOptions
|
|
132
129
|
}) {
|
|
133
130
|
const warnings = [];
|
|
134
|
-
const humeOptions = await
|
|
131
|
+
const humeOptions = await parseProviderOptions({
|
|
135
132
|
provider: "hume",
|
|
136
133
|
providerOptions,
|
|
137
134
|
schema: humeSpeechModelOptionsSchema
|
|
@@ -200,22 +197,22 @@ var HumeSpeechModel = class {
|
|
|
200
197
|
};
|
|
201
198
|
}
|
|
202
199
|
async doGenerate(options) {
|
|
203
|
-
var _a, _b, _c;
|
|
200
|
+
var _a, _b, _c, _d, _e;
|
|
204
201
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
205
202
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
206
203
|
const {
|
|
207
204
|
value: audio,
|
|
208
205
|
responseHeaders,
|
|
209
206
|
rawValue: rawResponse
|
|
210
|
-
} = await
|
|
207
|
+
} = await postJsonToApi({
|
|
211
208
|
url: this.config.url({
|
|
212
209
|
path: "/v0/tts/file",
|
|
213
210
|
modelId: this.modelId
|
|
214
211
|
}),
|
|
215
|
-
headers: (
|
|
212
|
+
headers: combineHeaders((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
|
|
216
213
|
body: requestBody,
|
|
217
214
|
failedResponseHandler: humeFailedResponseHandler,
|
|
218
|
-
successfulResponseHandler:
|
|
215
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
219
216
|
abortSignal: options.abortSignal,
|
|
220
217
|
fetch: this.config.fetch
|
|
221
218
|
});
|
|
@@ -236,13 +233,13 @@ var HumeSpeechModel = class {
|
|
|
236
233
|
};
|
|
237
234
|
|
|
238
235
|
// src/version.ts
|
|
239
|
-
var VERSION = true ? "3.0.0-beta.
|
|
236
|
+
var VERSION = true ? "3.0.0-beta.50" : "0.0.0-test";
|
|
240
237
|
|
|
241
238
|
// src/hume-provider.ts
|
|
242
239
|
function createHume(options = {}) {
|
|
243
|
-
const getHeaders = () =>
|
|
240
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
244
241
|
{
|
|
245
|
-
"X-Hume-Api-Key":
|
|
242
|
+
"X-Hume-Api-Key": loadApiKey({
|
|
246
243
|
apiKey: options.apiKey,
|
|
247
244
|
environmentVariableName: "HUME_API_KEY",
|
|
248
245
|
description: "Hume"
|
|
@@ -262,15 +259,36 @@ function createHume(options = {}) {
|
|
|
262
259
|
speech: createSpeechModel()
|
|
263
260
|
};
|
|
264
261
|
};
|
|
262
|
+
provider.specificationVersion = "v4";
|
|
265
263
|
provider.speech = createSpeechModel;
|
|
266
264
|
provider.speechModel = createSpeechModel;
|
|
265
|
+
provider.languageModel = (modelId) => {
|
|
266
|
+
throw new NoSuchModelError({
|
|
267
|
+
modelId,
|
|
268
|
+
modelType: "languageModel",
|
|
269
|
+
message: "Hume does not provide language models"
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
provider.embeddingModel = (modelId) => {
|
|
273
|
+
throw new NoSuchModelError({
|
|
274
|
+
modelId,
|
|
275
|
+
modelType: "embeddingModel",
|
|
276
|
+
message: "Hume does not provide embedding models"
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
provider.imageModel = (modelId) => {
|
|
280
|
+
throw new NoSuchModelError({
|
|
281
|
+
modelId,
|
|
282
|
+
modelType: "imageModel",
|
|
283
|
+
message: "Hume does not provide image models"
|
|
284
|
+
});
|
|
285
|
+
};
|
|
267
286
|
return provider;
|
|
268
287
|
}
|
|
269
288
|
var hume = createHume();
|
|
270
|
-
|
|
271
|
-
0 && (module.exports = {
|
|
289
|
+
export {
|
|
272
290
|
VERSION,
|
|
273
291
|
createHume,
|
|
274
292
|
hume
|
|
275
|
-
}
|
|
293
|
+
};
|
|
276
294
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hume-provider.ts","../src/hume-speech-model.ts","../src/hume-error.ts","../src/version.ts"],"sourcesContent":["export { createHume, hume } from './hume-provider';\nexport type { HumeProvider, HumeProviderSettings } from './hume-provider';\nexport type { HumeSpeechModelOptions } from './hume-speech-model';\nexport { VERSION } from './version';\n","import { SpeechModelV4, ProviderV4 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends Pick<ProviderV4, 'speechModel'> {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV4;\n}\n\nexport interface HumeProviderSettings {\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create an Hume provider instance.\n */\nexport function createHume(options: HumeProviderSettings = {}): HumeProvider {\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n 'X-Hume-Api-Key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'HUME_API_KEY',\n description: 'Hume',\n }),\n ...options.headers,\n },\n `ai-sdk/hume/${VERSION}`,\n );\n\n const createSpeechModel = () =>\n new HumeSpeechModel('', {\n provider: `hume.speech`,\n url: ({ path }) => `https://api.hume.ai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const provider = function () {\n return {\n speech: createSpeechModel(),\n };\n };\n\n provider.speech = createSpeechModel;\n provider.speechModel = createSpeechModel;\n\n return provider satisfies HumeProvider;\n}\n\n/**\n * Default Hume provider instance.\n */\nexport const hume = createHume();\n","import { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechModelOptionsSchema = z.object({\n /**\n * Context for the speech synthesis request.\n * Can be either a generationId for retrieving a previous generation,\n * or a list of utterances to synthesize.\n */\n context: z\n .object({\n /**\n * ID of a previously generated speech synthesis to retrieve.\n */\n generationId: z.string(),\n })\n .or(\n z.object({\n /**\n * List of utterances to synthesize into speech.\n */\n utterances: z.array(\n z.object({\n /**\n * The text content to convert to speech.\n */\n text: z.string(),\n /**\n * Optional description or instructions for how the text should be spoken.\n */\n description: z.string().optional(),\n /**\n * Optional speech rate multiplier.\n */\n speed: z.number().optional(),\n /**\n * Optional duration of silence to add after the utterance in seconds.\n */\n trailingSilence: z.number().optional(),\n /**\n * Voice configuration for the utterance.\n * Can be specified by ID or name.\n */\n voice: z\n .object({\n /**\n * ID of the voice to use.\n */\n id: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n })\n .or(\n z.object({\n /**\n * Name of the voice to use.\n */\n name: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n }),\n )\n .optional(),\n }),\n ),\n }),\n )\n .nullish(),\n});\n\nexport type HumeSpeechModelOptions = z.infer<\n typeof humeSpeechModelOptionsSchema\n>;\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV4 {\n readonly specificationVersion = 'v4';\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: '',\n private readonly config: HumeSpeechModelConfig,\n ) {}\n\n private async getArgs({\n text,\n voice = 'd8ab67c6-953d-4bd8-9370-8fa53a0f1453',\n outputFormat = 'mp3',\n speed,\n instructions,\n language,\n providerOptions,\n }: Parameters<SpeechModelV4['doGenerate']>[0]) {\n const warnings: SharedV4Warning[] = [];\n\n // Parse provider options\n const humeOptions = await parseProviderOptions({\n provider: 'hume',\n providerOptions,\n schema: humeSpeechModelOptionsSchema,\n });\n\n // Create request body\n const requestBody: HumeSpeechAPITypes = {\n utterances: [\n {\n text,\n speed,\n description: instructions,\n voice: {\n id: voice,\n provider: 'HUME_AI',\n },\n },\n ],\n format: { type: 'mp3' },\n };\n\n if (outputFormat) {\n if (['mp3', 'pcm', 'wav'].includes(outputFormat)) {\n requestBody.format = { type: outputFormat as 'mp3' | 'pcm' | 'wav' };\n } else {\n warnings.push({\n type: 'unsupported',\n feature: 'outputFormat',\n details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`,\n });\n }\n }\n\n // Add provider-specific options\n if (humeOptions) {\n const speechModelOptions: Omit<\n HumeSpeechAPITypes,\n 'utterances' | 'format'\n > = {};\n\n if (humeOptions.context) {\n if ('generationId' in humeOptions.context) {\n speechModelOptions.context = {\n generation_id: humeOptions.context.generationId,\n };\n } else {\n speechModelOptions.context = {\n utterances: humeOptions.context.utterances.map(utterance => ({\n text: utterance.text,\n description: utterance.description,\n speed: utterance.speed,\n trailing_silence: utterance.trailingSilence,\n voice: utterance.voice,\n })),\n };\n }\n }\n\n for (const key in speechModelOptions) {\n const value =\n speechModelOptions[\n key as keyof Omit<HumeSpeechAPITypes, 'utterances' | 'format'>\n ];\n if (value !== undefined) {\n (requestBody as Record<string, unknown>)[key] = value;\n }\n }\n }\n\n if (language) {\n warnings.push({\n type: 'unsupported',\n feature: 'language',\n details: `Hume speech models do not support language selection. Language parameter \"${language}\" was ignored.`,\n });\n }\n\n return {\n requestBody,\n warnings,\n };\n }\n\n async doGenerate(\n options: Parameters<SpeechModelV4['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { requestBody, warnings } = await this.getArgs(options);\n\n const {\n value: audio,\n responseHeaders,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: this.config.url({\n path: '/v0/tts/file',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers(), options.headers),\n body: requestBody,\n failedResponseHandler: humeFailedResponseHandler,\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n audio,\n warnings,\n request: {\n body: JSON.stringify(requestBody),\n },\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n body: rawResponse,\n },\n };\n }\n}\n","import { z } from 'zod/v4';\nimport { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\n\nexport const humeErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n code: z.number(),\n }),\n});\n\nexport type HumeErrorData = z.infer<typeof humeErrorDataSchema>;\n\nexport const humeFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: humeErrorDataSchema,\n errorToMessage: data => data.error.message,\n});\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,yBAIO;;;ACJP,IAAAC,yBAKO;AACP,IAAAC,aAAkB;;;ACPlB,gBAAkB;AAClB,4BAA+C;AAExC,IAAM,sBAAsB,YAAE,OAAO;AAAA,EAC1C,OAAO,YAAE,OAAO;AAAA,IACd,SAAS,YAAE,OAAO;AAAA,IAClB,MAAM,YAAE,OAAO;AAAA,EACjB,CAAC;AACH,CAAC;AAIM,IAAM,gCAA4B,sDAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ADFD,IAAM,+BAA+B,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM5C,SA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U;AAAA,IACV,KAAK,CAAC,EAAE,KAAK,MAAM,sBAAsB,IAAI;AAAA,IAC7C,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,WAAY;AAC3B,WAAO;AAAA,MACL,QAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AAEA,WAAS,SAAS;AAClB,WAAS,cAAc;AAEvB,SAAO;AACT;AAKO,IAAM,OAAO,WAAW;","names":["import_provider_utils","import_provider_utils","import_v4"]}
|
|
1
|
+
{"version":3,"sources":["../src/hume-provider.ts","../src/hume-speech-model.ts","../src/hume-error.ts","../src/hume-speech-model-options.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type SpeechModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends ProviderV4 {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV4;\n}\n\nexport interface HumeProviderSettings {\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create an Hume provider instance.\n */\nexport function createHume(options: HumeProviderSettings = {}): HumeProvider {\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n 'X-Hume-Api-Key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'HUME_API_KEY',\n description: 'Hume',\n }),\n ...options.headers,\n },\n `ai-sdk/hume/${VERSION}`,\n );\n\n const createSpeechModel = () =>\n new HumeSpeechModel('', {\n provider: `hume.speech`,\n url: ({ path }) => `https://api.hume.ai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const provider = function () {\n return {\n speech: createSpeechModel(),\n };\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.speech = createSpeechModel;\n provider.speechModel = createSpeechModel;\n\n provider.languageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n message: 'Hume does not provide language models',\n });\n };\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n message: 'Hume does not provide embedding models',\n });\n };\n\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'imageModel',\n message: 'Hume does not provide image models',\n });\n };\n\n return provider as HumeProvider;\n}\n\n/**\n * Default Hume provider instance.\n */\nexport const hume = createHume();\n","import type { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n serializeModelOptions,\n WORKFLOW_SERIALIZE,\n WORKFLOW_DESERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { humeSpeechModelOptionsSchema } from './hume-speech-model-options';\nimport type { HumeSpeechAPITypes } from './hume-api-types';\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV4 {\n readonly specificationVersion = 'v4';\n\n get provider(): string {\n return this.config.provider;\n }\n\n static [WORKFLOW_SERIALIZE](model: HumeSpeechModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: '';\n config: HumeSpeechModelConfig;\n }) {\n return new HumeSpeechModel(options.modelId as '', options.config);\n }\n\n constructor(\n readonly modelId: '',\n private readonly config: HumeSpeechModelConfig,\n ) {}\n\n private async getArgs({\n text,\n voice = 'd8ab67c6-953d-4bd8-9370-8fa53a0f1453',\n outputFormat = 'mp3',\n speed,\n instructions,\n language,\n providerOptions,\n }: Parameters<SpeechModelV4['doGenerate']>[0]) {\n const warnings: SharedV4Warning[] = [];\n\n // Parse provider options\n const humeOptions = await parseProviderOptions({\n provider: 'hume',\n providerOptions,\n schema: humeSpeechModelOptionsSchema,\n });\n\n // Create request body\n const requestBody: HumeSpeechAPITypes = {\n utterances: [\n {\n text,\n speed,\n description: instructions,\n voice: {\n id: voice,\n provider: 'HUME_AI',\n },\n },\n ],\n format: { type: 'mp3' },\n };\n\n if (outputFormat) {\n if (['mp3', 'pcm', 'wav'].includes(outputFormat)) {\n requestBody.format = { type: outputFormat as 'mp3' | 'pcm' | 'wav' };\n } else {\n warnings.push({\n type: 'unsupported',\n feature: 'outputFormat',\n details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`,\n });\n }\n }\n\n // Add provider-specific options\n if (humeOptions) {\n const speechModelOptions: Omit<\n HumeSpeechAPITypes,\n 'utterances' | 'format'\n > = {};\n\n if (humeOptions.context) {\n if ('generationId' in humeOptions.context) {\n speechModelOptions.context = {\n generation_id: humeOptions.context.generationId,\n };\n } else {\n speechModelOptions.context = {\n utterances: humeOptions.context.utterances.map(utterance => ({\n text: utterance.text,\n description: utterance.description,\n speed: utterance.speed,\n trailing_silence: utterance.trailingSilence,\n voice: utterance.voice,\n })),\n };\n }\n }\n\n for (const key in speechModelOptions) {\n const value =\n speechModelOptions[\n key as keyof Omit<HumeSpeechAPITypes, 'utterances' | 'format'>\n ];\n if (value !== undefined) {\n (requestBody as Record<string, unknown>)[key] = value;\n }\n }\n }\n\n if (language) {\n warnings.push({\n type: 'unsupported',\n feature: 'language',\n details: `Hume speech models do not support language selection. Language parameter \"${language}\" was ignored.`,\n });\n }\n\n return {\n requestBody,\n warnings,\n };\n }\n\n async doGenerate(\n options: Parameters<SpeechModelV4['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { requestBody, warnings } = await this.getArgs(options);\n\n const {\n value: audio,\n responseHeaders,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: this.config.url({\n path: '/v0/tts/file',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers?.(), options.headers),\n body: requestBody,\n failedResponseHandler: humeFailedResponseHandler,\n successfulResponseHandler: createBinaryResponseHandler(),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n audio,\n warnings,\n request: {\n body: JSON.stringify(requestBody),\n },\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n body: rawResponse,\n },\n };\n }\n}\n","import { z } from 'zod/v4';\nimport { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\n\nexport const humeErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n code: z.number(),\n }),\n});\n\nexport type HumeErrorData = z.infer<typeof humeErrorDataSchema>;\n\nexport const humeFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: humeErrorDataSchema,\n errorToMessage: data => data.error.message,\n});\n","import { z } from 'zod/v4';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nexport const humeSpeechModelOptionsSchema = z.object({\n /**\n * Context for the speech synthesis request.\n * Can be either a generationId for retrieving a previous generation,\n * or a list of utterances to synthesize.\n */\n context: z\n .object({\n /**\n * ID of a previously generated speech synthesis to retrieve.\n */\n generationId: z.string(),\n })\n .or(\n z.object({\n /**\n * List of utterances to synthesize into speech.\n */\n utterances: z.array(\n z.object({\n /**\n * The text content to convert to speech.\n */\n text: z.string(),\n /**\n * Optional description or instructions for how the text should be spoken.\n */\n description: z.string().optional(),\n /**\n * Optional speech rate multiplier.\n */\n speed: z.number().optional(),\n /**\n * Optional duration of silence to add after the utterance in seconds.\n */\n trailingSilence: z.number().optional(),\n /**\n * Voice configuration for the utterance.\n * Can be specified by ID or name.\n */\n voice: z\n .object({\n /**\n * ID of the voice to use.\n */\n id: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n })\n .or(\n z.object({\n /**\n * Name of the voice to use.\n */\n name: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n }),\n )\n .optional(),\n }),\n ),\n }),\n )\n .nullish(),\n});\n\nexport type HumeSpeechModelOptions = z.infer<\n typeof humeSpeechModelOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;;;ACRP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTP,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAExC,IAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,OAAO,EAAE,OAAO;AAAA,IACd,SAAS,EAAE,OAAO;AAAA,IAClB,MAAM,EAAE,OAAO;AAAA,EACjB,CAAC;AACH,CAAC;AAIM,IAAM,4BAA4B,+BAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ACfD,SAAS,KAAAA,UAAS;AAGX,IAAM,+BAA+BA,GAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnD,SAASA,GACN,OAAO;AAAA;AAAA;AAAA;AAAA,IAIN,cAAcA,GAAE,OAAO;AAAA,EACzB,CAAC,EACA;AAAA,IACCA,GAAE,OAAO;AAAA;AAAA;AAAA;AAAA,MAIP,YAAYA,GAAE;AAAA,QACZA,GAAE,OAAO;AAAA;A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IACA,eAAe,OAAO;AAAA,EACxB;AAEF,QAAM,oBAAoB,MACxB,IAAI,gBAAgB,IAAI;AAAA,IACtB,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,KAAK,MAAM,sBAAsB,IAAI;AAAA,IAC7C,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,WAAY;AAC3B,WAAO;AAAA,MACL,QAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AAEA,WAAS,uBAAuB;AAChC,WAAS,SAAS;AAClB,WAAS,cAAc;AAEvB,WAAS,gBAAgB,CAAC,YAAoB;AAC5C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,MACX,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAKO,IAAM,OAAO,WAAW;","names":["z"]}
|
package/docs/150-hume.mdx
CHANGED
|
@@ -76,7 +76,7 @@ const model = hume.speech();
|
|
|
76
76
|
You can pass standard speech generation options like `voice`, `speed`, `instructions`, and `outputFormat`:
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
|
-
import {
|
|
79
|
+
import { generateSpeech } from 'ai';
|
|
80
80
|
import { hume } from '@ai-sdk/hume';
|
|
81
81
|
|
|
82
82
|
const result = await generateSpeech({
|
|
@@ -123,7 +123,7 @@ const result = await generateSpeech({
|
|
|
123
123
|
You can pass additional provider-specific options using the `providerOptions` argument:
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
|
-
import {
|
|
126
|
+
import { generateSpeech } from 'ai';
|
|
127
127
|
import { hume } from '@ai-sdk/hume';
|
|
128
128
|
import { type HumeSpeechModelOptions } from '@ai-sdk/hume';
|
|
129
129
|
|
|
@@ -145,7 +145,6 @@ The following provider options are available:
|
|
|
145
145
|
- **context** _object_
|
|
146
146
|
|
|
147
147
|
Context for the speech synthesis request. Can be either:
|
|
148
|
-
|
|
149
148
|
- `{ generationId: string }` - ID of a previously generated speech synthesis to use as context.
|
|
150
149
|
- `{ utterances: Utterance[] }` - An array of utterance objects for context, where each utterance has:
|
|
151
150
|
- `text` _string_ (required) - The text content.
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/hume",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.50",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"license": "Apache-2.0",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
@@ -24,35 +24,37 @@
|
|
|
24
24
|
"./package.json": "./package.json",
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"import": "./dist/index.
|
|
28
|
-
"
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider": "
|
|
33
|
-
"@ai-sdk/provider
|
|
32
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.49",
|
|
33
|
+
"@ai-sdk/provider": "4.0.0-beta.19"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "
|
|
37
|
-
"tsup": "^8",
|
|
36
|
+
"@types/node": "22.19.19",
|
|
37
|
+
"tsup": "^8.5.1",
|
|
38
38
|
"typescript": "5.6.3",
|
|
39
39
|
"zod": "3.25.76",
|
|
40
|
-
"@ai-
|
|
41
|
-
"@
|
|
40
|
+
"@vercel/ai-tsconfig": "0.0.0",
|
|
41
|
+
"@ai-sdk/test-server": "2.0.0-beta.7"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"zod": "^3.25.76 || ^4.1.8"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
47
|
+
"node": ">=22"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
|
-
"access": "public"
|
|
50
|
+
"access": "public",
|
|
51
|
+
"provenance": true
|
|
51
52
|
},
|
|
52
53
|
"homepage": "https://ai-sdk.dev/docs",
|
|
53
54
|
"repository": {
|
|
54
55
|
"type": "git",
|
|
55
|
-
"url": "
|
|
56
|
+
"url": "https://github.com/vercel/ai",
|
|
57
|
+
"directory": "packages/hume"
|
|
56
58
|
},
|
|
57
59
|
"bugs": {
|
|
58
60
|
"url": "https://github.com/vercel/ai/issues"
|
|
@@ -64,9 +66,7 @@
|
|
|
64
66
|
"build": "tsup --tsconfig tsconfig.build.json",
|
|
65
67
|
"build:watch": "tsup --tsconfig tsconfig.build.json --watch",
|
|
66
68
|
"clean": "del-cli dist docs",
|
|
67
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
68
69
|
"type-check": "tsc --noEmit",
|
|
69
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
70
70
|
"test": "pnpm test:node && pnpm test:edge",
|
|
71
71
|
"test:watch": "vitest --config vitest.node.config.js --watch",
|
|
72
72
|
"test:edge": "vitest --config vitest.edge.config.js --run",
|
package/src/hume-config.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
1
|
+
import type { FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
2
|
|
|
3
3
|
export type HumeConfig = {
|
|
4
4
|
provider: string;
|
|
5
5
|
url: (options: { modelId: string; path: string }) => string;
|
|
6
|
-
headers
|
|
6
|
+
headers?: () => Record<string, string | undefined>;
|
|
7
7
|
fetch?: FetchFunction;
|
|
8
8
|
generateId?: () => string;
|
|
9
9
|
};
|
package/src/hume-provider.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { SpeechModelV4, ProviderV4 } from '@ai-sdk/provider';
|
|
2
1
|
import {
|
|
3
|
-
|
|
2
|
+
NoSuchModelError,
|
|
3
|
+
type SpeechModelV4,
|
|
4
|
+
type ProviderV4,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
6
|
+
import {
|
|
4
7
|
loadApiKey,
|
|
5
8
|
withUserAgentSuffix,
|
|
9
|
+
type FetchFunction,
|
|
6
10
|
} from '@ai-sdk/provider-utils';
|
|
7
11
|
import { HumeSpeechModel } from './hume-speech-model';
|
|
8
12
|
import { VERSION } from './version';
|
|
9
13
|
|
|
10
|
-
export interface HumeProvider extends
|
|
14
|
+
export interface HumeProvider extends ProviderV4 {
|
|
11
15
|
(settings?: {}): {
|
|
12
16
|
speech: HumeSpeechModel;
|
|
13
17
|
};
|
|
@@ -67,10 +71,35 @@ export function createHume(options: HumeProviderSettings = {}): HumeProvider {
|
|
|
67
71
|
};
|
|
68
72
|
};
|
|
69
73
|
|
|
74
|
+
provider.specificationVersion = 'v4' as const;
|
|
70
75
|
provider.speech = createSpeechModel;
|
|
71
76
|
provider.speechModel = createSpeechModel;
|
|
72
77
|
|
|
73
|
-
|
|
78
|
+
provider.languageModel = (modelId: string) => {
|
|
79
|
+
throw new NoSuchModelError({
|
|
80
|
+
modelId,
|
|
81
|
+
modelType: 'languageModel',
|
|
82
|
+
message: 'Hume does not provide language models',
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
provider.embeddingModel = (modelId: string) => {
|
|
87
|
+
throw new NoSuchModelError({
|
|
88
|
+
modelId,
|
|
89
|
+
modelType: 'embeddingModel',
|
|
90
|
+
message: 'Hume does not provide embedding models',
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
provider.imageModel = (modelId: string) => {
|
|
95
|
+
throw new NoSuchModelError({
|
|
96
|
+
modelId,
|
|
97
|
+
modelType: 'imageModel',
|
|
98
|
+
message: 'Hume does not provide image models',
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return provider as HumeProvider;
|
|
74
103
|
}
|
|
75
104
|
|
|
76
105
|
/**
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
|
|
3
|
+
// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file
|
|
4
|
+
export const humeSpeechModelOptionsSchema = z.object({
|
|
5
|
+
/**
|
|
6
|
+
* Context for the speech synthesis request.
|
|
7
|
+
* Can be either a generationId for retrieving a previous generation,
|
|
8
|
+
* or a list of utterances to synthesize.
|
|
9
|
+
*/
|
|
10
|
+
context: z
|
|
11
|
+
.object({
|
|
12
|
+
/**
|
|
13
|
+
* ID of a previously generated speech synthesis to retrieve.
|
|
14
|
+
*/
|
|
15
|
+
generationId: z.string(),
|
|
16
|
+
})
|
|
17
|
+
.or(
|
|
18
|
+
z.object({
|
|
19
|
+
/**
|
|
20
|
+
* List of utterances to synthesize into speech.
|
|
21
|
+
*/
|
|
22
|
+
utterances: z.array(
|
|
23
|
+
z.object({
|
|
24
|
+
/**
|
|
25
|
+
* The text content to convert to speech.
|
|
26
|
+
*/
|
|
27
|
+
text: z.string(),
|
|
28
|
+
/**
|
|
29
|
+
* Optional description or instructions for how the text should be spoken.
|
|
30
|
+
*/
|
|
31
|
+
description: z.string().optional(),
|
|
32
|
+
/**
|
|
33
|
+
* Optional speech rate multiplier.
|
|
34
|
+
*/
|
|
35
|
+
speed: z.number().optional(),
|
|
36
|
+
/**
|
|
37
|
+
* Optional duration of silence to add after the utterance in seconds.
|
|
38
|
+
*/
|
|
39
|
+
trailingSilence: z.number().optional(),
|
|
40
|
+
/**
|
|
41
|
+
* Voice configuration for the utterance.
|
|
42
|
+
* Can be specified by ID or name.
|
|
43
|
+
*/
|
|
44
|
+
voice: z
|
|
45
|
+
.object({
|
|
46
|
+
/**
|
|
47
|
+
* ID of the voice to use.
|
|
48
|
+
*/
|
|
49
|
+
id: z.string(),
|
|
50
|
+
/**
|
|
51
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
52
|
+
*/
|
|
53
|
+
provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
|
|
54
|
+
})
|
|
55
|
+
.or(
|
|
56
|
+
z.object({
|
|
57
|
+
/**
|
|
58
|
+
* Name of the voice to use.
|
|
59
|
+
*/
|
|
60
|
+
name: z.string(),
|
|
61
|
+
/**
|
|
62
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
63
|
+
*/
|
|
64
|
+
provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
.optional(),
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
.nullish(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export type HumeSpeechModelOptions = z.infer<
|
|
76
|
+
typeof humeSpeechModelOptionsSchema
|
|
77
|
+
>;
|