@ai-sdk/hume 2.0.66 → 2.0.68
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 +16 -0
- package/dist/index.d.mts +22 -28
- package/dist/index.d.ts +22 -28
- package/dist/index.js +65 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/hume-error.ts +17 -8
- package/src/hume-speech-model.ts +68 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/hume
|
|
2
2
|
|
|
3
|
+
## 2.0.68
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1e6946b: Defer validation schema construction until first use to reduce provider import time.
|
|
8
|
+
- Updated dependencies [1183cc4]
|
|
9
|
+
- Updated dependencies [d726591]
|
|
10
|
+
- @ai-sdk/provider-utils@4.0.62
|
|
11
|
+
|
|
12
|
+
## 2.0.67
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [5aa3086]
|
|
17
|
+
- @ai-sdk/provider-utils@4.0.61
|
|
18
|
+
|
|
3
19
|
## 2.0.66
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
|
+
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
5
|
type HumeConfig = {
|
|
6
6
|
provider: string;
|
|
@@ -13,32 +13,26 @@ type HumeConfig = {
|
|
|
13
13
|
generateId?: () => string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
declare const humeSpeechModelOptionsSchema:
|
|
17
|
-
context
|
|
18
|
-
generationId:
|
|
19
|
-
}
|
|
20
|
-
utterances:
|
|
21
|
-
text:
|
|
22
|
-
description
|
|
23
|
-
speed
|
|
24
|
-
trailingSilence
|
|
25
|
-
voice
|
|
26
|
-
id:
|
|
27
|
-
provider
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}>>;
|
|
37
|
-
}, z.core.$strip>]>>;
|
|
38
|
-
}, z.core.$strip>>;
|
|
39
|
-
}, z.core.$strip>]>>>;
|
|
40
|
-
}, z.core.$strip>;
|
|
41
|
-
type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
|
|
16
|
+
declare const humeSpeechModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
17
|
+
context?: {
|
|
18
|
+
generationId: string;
|
|
19
|
+
} | {
|
|
20
|
+
utterances: {
|
|
21
|
+
text: string;
|
|
22
|
+
description?: string | undefined;
|
|
23
|
+
speed?: number | undefined;
|
|
24
|
+
trailingSilence?: number | undefined;
|
|
25
|
+
voice?: {
|
|
26
|
+
id: string;
|
|
27
|
+
provider?: "HUME_AI" | "CUSTOM_VOICE" | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
name: string;
|
|
30
|
+
provider?: "HUME_AI" | "CUSTOM_VOICE" | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}[];
|
|
33
|
+
} | null | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
type HumeSpeechModelOptions = InferSchema<typeof humeSpeechModelOptionsSchema>;
|
|
42
36
|
interface HumeSpeechModelConfig extends HumeConfig {
|
|
43
37
|
_internal?: {
|
|
44
38
|
currentDate?: () => Date;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
|
+
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
5
|
type HumeConfig = {
|
|
6
6
|
provider: string;
|
|
@@ -13,32 +13,26 @@ type HumeConfig = {
|
|
|
13
13
|
generateId?: () => string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
declare const humeSpeechModelOptionsSchema:
|
|
17
|
-
context
|
|
18
|
-
generationId:
|
|
19
|
-
}
|
|
20
|
-
utterances:
|
|
21
|
-
text:
|
|
22
|
-
description
|
|
23
|
-
speed
|
|
24
|
-
trailingSilence
|
|
25
|
-
voice
|
|
26
|
-
id:
|
|
27
|
-
provider
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}>>;
|
|
37
|
-
}, z.core.$strip>]>>;
|
|
38
|
-
}, z.core.$strip>>;
|
|
39
|
-
}, z.core.$strip>]>>>;
|
|
40
|
-
}, z.core.$strip>;
|
|
41
|
-
type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
|
|
16
|
+
declare const humeSpeechModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
17
|
+
context?: {
|
|
18
|
+
generationId: string;
|
|
19
|
+
} | {
|
|
20
|
+
utterances: {
|
|
21
|
+
text: string;
|
|
22
|
+
description?: string | undefined;
|
|
23
|
+
speed?: number | undefined;
|
|
24
|
+
trailingSilence?: number | undefined;
|
|
25
|
+
voice?: {
|
|
26
|
+
id: string;
|
|
27
|
+
provider?: "HUME_AI" | "CUSTOM_VOICE" | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
name: string;
|
|
30
|
+
provider?: "HUME_AI" | "CUSTOM_VOICE" | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}[];
|
|
33
|
+
} | null | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
type HumeSpeechModelOptions = InferSchema<typeof humeSpeechModelOptionsSchema>;
|
|
42
36
|
interface HumeSpeechModelConfig extends HumeConfig {
|
|
43
37
|
_internal?: {
|
|
44
38
|
currentDate?: () => Date;
|
package/dist/index.js
CHANGED
|
@@ -36,82 +36,90 @@ var import_v42 = require("zod/v4");
|
|
|
36
36
|
// src/hume-error.ts
|
|
37
37
|
var import_v4 = require("zod/v4");
|
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
39
|
-
var humeErrorDataSchema =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
var humeErrorDataSchema = (0, import_provider_utils.lazySchema)(
|
|
40
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
41
|
+
import_v4.z.object({
|
|
42
|
+
error: import_v4.z.object({
|
|
43
|
+
message: import_v4.z.string(),
|
|
44
|
+
code: import_v4.z.number()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
);
|
|
45
49
|
var humeFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
|
46
50
|
errorSchema: humeErrorDataSchema,
|
|
47
51
|
errorToMessage: (data) => data.error.message
|
|
48
52
|
});
|
|
49
53
|
|
|
50
54
|
// src/hume-speech-model.ts
|
|
51
|
-
var humeSpeechModelOptionsSchema =
|
|
52
|
-
|
|
53
|
-
* Context for the speech synthesis request.
|
|
54
|
-
* Can be either a generationId for retrieving a previous generation,
|
|
55
|
-
* or a list of utterances to synthesize.
|
|
56
|
-
*/
|
|
57
|
-
context: import_v42.z.object({
|
|
58
|
-
/**
|
|
59
|
-
* ID of a previously generated speech synthesis to retrieve.
|
|
60
|
-
*/
|
|
61
|
-
generationId: import_v42.z.string()
|
|
62
|
-
}).or(
|
|
55
|
+
var humeSpeechModelOptionsSchema = (0, import_provider_utils2.lazySchema)(
|
|
56
|
+
() => (0, import_provider_utils2.zodSchema)(
|
|
63
57
|
import_v42.z.object({
|
|
64
58
|
/**
|
|
65
|
-
*
|
|
59
|
+
* Context for the speech synthesis request.
|
|
60
|
+
* Can be either a generationId for retrieving a previous generation,
|
|
61
|
+
* or a list of utterances to synthesize.
|
|
66
62
|
*/
|
|
67
|
-
|
|
63
|
+
context: import_v42.z.object({
|
|
64
|
+
/**
|
|
65
|
+
* ID of a previously generated speech synthesis to retrieve.
|
|
66
|
+
*/
|
|
67
|
+
generationId: import_v42.z.string()
|
|
68
|
+
}).or(
|
|
68
69
|
import_v42.z.object({
|
|
69
70
|
/**
|
|
70
|
-
*
|
|
71
|
+
* List of utterances to synthesize into speech.
|
|
71
72
|
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Optional description or instructions for how the text should be spoken.
|
|
75
|
-
*/
|
|
76
|
-
description: import_v42.z.string().optional(),
|
|
77
|
-
/**
|
|
78
|
-
* Optional speech rate multiplier.
|
|
79
|
-
*/
|
|
80
|
-
speed: import_v42.z.number().optional(),
|
|
81
|
-
/**
|
|
82
|
-
* Optional duration of silence to add after the utterance in seconds.
|
|
83
|
-
*/
|
|
84
|
-
trailingSilence: import_v42.z.number().optional(),
|
|
85
|
-
/**
|
|
86
|
-
* Voice configuration for the utterance.
|
|
87
|
-
* Can be specified by ID or name.
|
|
88
|
-
*/
|
|
89
|
-
voice: import_v42.z.object({
|
|
90
|
-
/**
|
|
91
|
-
* ID of the voice to use.
|
|
92
|
-
*/
|
|
93
|
-
id: import_v42.z.string(),
|
|
94
|
-
/**
|
|
95
|
-
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
96
|
-
*/
|
|
97
|
-
provider: import_v42.z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
98
|
-
}).or(
|
|
73
|
+
utterances: import_v42.z.array(
|
|
99
74
|
import_v42.z.object({
|
|
100
75
|
/**
|
|
101
|
-
*
|
|
76
|
+
* The text content to convert to speech.
|
|
77
|
+
*/
|
|
78
|
+
text: import_v42.z.string(),
|
|
79
|
+
/**
|
|
80
|
+
* Optional description or instructions for how the text should be spoken.
|
|
81
|
+
*/
|
|
82
|
+
description: import_v42.z.string().optional(),
|
|
83
|
+
/**
|
|
84
|
+
* Optional speech rate multiplier.
|
|
85
|
+
*/
|
|
86
|
+
speed: import_v42.z.number().optional(),
|
|
87
|
+
/**
|
|
88
|
+
* Optional duration of silence to add after the utterance in seconds.
|
|
102
89
|
*/
|
|
103
|
-
|
|
90
|
+
trailingSilence: import_v42.z.number().optional(),
|
|
104
91
|
/**
|
|
105
|
-
*
|
|
92
|
+
* Voice configuration for the utterance.
|
|
93
|
+
* Can be specified by ID or name.
|
|
106
94
|
*/
|
|
107
|
-
|
|
95
|
+
voice: import_v42.z.object({
|
|
96
|
+
/**
|
|
97
|
+
* ID of the voice to use.
|
|
98
|
+
*/
|
|
99
|
+
id: import_v42.z.string(),
|
|
100
|
+
/**
|
|
101
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
102
|
+
*/
|
|
103
|
+
provider: import_v42.z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
104
|
+
}).or(
|
|
105
|
+
import_v42.z.object({
|
|
106
|
+
/**
|
|
107
|
+
* Name of the voice to use.
|
|
108
|
+
*/
|
|
109
|
+
name: import_v42.z.string(),
|
|
110
|
+
/**
|
|
111
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
112
|
+
*/
|
|
113
|
+
provider: import_v42.z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
114
|
+
})
|
|
115
|
+
).optional()
|
|
108
116
|
})
|
|
109
|
-
)
|
|
117
|
+
)
|
|
110
118
|
})
|
|
111
|
-
)
|
|
119
|
+
).nullish()
|
|
112
120
|
})
|
|
113
|
-
)
|
|
114
|
-
|
|
121
|
+
)
|
|
122
|
+
);
|
|
115
123
|
var HumeSpeechModel = class {
|
|
116
124
|
constructor(modelId, config) {
|
|
117
125
|
this.modelId = modelId;
|
|
@@ -236,7 +244,7 @@ var HumeSpeechModel = class {
|
|
|
236
244
|
};
|
|
237
245
|
|
|
238
246
|
// src/version.ts
|
|
239
|
-
var VERSION = true ? "2.0.
|
|
247
|
+
var VERSION = true ? "2.0.68" : "0.0.0-test";
|
|
240
248
|
|
|
241
249
|
// src/hume-provider.ts
|
|
242
250
|
function createHume(options = {}) {
|
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 type { SpeechModelV3, ProviderV3 } 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 Pick<ProviderV3, 'speechModel'> {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV3;\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 type { SpeechModelV3, SharedV3Warning } 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 type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport type { 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 SpeechModelV3 {\n readonly specificationVersion = 'v3';\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<SpeechModelV3['doGenerate']>[0]) {\n const warnings: SharedV3Warning[] = [];\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<SpeechModelV3['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV3['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;AA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X,SAAS,KAAK;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;;;AE7OO,IAAM,UACX,OACI,WACA;;;AHoCC,SAAS,WAAW,UAAgC,CAAC,GAAiB;AAC3E,QAAM,aAAa,UACjB;AAAA,IACE;AAAA,MACE,sBAAkB,mCAAW;AAAA,QAC3B,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,GAAG,QAAQ;AAAA,IACb;AAAA,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,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/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 type { SpeechModelV3, ProviderV3 } 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 Pick<ProviderV3, 'speechModel'> {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV3;\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 type { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';\nimport {\n lazySchema,\n zodSchema,\n type InferSchema,\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport type { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechModelOptionsSchema = lazySchema(() =>\n zodSchema(\n 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 ),\n);\n\nexport type HumeSpeechModelOptions = InferSchema<\n typeof humeSpeechModelOptionsSchema\n>;\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV3 {\n readonly specificationVersion = 'v3';\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<SpeechModelV3['doGenerate']>[0]) {\n const warnings: SharedV3Warning[] = [];\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<SpeechModelV3['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV3['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 {\n lazySchema,\n zodSchema,\n type InferSchema,\n createJsonErrorResponseHandler,\n} from '@ai-sdk/provider-utils';\n\nexport const humeErrorDataSchema = lazySchema(() =>\n zodSchema(\n z.object({\n error: z.object({\n message: z.string(),\n code: z.number(),\n }),\n }),\n ),\n);\n\nexport type HumeErrorData = InferSchema<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,yBAQO;AACP,IAAAC,aAAkB;;;ACVlB,gBAAkB;AAClB,4BAKO;AAEA,IAAM,0BAAsB;AAAA,EAAW,UAC5C;AAAA,IACE,YAAE,OAAO;AAAA,MACP,OAAO,YAAE,OAAO;AAAA,QACd,SAAS,YAAE,OAAO;AAAA,QAClB,MAAM,YAAE,OAAO;AAAA,MACjB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAIO,IAAM,gCAA4B,sDAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ADRD,IAAM,mCAA+B;AAAA,EAAW,UAC9C;AAAA,IACE,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMP,SAAS,aACN,OAAO;AAAA;AAAA;AAAA;AAAA,QAIN,cAAc,aAAE,OAAO;AAAA,MACzB,CAAC,EACA;AAAA,QACC,aAAE,O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;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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/hume-speech-model.ts
|
|
8
8
|
import {
|
|
9
|
+
lazySchema as lazySchema2,
|
|
10
|
+
zodSchema as zodSchema2,
|
|
9
11
|
combineHeaders,
|
|
10
12
|
createBinaryResponseHandler,
|
|
11
13
|
parseProviderOptions,
|
|
@@ -15,83 +17,95 @@ import { z as z2 } from "zod/v4";
|
|
|
15
17
|
|
|
16
18
|
// src/hume-error.ts
|
|
17
19
|
import { z } from "zod/v4";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
import {
|
|
21
|
+
lazySchema,
|
|
22
|
+
zodSchema,
|
|
23
|
+
createJsonErrorResponseHandler
|
|
24
|
+
} from "@ai-sdk/provider-utils";
|
|
25
|
+
var humeErrorDataSchema = lazySchema(
|
|
26
|
+
() => zodSchema(
|
|
27
|
+
z.object({
|
|
28
|
+
error: z.object({
|
|
29
|
+
message: z.string(),
|
|
30
|
+
code: z.number()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
);
|
|
25
35
|
var humeFailedResponseHandler = createJsonErrorResponseHandler({
|
|
26
36
|
errorSchema: humeErrorDataSchema,
|
|
27
37
|
errorToMessage: (data) => data.error.message
|
|
28
38
|
});
|
|
29
39
|
|
|
30
40
|
// src/hume-speech-model.ts
|
|
31
|
-
var humeSpeechModelOptionsSchema =
|
|
32
|
-
|
|
33
|
-
* Context for the speech synthesis request.
|
|
34
|
-
* Can be either a generationId for retrieving a previous generation,
|
|
35
|
-
* or a list of utterances to synthesize.
|
|
36
|
-
*/
|
|
37
|
-
context: z2.object({
|
|
38
|
-
/**
|
|
39
|
-
* ID of a previously generated speech synthesis to retrieve.
|
|
40
|
-
*/
|
|
41
|
-
generationId: z2.string()
|
|
42
|
-
}).or(
|
|
41
|
+
var humeSpeechModelOptionsSchema = lazySchema2(
|
|
42
|
+
() => zodSchema2(
|
|
43
43
|
z2.object({
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Context for the speech synthesis request.
|
|
46
|
+
* Can be either a generationId for retrieving a previous generation,
|
|
47
|
+
* or a list of utterances to synthesize.
|
|
46
48
|
*/
|
|
47
|
-
|
|
49
|
+
context: z2.object({
|
|
50
|
+
/**
|
|
51
|
+
* ID of a previously generated speech synthesis to retrieve.
|
|
52
|
+
*/
|
|
53
|
+
generationId: z2.string()
|
|
54
|
+
}).or(
|
|
48
55
|
z2.object({
|
|
49
56
|
/**
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
text: z2.string(),
|
|
53
|
-
/**
|
|
54
|
-
* Optional description or instructions for how the text should be spoken.
|
|
55
|
-
*/
|
|
56
|
-
description: z2.string().optional(),
|
|
57
|
-
/**
|
|
58
|
-
* Optional speech rate multiplier.
|
|
59
|
-
*/
|
|
60
|
-
speed: z2.number().optional(),
|
|
61
|
-
/**
|
|
62
|
-
* Optional duration of silence to add after the utterance in seconds.
|
|
57
|
+
* List of utterances to synthesize into speech.
|
|
63
58
|
*/
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Voice configuration for the utterance.
|
|
67
|
-
* Can be specified by ID or name.
|
|
68
|
-
*/
|
|
69
|
-
voice: z2.object({
|
|
70
|
-
/**
|
|
71
|
-
* ID of the voice to use.
|
|
72
|
-
*/
|
|
73
|
-
id: z2.string(),
|
|
74
|
-
/**
|
|
75
|
-
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
76
|
-
*/
|
|
77
|
-
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
78
|
-
}).or(
|
|
59
|
+
utterances: z2.array(
|
|
79
60
|
z2.object({
|
|
80
61
|
/**
|
|
81
|
-
*
|
|
62
|
+
* The text content to convert to speech.
|
|
82
63
|
*/
|
|
83
|
-
|
|
64
|
+
text: z2.string(),
|
|
84
65
|
/**
|
|
85
|
-
*
|
|
66
|
+
* Optional description or instructions for how the text should be spoken.
|
|
86
67
|
*/
|
|
87
|
-
|
|
68
|
+
description: z2.string().optional(),
|
|
69
|
+
/**
|
|
70
|
+
* Optional speech rate multiplier.
|
|
71
|
+
*/
|
|
72
|
+
speed: z2.number().optional(),
|
|
73
|
+
/**
|
|
74
|
+
* Optional duration of silence to add after the utterance in seconds.
|
|
75
|
+
*/
|
|
76
|
+
trailingSilence: z2.number().optional(),
|
|
77
|
+
/**
|
|
78
|
+
* Voice configuration for the utterance.
|
|
79
|
+
* Can be specified by ID or name.
|
|
80
|
+
*/
|
|
81
|
+
voice: z2.object({
|
|
82
|
+
/**
|
|
83
|
+
* ID of the voice to use.
|
|
84
|
+
*/
|
|
85
|
+
id: z2.string(),
|
|
86
|
+
/**
|
|
87
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
88
|
+
*/
|
|
89
|
+
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
90
|
+
}).or(
|
|
91
|
+
z2.object({
|
|
92
|
+
/**
|
|
93
|
+
* Name of the voice to use.
|
|
94
|
+
*/
|
|
95
|
+
name: z2.string(),
|
|
96
|
+
/**
|
|
97
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
98
|
+
*/
|
|
99
|
+
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
100
|
+
})
|
|
101
|
+
).optional()
|
|
88
102
|
})
|
|
89
|
-
)
|
|
103
|
+
)
|
|
90
104
|
})
|
|
91
|
-
)
|
|
105
|
+
).nullish()
|
|
92
106
|
})
|
|
93
|
-
)
|
|
94
|
-
|
|
107
|
+
)
|
|
108
|
+
);
|
|
95
109
|
var HumeSpeechModel = class {
|
|
96
110
|
constructor(modelId, config) {
|
|
97
111
|
this.modelId = modelId;
|
|
@@ -216,7 +230,7 @@ var HumeSpeechModel = class {
|
|
|
216
230
|
};
|
|
217
231
|
|
|
218
232
|
// src/version.ts
|
|
219
|
-
var VERSION = true ? "2.0.
|
|
233
|
+
var VERSION = true ? "2.0.68" : "0.0.0-test";
|
|
220
234
|
|
|
221
235
|
// src/hume-provider.ts
|
|
222
236
|
function createHume(options = {}) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hume-provider.ts","../src/hume-speech-model.ts","../src/hume-error.ts","../src/version.ts"],"sourcesContent":["import type { SpeechModelV3, ProviderV3 } 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 Pick<ProviderV3, 'speechModel'> {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV3;\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 type { SpeechModelV3, SharedV3Warning } 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 type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport type { 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 SpeechModelV3 {\n readonly specificationVersion = 'v3';\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<SpeechModelV3['doGenerate']>[0]) {\n const warnings: SharedV3Warning[] = [];\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<SpeechModelV3['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV3['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":";AACA;AAAA,EACE;AA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W;AAAA,MAClC;AAAA,MACA,UAAU;AAAA,QACR,WAAW;AAAA,QACX,SAAS,KAAK;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;;;AE7OO,IAAM,UACX,OACI,WACA;;;AHoCC,SAAS,WAAW,UAAgC,CAAC,GAAiB;AAC3E,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,kBAAkB,WAAW;AAAA,QAC3B,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,GAAG,QAAQ;AAAA,IACb;AAAA,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,SAAS;AAClB,WAAS,cAAc;AAEvB,SAAO;AACT;AAKO,IAAM,OAAO,WAAW;","names":["z","z"]}
|
|
1
|
+
{"version":3,"sources":["../src/hume-provider.ts","../src/hume-speech-model.ts","../src/hume-error.ts","../src/version.ts"],"sourcesContent":["import type { SpeechModelV3, ProviderV3 } 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 Pick<ProviderV3, 'speechModel'> {\n (settings?: {}): {\n speech: HumeSpeechModel;\n };\n\n /**\n * Creates a model for speech synthesis.\n */\n speech(): SpeechModelV3;\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 type { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';\nimport {\n lazySchema,\n zodSchema,\n type InferSchema,\n combineHeaders,\n createBinaryResponseHandler,\n parseProviderOptions,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport type { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechModelOptionsSchema = lazySchema(() =>\n zodSchema(\n 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 ),\n);\n\nexport type HumeSpeechModelOptions = InferSchema<\n typeof humeSpeechModelOptionsSchema\n>;\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements SpeechModelV3 {\n readonly specificationVersion = 'v3';\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<SpeechModelV3['doGenerate']>[0]) {\n const warnings: SharedV3Warning[] = [];\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<SpeechModelV3['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<SpeechModelV3['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 {\n lazySchema,\n zodSchema,\n type InferSchema,\n createJsonErrorResponseHandler,\n} from '@ai-sdk/provider-utils';\n\nexport const humeErrorDataSchema = lazySchema(() =>\n zodSchema(\n z.object({\n error: z.object({\n message: z.string(),\n code: z.number(),\n }),\n }),\n ),\n);\n\nexport type HumeErrorData = InferSchema<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":";AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;;;ACJP;AAAA,EACE,cAAAA;AAAA,EACA,aAAAC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,KAAAC,UAAS;;;ACVlB,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAEA,IAAM,sBAAsB;AAAA,EAAW,MAC5C;AAAA,IACE,EAAE,OAAO;AAAA,MACP,OAAO,EAAE,OAAO;AAAA,QACd,SAAS,EAAE,OAAO;AAAA,QAClB,MAAM,EAAE,OAAO;AAAA,MACjB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAIO,IAAM,4BAA4B,+BAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ADRD,IAAM,+BAA+BC;AAAA,EAAW,MAC9CC;AAAA,IACEC,GAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMP,SAASA,GACN,OAAO;AAAA;AAAA;AAAA;AAAA,QAIN,cAAcA,GAAE,OAAO;AAAA,MACzB,CAAC,EACA;AAAA,QACCA,GAAE,OAAO;AAA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S;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":["lazySchema","zodSchema","z","lazySchema","zodSchema","z"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/hume",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.68",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@ai-sdk/provider": "3.0.19",
|
|
33
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
33
|
+
"@ai-sdk/provider-utils": "4.0.62"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "20.17.24",
|
package/src/hume-error.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
type InferSchema,
|
|
6
|
+
createJsonErrorResponseHandler,
|
|
7
|
+
} from '@ai-sdk/provider-utils';
|
|
3
8
|
|
|
4
|
-
export const humeErrorDataSchema =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
export const humeErrorDataSchema = lazySchema(() =>
|
|
10
|
+
zodSchema(
|
|
11
|
+
z.object({
|
|
12
|
+
error: z.object({
|
|
13
|
+
message: z.string(),
|
|
14
|
+
code: z.number(),
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
10
19
|
|
|
11
|
-
export type HumeErrorData =
|
|
20
|
+
export type HumeErrorData = InferSchema<typeof humeErrorDataSchema>;
|
|
12
21
|
|
|
13
22
|
export const humeFailedResponseHandler = createJsonErrorResponseHandler({
|
|
14
23
|
errorSchema: humeErrorDataSchema,
|
package/src/hume-speech-model.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
type InferSchema,
|
|
3
6
|
combineHeaders,
|
|
4
7
|
createBinaryResponseHandler,
|
|
5
8
|
parseProviderOptions,
|
|
@@ -11,78 +14,82 @@ import { humeFailedResponseHandler } from './hume-error';
|
|
|
11
14
|
import type { HumeSpeechAPITypes } from './hume-api-types';
|
|
12
15
|
|
|
13
16
|
// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file
|
|
14
|
-
const humeSpeechModelOptionsSchema =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Can be either a generationId for retrieving a previous generation,
|
|
18
|
-
* or a list of utterances to synthesize.
|
|
19
|
-
*/
|
|
20
|
-
context: z
|
|
21
|
-
.object({
|
|
17
|
+
const humeSpeechModelOptionsSchema = lazySchema(() =>
|
|
18
|
+
zodSchema(
|
|
19
|
+
z.object({
|
|
22
20
|
/**
|
|
23
|
-
*
|
|
21
|
+
* Context for the speech synthesis request.
|
|
22
|
+
* Can be either a generationId for retrieving a previous generation,
|
|
23
|
+
* or a list of utterances to synthesize.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
context: z
|
|
26
|
+
.object({
|
|
27
|
+
/**
|
|
28
|
+
* ID of a previously generated speech synthesis to retrieve.
|
|
29
|
+
*/
|
|
30
|
+
generationId: z.string(),
|
|
31
|
+
})
|
|
32
|
+
.or(
|
|
33
33
|
z.object({
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* List of utterances to synthesize into speech.
|
|
36
36
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Optional description or instructions for how the text should be spoken.
|
|
40
|
-
*/
|
|
41
|
-
description: z.string().optional(),
|
|
42
|
-
/**
|
|
43
|
-
* Optional speech rate multiplier.
|
|
44
|
-
*/
|
|
45
|
-
speed: z.number().optional(),
|
|
46
|
-
/**
|
|
47
|
-
* Optional duration of silence to add after the utterance in seconds.
|
|
48
|
-
*/
|
|
49
|
-
trailingSilence: z.number().optional(),
|
|
50
|
-
/**
|
|
51
|
-
* Voice configuration for the utterance.
|
|
52
|
-
* Can be specified by ID or name.
|
|
53
|
-
*/
|
|
54
|
-
voice: z
|
|
55
|
-
.object({
|
|
37
|
+
utterances: z.array(
|
|
38
|
+
z.object({
|
|
56
39
|
/**
|
|
57
|
-
*
|
|
40
|
+
* The text content to convert to speech.
|
|
58
41
|
*/
|
|
59
|
-
|
|
42
|
+
text: z.string(),
|
|
60
43
|
/**
|
|
61
|
-
*
|
|
44
|
+
* Optional description or instructions for how the text should be spoken.
|
|
62
45
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
46
|
+
description: z.string().optional(),
|
|
47
|
+
/**
|
|
48
|
+
* Optional speech rate multiplier.
|
|
49
|
+
*/
|
|
50
|
+
speed: z.number().optional(),
|
|
51
|
+
/**
|
|
52
|
+
* Optional duration of silence to add after the utterance in seconds.
|
|
53
|
+
*/
|
|
54
|
+
trailingSilence: z.number().optional(),
|
|
55
|
+
/**
|
|
56
|
+
* Voice configuration for the utterance.
|
|
57
|
+
* Can be specified by ID or name.
|
|
58
|
+
*/
|
|
59
|
+
voice: z
|
|
60
|
+
.object({
|
|
61
|
+
/**
|
|
62
|
+
* ID of the voice to use.
|
|
63
|
+
*/
|
|
64
|
+
id: z.string(),
|
|
65
|
+
/**
|
|
66
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
67
|
+
*/
|
|
68
|
+
provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
|
|
69
|
+
})
|
|
70
|
+
.or(
|
|
71
|
+
z.object({
|
|
72
|
+
/**
|
|
73
|
+
* Name of the voice to use.
|
|
74
|
+
*/
|
|
75
|
+
name: z.string(),
|
|
76
|
+
/**
|
|
77
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
78
|
+
*/
|
|
79
|
+
provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
.optional(),
|
|
83
|
+
}),
|
|
84
|
+
),
|
|
78
85
|
}),
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
)
|
|
87
|
+
.nullish(),
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
);
|
|
84
91
|
|
|
85
|
-
export type HumeSpeechModelOptions =
|
|
92
|
+
export type HumeSpeechModelOptions = InferSchema<
|
|
86
93
|
typeof humeSpeechModelOptionsSchema
|
|
87
94
|
>;
|
|
88
95
|
|