@ai-sdk/hume 3.0.51 → 3.0.52
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 +9 -0
- package/dist/index.d.ts +87 -83
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +229 -287
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/hume
|
|
2
2
|
|
|
3
|
+
## 3.0.52
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ede5b89: chore: migrate package builds from tsup to tsdown
|
|
8
|
+
- Updated dependencies [ede5b89]
|
|
9
|
+
- @ai-sdk/provider@4.0.20
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.52
|
|
11
|
+
|
|
3
12
|
## 3.0.51
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,102 +1,106 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ProviderV4, SpeechModelV4 } from "@ai-sdk/provider";
|
|
2
|
+
import { FetchFunction, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
//#region src/hume-config.d.ts
|
|
6
5
|
type HumeConfig = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
provider: string;
|
|
7
|
+
url: (options: {
|
|
8
|
+
modelId: string;
|
|
9
|
+
path: string;
|
|
10
|
+
}) => string;
|
|
11
|
+
headers?: () => Record<string, string | undefined>;
|
|
12
|
+
fetch?: FetchFunction;
|
|
13
|
+
generateId?: () => string;
|
|
15
14
|
};
|
|
16
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/hume-speech-model.d.ts
|
|
17
17
|
interface HumeSpeechModelConfig extends HumeConfig {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
_internal?: {
|
|
19
|
+
currentDate?: () => Date;
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
declare class HumeSpeechModel implements SpeechModelV4 {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
readonly modelId: '';
|
|
24
|
+
private readonly config;
|
|
25
|
+
readonly specificationVersion = "v4";
|
|
26
|
+
get provider(): string;
|
|
27
|
+
static [WORKFLOW_SERIALIZE](model: HumeSpeechModel): {
|
|
28
|
+
modelId: string;
|
|
29
|
+
config: import("@ai-sdk/provider").JSONObject;
|
|
30
|
+
};
|
|
31
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
32
|
+
modelId: '';
|
|
33
|
+
config: HumeSpeechModelConfig;
|
|
34
|
+
}): HumeSpeechModel;
|
|
35
|
+
constructor(modelId: '', config: HumeSpeechModelConfig);
|
|
36
|
+
private getArgs;
|
|
37
|
+
doGenerate(options: Parameters<SpeechModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>>;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/hume-provider.d.ts
|
|
40
41
|
interface HumeProvider extends ProviderV4 {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
(settings?: {}): {
|
|
43
|
+
speech: HumeSpeechModel;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Creates a model for speech synthesis.
|
|
47
|
+
*/
|
|
48
|
+
speech(): SpeechModelV4;
|
|
48
49
|
}
|
|
49
50
|
interface HumeProviderSettings {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
/**
|
|
52
|
+
* API key for authenticating requests.
|
|
53
|
+
*/
|
|
54
|
+
apiKey?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Custom headers to include in the requests.
|
|
57
|
+
*/
|
|
58
|
+
headers?: Record<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
61
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
62
|
+
*/
|
|
63
|
+
fetch?: FetchFunction;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Create an Hume provider instance.
|
|
66
67
|
*/
|
|
67
|
-
declare function createHume(options?: HumeProviderSettings): HumeProvider;
|
|
68
|
+
export declare function createHume(options?: HumeProviderSettings): HumeProvider;
|
|
68
69
|
/**
|
|
69
70
|
* Default Hume provider instance.
|
|
70
71
|
*/
|
|
71
|
-
declare const hume: HumeProvider;
|
|
72
|
-
|
|
72
|
+
export declare const hume: HumeProvider;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/hume-speech-model-options.d.ts
|
|
73
75
|
declare const humeSpeechModelOptionsSchema: z.ZodObject<{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
76
|
+
context: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
|
|
77
|
+
generationId: z.ZodString;
|
|
78
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
79
|
+
utterances: z.ZodArray<z.ZodObject<{
|
|
80
|
+
text: z.ZodString;
|
|
81
|
+
description: z.ZodOptional<z.ZodString>;
|
|
82
|
+
speed: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
trailingSilence: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
voice: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
85
|
+
id: z.ZodString;
|
|
86
|
+
provider: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
HUME_AI: "HUME_AI";
|
|
88
|
+
CUSTOM_VOICE: "CUSTOM_VOICE";
|
|
89
|
+
}>>;
|
|
90
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
91
|
+
name: z.ZodString;
|
|
92
|
+
provider: z.ZodOptional<z.ZodEnum<{
|
|
93
|
+
HUME_AI: "HUME_AI";
|
|
94
|
+
CUSTOM_VOICE: "CUSTOM_VOICE";
|
|
95
|
+
}>>;
|
|
96
|
+
}, z.core.$strip>]>>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
}, z.core.$strip>]>>>;
|
|
97
99
|
}, z.core.$strip>;
|
|
98
100
|
type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/version.d.ts
|
|
103
|
+
export declare const VERSION: string;
|
|
104
|
+
//#endregion
|
|
105
|
+
export type { HumeProvider, HumeProviderSettings, HumeSpeechModelOptions };
|
|
106
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/hume-config.ts","../src/hume-speech-model.ts","../src/hume-provider.ts","../src/hume-speech-model-options.ts","../src/version.ts"],"mappings":";;;;KAEY;EACV;EACA,MAAM;IAAW;IAAiB;;EAClC,gBAAgB;EAChB,QAAQ;EACR;;;;UCQQ,8BAA8B;EACtC;IACE,oBAAoB;;;cAIX,2BAA2B;WAsB3B;mBACQ;WAtBV;MAEL;UAII,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B;IACA,QAAQ;MACT;EAKU,YAAA,aACQ,QAAQ;UAGb;EAgGR,WACJ,SAAS,WAAW,kCACnB,QAAQ,QAAQ,WAAW;;;;UCpIf,qBAAqB;GACnC;IACC,QAAQ;;;;;EAMV,UAAU;;UAGK;;;;EAIf;;;;EAKA,UAAU;;;;;EAMV,QAAQ;;;;;wBAMM,WAAW,UAAS,uBAA4B;;;;qBA8DnD,MAAI;;;cCxGJ,8BAA4B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;GAqEvC,EAAA,KAAA;KAEU,yBAAyB,EAAE,aAC9B;;;qBCzEI"}
|
package/dist/index.js
CHANGED
|
@@ -1,293 +1,235 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
NoSuchModelError
|
|
4
|
-
} from "@ai-sdk/provider";
|
|
5
|
-
import {
|
|
6
|
-
loadApiKey,
|
|
7
|
-
withUserAgentSuffix
|
|
8
|
-
} from "@ai-sdk/provider-utils";
|
|
9
|
-
|
|
10
|
-
// src/hume-speech-model.ts
|
|
11
|
-
import {
|
|
12
|
-
combineHeaders,
|
|
13
|
-
createBinaryResponseHandler,
|
|
14
|
-
parseProviderOptions,
|
|
15
|
-
postJsonToApi,
|
|
16
|
-
serializeModelOptions,
|
|
17
|
-
WORKFLOW_SERIALIZE,
|
|
18
|
-
WORKFLOW_DESERIALIZE
|
|
19
|
-
} from "@ai-sdk/provider-utils";
|
|
20
|
-
|
|
21
|
-
// src/hume-error.ts
|
|
1
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, createBinaryResponseHandler, createJsonErrorResponseHandler, loadApiKey, parseProviderOptions, postJsonToApi, serializeModelOptions, withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
22
3
|
import { z } from "zod/v4";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
errorSchema: humeErrorDataSchema,
|
|
32
|
-
errorToMessage: (data) => data.error.message
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// src/hume-speech-model-options.ts
|
|
36
|
-
import { z as z2 } from "zod/v4";
|
|
37
|
-
var humeSpeechModelOptionsSchema = z2.object({
|
|
38
|
-
/**
|
|
39
|
-
* Context for the speech synthesis request.
|
|
40
|
-
* Can be either a generationId for retrieving a previous generation,
|
|
41
|
-
* or a list of utterances to synthesize.
|
|
42
|
-
*/
|
|
43
|
-
context: z2.object({
|
|
44
|
-
/**
|
|
45
|
-
* ID of a previously generated speech synthesis to retrieve.
|
|
46
|
-
*/
|
|
47
|
-
generationId: z2.string()
|
|
48
|
-
}).or(
|
|
49
|
-
z2.object({
|
|
50
|
-
/**
|
|
51
|
-
* List of utterances to synthesize into speech.
|
|
52
|
-
*/
|
|
53
|
-
utterances: z2.array(
|
|
54
|
-
z2.object({
|
|
55
|
-
/**
|
|
56
|
-
* The text content to convert to speech.
|
|
57
|
-
*/
|
|
58
|
-
text: z2.string(),
|
|
59
|
-
/**
|
|
60
|
-
* Optional description or instructions for how the text should be spoken.
|
|
61
|
-
*/
|
|
62
|
-
description: z2.string().optional(),
|
|
63
|
-
/**
|
|
64
|
-
* Optional speech rate multiplier.
|
|
65
|
-
*/
|
|
66
|
-
speed: z2.number().optional(),
|
|
67
|
-
/**
|
|
68
|
-
* Optional duration of silence to add after the utterance in seconds.
|
|
69
|
-
*/
|
|
70
|
-
trailingSilence: z2.number().optional(),
|
|
71
|
-
/**
|
|
72
|
-
* Voice configuration for the utterance.
|
|
73
|
-
* Can be specified by ID or name.
|
|
74
|
-
*/
|
|
75
|
-
voice: z2.object({
|
|
76
|
-
/**
|
|
77
|
-
* ID of the voice to use.
|
|
78
|
-
*/
|
|
79
|
-
id: z2.string(),
|
|
80
|
-
/**
|
|
81
|
-
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
82
|
-
*/
|
|
83
|
-
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
84
|
-
}).or(
|
|
85
|
-
z2.object({
|
|
86
|
-
/**
|
|
87
|
-
* Name of the voice to use.
|
|
88
|
-
*/
|
|
89
|
-
name: z2.string(),
|
|
90
|
-
/**
|
|
91
|
-
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
92
|
-
*/
|
|
93
|
-
provider: z2.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
94
|
-
})
|
|
95
|
-
).optional()
|
|
96
|
-
})
|
|
97
|
-
)
|
|
98
|
-
})
|
|
99
|
-
).nullish()
|
|
4
|
+
//#region src/hume-error.ts
|
|
5
|
+
const humeErrorDataSchema = z.object({ error: z.object({
|
|
6
|
+
message: z.string(),
|
|
7
|
+
code: z.number()
|
|
8
|
+
}) });
|
|
9
|
+
const humeFailedResponseHandler = createJsonErrorResponseHandler({
|
|
10
|
+
errorSchema: humeErrorDataSchema,
|
|
11
|
+
errorToMessage: (data) => data.error.message
|
|
100
12
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/hume-speech-model-options.ts
|
|
15
|
+
const humeSpeechModelOptionsSchema = z.object({
|
|
16
|
+
/**
|
|
17
|
+
* Context for the speech synthesis request.
|
|
18
|
+
* Can be either a generationId for retrieving a previous generation,
|
|
19
|
+
* or a list of utterances to synthesize.
|
|
20
|
+
*/
|
|
21
|
+
context: z.object({
|
|
22
|
+
/**
|
|
23
|
+
* ID of a previously generated speech synthesis to retrieve.
|
|
24
|
+
*/
|
|
25
|
+
generationId: z.string() }).or(z.object({
|
|
26
|
+
/**
|
|
27
|
+
* List of utterances to synthesize into speech.
|
|
28
|
+
*/
|
|
29
|
+
utterances: z.array(z.object({
|
|
30
|
+
/**
|
|
31
|
+
* The text content to convert to speech.
|
|
32
|
+
*/
|
|
33
|
+
text: z.string(),
|
|
34
|
+
/**
|
|
35
|
+
* Optional description or instructions for how the text should be spoken.
|
|
36
|
+
*/
|
|
37
|
+
description: z.string().optional(),
|
|
38
|
+
/**
|
|
39
|
+
* Optional speech rate multiplier.
|
|
40
|
+
*/
|
|
41
|
+
speed: z.number().optional(),
|
|
42
|
+
/**
|
|
43
|
+
* Optional duration of silence to add after the utterance in seconds.
|
|
44
|
+
*/
|
|
45
|
+
trailingSilence: z.number().optional(),
|
|
46
|
+
/**
|
|
47
|
+
* Voice configuration for the utterance.
|
|
48
|
+
* Can be specified by ID or name.
|
|
49
|
+
*/
|
|
50
|
+
voice: z.object({
|
|
51
|
+
/**
|
|
52
|
+
* ID of the voice to use.
|
|
53
|
+
*/
|
|
54
|
+
id: z.string(),
|
|
55
|
+
/**
|
|
56
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
57
|
+
*/
|
|
58
|
+
provider: z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
59
|
+
}).or(z.object({
|
|
60
|
+
/**
|
|
61
|
+
* Name of the voice to use.
|
|
62
|
+
*/
|
|
63
|
+
name: z.string(),
|
|
64
|
+
/**
|
|
65
|
+
* Provider of the voice, either Hume's built-in voices or a custom voice.
|
|
66
|
+
*/
|
|
67
|
+
provider: z.enum(["HUME_AI", "CUSTOM_VOICE"]).optional()
|
|
68
|
+
})).optional()
|
|
69
|
+
})) })).nullish() });
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/hume-speech-model.ts
|
|
72
|
+
var HumeSpeechModel = class HumeSpeechModel {
|
|
73
|
+
get provider() {
|
|
74
|
+
return this.config.provider;
|
|
75
|
+
}
|
|
76
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
77
|
+
return serializeModelOptions({
|
|
78
|
+
modelId: model.modelId,
|
|
79
|
+
config: model.config
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
83
|
+
return new HumeSpeechModel(options.modelId, options.config);
|
|
84
|
+
}
|
|
85
|
+
constructor(modelId, config) {
|
|
86
|
+
this.modelId = modelId;
|
|
87
|
+
this.config = config;
|
|
88
|
+
this.specificationVersion = "v4";
|
|
89
|
+
}
|
|
90
|
+
async getArgs({ text, voice = "d8ab67c6-953d-4bd8-9370-8fa53a0f1453", outputFormat = "mp3", speed, instructions, language, providerOptions }) {
|
|
91
|
+
const warnings = [];
|
|
92
|
+
const humeOptions = await parseProviderOptions({
|
|
93
|
+
provider: "hume",
|
|
94
|
+
providerOptions,
|
|
95
|
+
schema: humeSpeechModelOptionsSchema
|
|
96
|
+
});
|
|
97
|
+
const requestBody = {
|
|
98
|
+
utterances: [{
|
|
99
|
+
text,
|
|
100
|
+
speed,
|
|
101
|
+
description: instructions,
|
|
102
|
+
voice: {
|
|
103
|
+
id: voice,
|
|
104
|
+
provider: "HUME_AI"
|
|
105
|
+
}
|
|
106
|
+
}],
|
|
107
|
+
format: { type: "mp3" }
|
|
108
|
+
};
|
|
109
|
+
if (outputFormat) {
|
|
110
|
+
if ([
|
|
111
|
+
"mp3",
|
|
112
|
+
"pcm",
|
|
113
|
+
"wav"
|
|
114
|
+
].includes(outputFormat)) requestBody.format = { type: outputFormat };
|
|
115
|
+
else warnings.push({
|
|
116
|
+
type: "unsupported",
|
|
117
|
+
feature: "outputFormat",
|
|
118
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (humeOptions) {
|
|
122
|
+
const speechModelOptions = {};
|
|
123
|
+
if (humeOptions.context) {
|
|
124
|
+
if ("generationId" in humeOptions.context) speechModelOptions.context = { generation_id: humeOptions.context.generationId };
|
|
125
|
+
else speechModelOptions.context = { utterances: humeOptions.context.utterances.map((utterance) => ({
|
|
126
|
+
text: utterance.text,
|
|
127
|
+
description: utterance.description,
|
|
128
|
+
speed: utterance.speed,
|
|
129
|
+
trailing_silence: utterance.trailingSilence,
|
|
130
|
+
voice: utterance.voice
|
|
131
|
+
})) };
|
|
132
|
+
}
|
|
133
|
+
for (const key in speechModelOptions) {
|
|
134
|
+
const value = speechModelOptions[key];
|
|
135
|
+
if (value !== void 0) requestBody[key] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (language) warnings.push({
|
|
139
|
+
type: "unsupported",
|
|
140
|
+
feature: "language",
|
|
141
|
+
details: `Hume speech models do not support language selection. Language parameter "${language}" was ignored.`
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
requestBody,
|
|
145
|
+
warnings
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async doGenerate(options) {
|
|
149
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
150
|
+
const { requestBody, warnings } = await this.getArgs(options);
|
|
151
|
+
const { value: audio, responseHeaders, rawValue: rawResponse } = await postJsonToApi({
|
|
152
|
+
url: this.config.url({
|
|
153
|
+
path: "/v0/tts/file",
|
|
154
|
+
modelId: this.modelId
|
|
155
|
+
}),
|
|
156
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
157
|
+
body: requestBody,
|
|
158
|
+
failedResponseHandler: humeFailedResponseHandler,
|
|
159
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
160
|
+
abortSignal: options.abortSignal,
|
|
161
|
+
fetch: this.config.fetch
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
audio,
|
|
165
|
+
warnings,
|
|
166
|
+
request: { body: JSON.stringify(requestBody) },
|
|
167
|
+
response: {
|
|
168
|
+
timestamp: currentDate,
|
|
169
|
+
modelId: this.modelId,
|
|
170
|
+
headers: responseHeaders,
|
|
171
|
+
body: rawResponse
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
232
175
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/version.ts
|
|
178
|
+
const VERSION = "3.0.52";
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/hume-provider.ts
|
|
181
|
+
/**
|
|
182
|
+
* Create an Hume provider instance.
|
|
183
|
+
*/
|
|
238
184
|
function createHume(options = {}) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
modelType: "imageModel",
|
|
282
|
-
message: "Hume does not provide image models"
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
return provider;
|
|
185
|
+
const getHeaders = () => withUserAgentSuffix({
|
|
186
|
+
"X-Hume-Api-Key": loadApiKey({
|
|
187
|
+
apiKey: options.apiKey,
|
|
188
|
+
environmentVariableName: "HUME_API_KEY",
|
|
189
|
+
description: "Hume"
|
|
190
|
+
}),
|
|
191
|
+
...options.headers
|
|
192
|
+
}, `ai-sdk-hume/${VERSION}`);
|
|
193
|
+
const createSpeechModel = () => new HumeSpeechModel("", {
|
|
194
|
+
provider: `hume.speech`,
|
|
195
|
+
url: ({ path }) => `https://api.hume.ai${path}`,
|
|
196
|
+
headers: getHeaders,
|
|
197
|
+
fetch: options.fetch
|
|
198
|
+
});
|
|
199
|
+
const provider = function() {
|
|
200
|
+
return { speech: createSpeechModel() };
|
|
201
|
+
};
|
|
202
|
+
provider.specificationVersion = "v4";
|
|
203
|
+
provider.speech = createSpeechModel;
|
|
204
|
+
provider.speechModel = createSpeechModel;
|
|
205
|
+
provider.languageModel = (modelId) => {
|
|
206
|
+
throw new NoSuchModelError({
|
|
207
|
+
modelId,
|
|
208
|
+
modelType: "languageModel",
|
|
209
|
+
message: "Hume does not provide language models"
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
provider.embeddingModel = (modelId) => {
|
|
213
|
+
throw new NoSuchModelError({
|
|
214
|
+
modelId,
|
|
215
|
+
modelType: "embeddingModel",
|
|
216
|
+
message: "Hume does not provide embedding models"
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
provider.imageModel = (modelId) => {
|
|
220
|
+
throw new NoSuchModelError({
|
|
221
|
+
modelId,
|
|
222
|
+
modelType: "imageModel",
|
|
223
|
+
message: "Hume does not provide image models"
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
return provider;
|
|
286
227
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
};
|
|
228
|
+
/**
|
|
229
|
+
* Default Hume provider instance.
|
|
230
|
+
*/
|
|
231
|
+
const hume = createHume();
|
|
232
|
+
//#endregion
|
|
233
|
+
export { VERSION, createHume, hume };
|
|
234
|
+
|
|
293
235
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAAA;AAAA;AAAA,UAIP,MAAMA,GAAE,OAAO;AAAA;AAAA;AAAA;AAAA,UAIf,aAAaA,GAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,UAIjC,OAAOA,GAAE,OAA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,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"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/hume-error.ts","../src/hume-speech-model-options.ts","../src/hume-speech-model.ts","../src/version.ts","../src/hume-provider.ts"],"sourcesContent":["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","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","// 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","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"],"mappings":";;;;AAGA,MAAa,sBAAsB,EAAE,OAAO,EAC1C,OAAO,EAAE,OAAO;CACd,SAAS,EAAE,OAAO;CAClB,MAAM,EAAE,OAAO;AACjB,CAAC,EACH,CAAC;AAID,MAAa,4BAA4B,+BAA+B;CACtE,aAAa;CACb,iBAAgB,SAAQ,KAAK,MAAM;AACrC,CAAC;;;ACZD,MAAa,+BAA+B,EAAE,OAAO;;;;;;AAMnD,SAAS,EACN,OAAO;;;;AAIN,cAAc,EAAE,OAAO,EACzB,CAAC,CAAC,CACD,GACC,EAAE,OAAO;;;;AAIP,YAAY,EAAE,MACZ,EAAE,OAAO;;;;CAIP,MAAM,EAAE,OAAO;;;;CAIf,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,SAAS,KAAK;IACd,SAAS;IACT,MAAM;GACR;EACF;CACF;AACF;;;AClLA,MAAa,UAAA;;;;;;AC2Cb,SAAgB,WAAW,UAAgC,CAAC,GAAiB;CAC3E,MAAM,mBACJ,oBACE;EACE,kBAAkB,WAAW;GAC3B,QAAQ,QAAQ;GAChB,yBAAyB;GACzB,aAAa;EACf,CAAC;EACD,GAAG,QAAQ;CACb,GACA,eAAe,SACjB;CAEF,MAAM,0BACJ,IAAI,gBAAgB,IAAI;EACtB,UAAU;EACV,MAAM,EAAE,WAAW,sBAAsB;EACzC,SAAS;EACT,OAAO,QAAQ;CACjB,CAAC;CAEH,MAAM,WAAW,WAAY;EAC3B,OAAO,EACL,QAAQ,kBAAkB,EAC5B;CACF;CAEA,SAAS,uBAAuB;CAChC,SAAS,SAAS;CAClB,SAAS,cAAc;CAEvB,SAAS,iBAAiB,YAAoB;EAC5C,MAAM,IAAI,iBAAiB;GACzB;GACA,WAAW;GACX,SAAS;EACX,CAAC;CACH;CAEA,SAAS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GACzB;GACA,WAAW;GACX,SAAS;EACX,CAAC;CACH;CAEA,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GACzB;GACA,WAAW;GACX,SAAS;EACX,CAAC;CACH;CAEA,OAAO;AACT;;;;AAKA,MAAa,OAAO,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/hume",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider": "4.0.
|
|
33
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
32
|
+
"@ai-sdk/provider": "4.0.20",
|
|
33
|
+
"@ai-sdk/provider-utils": "5.0.52"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@ai-sdk/test-server": "2.0.
|
|
36
|
+
"@ai-sdk/test-server": "2.0.3",
|
|
37
37
|
"@types/node": "22.19.19",
|
|
38
38
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
39
|
-
"
|
|
39
|
+
"tsdown": "^0.23.0",
|
|
40
40
|
"typescript": "5.6.3",
|
|
41
41
|
"zod": "3.25.76"
|
|
42
42
|
},
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"ai"
|
|
64
64
|
],
|
|
65
65
|
"scripts": {
|
|
66
|
-
"build": "
|
|
67
|
-
"build:watch": "
|
|
68
|
-
"clean": "del-cli
|
|
66
|
+
"build": "tsdown",
|
|
67
|
+
"build:watch": "tsdown --watch",
|
|
68
|
+
"clean": "del-cli docs",
|
|
69
69
|
"type-check": "tsc --noEmit",
|
|
70
70
|
"test": "pnpm test:node && pnpm test:edge",
|
|
71
71
|
"test:watch": "vitest --config vitest.node.config.js --watch",
|