@ai-sdk/hume 2.0.18 → 2.0.19
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 +6 -0
- package/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/docs/150-hume.mdx +2 -1
- package/package.json +1 -1
- package/src/hume-speech-model.ts +5 -3
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
3
4
|
|
|
4
5
|
type HumeConfig = {
|
|
5
6
|
provider: string;
|
|
@@ -12,6 +13,32 @@ type HumeConfig = {
|
|
|
12
13
|
generateId?: () => string;
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
declare const humeSpeechModelOptionsSchema: z.ZodObject<{
|
|
17
|
+
context: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
|
|
18
|
+
generationId: z.ZodString;
|
|
19
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
20
|
+
utterances: z.ZodArray<z.ZodObject<{
|
|
21
|
+
text: z.ZodString;
|
|
22
|
+
description: z.ZodOptional<z.ZodString>;
|
|
23
|
+
speed: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
trailingSilence: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
voice: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
provider: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
HUME_AI: "HUME_AI";
|
|
29
|
+
CUSTOM_VOICE: "CUSTOM_VOICE";
|
|
30
|
+
}>>;
|
|
31
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
provider: z.ZodOptional<z.ZodEnum<{
|
|
34
|
+
HUME_AI: "HUME_AI";
|
|
35
|
+
CUSTOM_VOICE: "CUSTOM_VOICE";
|
|
36
|
+
}>>;
|
|
37
|
+
}, z.core.$strip>]>>;
|
|
38
|
+
}, z.core.$strip>>;
|
|
39
|
+
}, z.core.$strip>]>>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
|
|
15
42
|
interface HumeSpeechModelConfig extends HumeConfig {
|
|
16
43
|
_internal?: {
|
|
17
44
|
currentDate?: () => Date;
|
|
@@ -62,4 +89,4 @@ declare const hume: HumeProvider;
|
|
|
62
89
|
|
|
63
90
|
declare const VERSION: string;
|
|
64
91
|
|
|
65
|
-
export { type HumeProvider, type HumeProviderSettings, VERSION, createHume, hume };
|
|
92
|
+
export { type HumeProvider, type HumeProviderSettings, type HumeSpeechModelOptions, VERSION, createHume, hume };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
3
4
|
|
|
4
5
|
type HumeConfig = {
|
|
5
6
|
provider: string;
|
|
@@ -12,6 +13,32 @@ type HumeConfig = {
|
|
|
12
13
|
generateId?: () => string;
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
declare const humeSpeechModelOptionsSchema: z.ZodObject<{
|
|
17
|
+
context: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodObject<{
|
|
18
|
+
generationId: z.ZodString;
|
|
19
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
20
|
+
utterances: z.ZodArray<z.ZodObject<{
|
|
21
|
+
text: z.ZodString;
|
|
22
|
+
description: z.ZodOptional<z.ZodString>;
|
|
23
|
+
speed: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
trailingSilence: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
voice: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
provider: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
HUME_AI: "HUME_AI";
|
|
29
|
+
CUSTOM_VOICE: "CUSTOM_VOICE";
|
|
30
|
+
}>>;
|
|
31
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
provider: z.ZodOptional<z.ZodEnum<{
|
|
34
|
+
HUME_AI: "HUME_AI";
|
|
35
|
+
CUSTOM_VOICE: "CUSTOM_VOICE";
|
|
36
|
+
}>>;
|
|
37
|
+
}, z.core.$strip>]>>;
|
|
38
|
+
}, z.core.$strip>>;
|
|
39
|
+
}, z.core.$strip>]>>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
type HumeSpeechModelOptions = z.infer<typeof humeSpeechModelOptionsSchema>;
|
|
15
42
|
interface HumeSpeechModelConfig extends HumeConfig {
|
|
16
43
|
_internal?: {
|
|
17
44
|
currentDate?: () => Date;
|
|
@@ -62,4 +89,4 @@ declare const hume: HumeProvider;
|
|
|
62
89
|
|
|
63
90
|
declare const VERSION: string;
|
|
64
91
|
|
|
65
|
-
export { type HumeProvider, type HumeProviderSettings, VERSION, createHume, hume };
|
|
92
|
+
export { type HumeProvider, type HumeProviderSettings, type HumeSpeechModelOptions, VERSION, createHume, hume };
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ var humeFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespons
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
// src/hume-speech-model.ts
|
|
51
|
-
var
|
|
51
|
+
var humeSpeechModelOptionsSchema = import_v42.z.object({
|
|
52
52
|
/**
|
|
53
53
|
* Context for the speech synthesis request.
|
|
54
54
|
* Can be either a generationId for retrieving a previous generation,
|
|
@@ -134,7 +134,7 @@ var HumeSpeechModel = class {
|
|
|
134
134
|
const humeOptions = await (0, import_provider_utils2.parseProviderOptions)({
|
|
135
135
|
provider: "hume",
|
|
136
136
|
providerOptions,
|
|
137
|
-
schema:
|
|
137
|
+
schema: humeSpeechModelOptionsSchema
|
|
138
138
|
});
|
|
139
139
|
const requestBody = {
|
|
140
140
|
utterances: [
|
|
@@ -236,7 +236,7 @@ var HumeSpeechModel = class {
|
|
|
236
236
|
};
|
|
237
237
|
|
|
238
238
|
// src/version.ts
|
|
239
|
-
var VERSION = true ? "2.0.
|
|
239
|
+
var VERSION = true ? "2.0.19" : "0.0.0-test";
|
|
240
240
|
|
|
241
241
|
// src/hume-provider.ts
|
|
242
242
|
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 { VERSION } from './version';\n","import { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends Pick<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 { 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 { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechCallOptionsSchema = 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 HumeSpeechCallOptions = z.infer<typeof humeSpeechCallOptionsSchema>;\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: humeSpeechCallOptionsSchema,\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;AAAA;AAAA;;;ACCA,IAAAA,yBAIO;;;ACJP,IAAAC,yBAKO;AACP,IAAAC,aAAkB;;;ACPlB,gBAAkB;AAClB,4BAA+C;AAExC,IAAM,sBAAsB,YAAE,OAAO;AAAA,EAC1C,OAAO,YAAE,OAAO;AAAA,IACd,SAAS,YAAE,OAAO;AAAA,IAClB,MAAM,YAAE,OAAO;AAAA,EACjB,CAAC;AACH,CAAC;AAIM,IAAM,gCAA4B,sDAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ADFD,IAAM,8BAA8B,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3C,SAAS,aACN,OAAO;AAAA;AAAA;AAAA;AAAA,IAIN,cAAc,aAAE,OAAO;AAAA,EACzB,CAAC,EACA;AAAA,IACC,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA,MAIP,YAAY,aAAE;AAAA,QACZ,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA,UAIP,MAAM,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA,UAIf,aAAa,aAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,UAIjC,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA,UAI3B,iBAAiB,aAAE,OAAO,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,UAKrC,OAAO,aACJ,OAAO;AAAA;AAAA;AAAA;AAAA,YAIN,IAAI,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA,YAIb,UAAU,aAAE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B;AAAA,MACvB,+BAA2B,oDAA4B;AAAA,MACvD,aAAa,QAAQ;AAAA,MACrB,OAAO,KAAK,OAAO;AAAA,IACrB,CAAC;AAED,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,SAAS;AAAA,QACP,MAAM,KAAK,UAAU,WAAW;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;;;AE3OO,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 { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends Pick<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 { 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 { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechModelOptionsSchema = z.object({\n /**\n * Context for the speech synthesis request.\n * Can be either a generationId for retrieving a previous generation,\n * or a list of utterances to synthesize.\n */\n context: z\n .object({\n /**\n * ID of a previously generated speech synthesis to retrieve.\n */\n generationId: z.string(),\n })\n .or(\n z.object({\n /**\n * List of utterances to synthesize into speech.\n */\n utterances: z.array(\n z.object({\n /**\n * The text content to convert to speech.\n */\n text: z.string(),\n /**\n * Optional description or instructions for how the text should be spoken.\n */\n description: z.string().optional(),\n /**\n * Optional speech rate multiplier.\n */\n speed: z.number().optional(),\n /**\n * Optional duration of silence to add after the utterance in seconds.\n */\n trailingSilence: z.number().optional(),\n /**\n * Voice configuration for the utterance.\n * Can be specified by ID or name.\n */\n voice: z\n .object({\n /**\n * ID of the voice to use.\n */\n id: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n })\n .or(\n z.object({\n /**\n * Name of the voice to use.\n */\n name: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n }),\n )\n .optional(),\n }),\n ),\n }),\n )\n .nullish(),\n});\n\nexport type HumeSpeechModelOptions = z.infer<\n typeof humeSpeechModelOptionsSchema\n>;\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements 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;AAAA;AAAA;;;ACCA,IAAAA,yBAIO;;;ACJP,IAAAC,yBAKO;AACP,IAAAC,aAAkB;;;ACPlB,gBAAkB;AAClB,4BAA+C;AAExC,IAAM,sBAAsB,YAAE,OAAO;AAAA,EAC1C,OAAO,YAAE,OAAO;AAAA,IACd,SAAS,YAAE,OAAO;AAAA,IAClB,MAAM,YAAE,OAAO;AAAA,EACjB,CAAC;AACH,CAAC;AAIM,IAAM,gCAA4B,sDAA+B;AAAA,EACtE,aAAa;AAAA,EACb,gBAAgB,UAAQ,KAAK,MAAM;AACrC,CAAC;;;ADFD,IAAM,+BAA+B,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM5C,SAAS,aACN,OAAO;AAAA;AAAA;AAAA;AAAA,IAIN,cAAc,aAAE,OAAO;AAAA,EACzB,CA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AAA,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
|
@@ -28,7 +28,7 @@ var humeFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// src/hume-speech-model.ts
|
|
31
|
-
var
|
|
31
|
+
var humeSpeechModelOptionsSchema = z2.object({
|
|
32
32
|
/**
|
|
33
33
|
* Context for the speech synthesis request.
|
|
34
34
|
* Can be either a generationId for retrieving a previous generation,
|
|
@@ -114,7 +114,7 @@ var HumeSpeechModel = class {
|
|
|
114
114
|
const humeOptions = await parseProviderOptions({
|
|
115
115
|
provider: "hume",
|
|
116
116
|
providerOptions,
|
|
117
|
-
schema:
|
|
117
|
+
schema: humeSpeechModelOptionsSchema
|
|
118
118
|
});
|
|
119
119
|
const requestBody = {
|
|
120
120
|
utterances: [
|
|
@@ -216,7 +216,7 @@ var HumeSpeechModel = class {
|
|
|
216
216
|
};
|
|
217
217
|
|
|
218
218
|
// src/version.ts
|
|
219
|
-
var VERSION = true ? "2.0.
|
|
219
|
+
var VERSION = true ? "2.0.19" : "0.0.0-test";
|
|
220
220
|
|
|
221
221
|
// src/hume-provider.ts
|
|
222
222
|
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 { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends Pick<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 { 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 { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechCallOptionsSchema = 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 HumeSpeechCallOptions = z.infer<typeof humeSpeechCallOptionsSchema>;\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: humeSpeechCallOptionsSchema,\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,EAEE;AAAA,EACA;AAAA,OACK;;;ACJP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,KAAAA,UAAS;;;ACPlB,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;;;ADFD,IAAM,8BAA8BC,GAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3C,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;AAA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Q,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 { SpeechModelV3, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { HumeSpeechModel } from './hume-speech-model';\nimport { VERSION } from './version';\n\nexport interface HumeProvider extends Pick<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 { 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 { HumeConfig } from './hume-config';\nimport { humeFailedResponseHandler } from './hume-error';\nimport { HumeSpeechAPITypes } from './hume-api-types';\n\n// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file\nconst humeSpeechModelOptionsSchema = z.object({\n /**\n * Context for the speech synthesis request.\n * Can be either a generationId for retrieving a previous generation,\n * or a list of utterances to synthesize.\n */\n context: z\n .object({\n /**\n * ID of a previously generated speech synthesis to retrieve.\n */\n generationId: z.string(),\n })\n .or(\n z.object({\n /**\n * List of utterances to synthesize into speech.\n */\n utterances: z.array(\n z.object({\n /**\n * The text content to convert to speech.\n */\n text: z.string(),\n /**\n * Optional description or instructions for how the text should be spoken.\n */\n description: z.string().optional(),\n /**\n * Optional speech rate multiplier.\n */\n speed: z.number().optional(),\n /**\n * Optional duration of silence to add after the utterance in seconds.\n */\n trailingSilence: z.number().optional(),\n /**\n * Voice configuration for the utterance.\n * Can be specified by ID or name.\n */\n voice: z\n .object({\n /**\n * ID of the voice to use.\n */\n id: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n })\n .or(\n z.object({\n /**\n * Name of the voice to use.\n */\n name: z.string(),\n /**\n * Provider of the voice, either Hume's built-in voices or a custom voice.\n */\n provider: z.enum(['HUME_AI', 'CUSTOM_VOICE']).optional(),\n }),\n )\n .optional(),\n }),\n ),\n }),\n )\n .nullish(),\n});\n\nexport type HumeSpeechModelOptions = z.infer<\n typeof humeSpeechModelOptionsSchema\n>;\n\ninterface HumeSpeechModelConfig extends HumeConfig {\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class HumeSpeechModel implements 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,EAEE;AAAA,EACA;AAAA,OACK;;;ACJP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,KAAAA,UAAS;;;ACPlB,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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ChB,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"]}
|
package/docs/150-hume.mdx
CHANGED
|
@@ -125,6 +125,7 @@ You can pass additional provider-specific options using the `providerOptions` ar
|
|
|
125
125
|
```ts
|
|
126
126
|
import { experimental_generateSpeech as generateSpeech } from 'ai';
|
|
127
127
|
import { hume } from '@ai-sdk/hume';
|
|
128
|
+
import { type HumeSpeechModelOptions } from '@ai-sdk/hume';
|
|
128
129
|
|
|
129
130
|
const result = await generateSpeech({
|
|
130
131
|
model: hume.speech(),
|
|
@@ -134,7 +135,7 @@ const result = await generateSpeech({
|
|
|
134
135
|
context: {
|
|
135
136
|
generationId: 'previous-generation-id',
|
|
136
137
|
},
|
|
137
|
-
},
|
|
138
|
+
} satisfies HumeSpeechModelOptions,
|
|
138
139
|
},
|
|
139
140
|
});
|
|
140
141
|
```
|
package/package.json
CHANGED
package/src/hume-speech-model.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { humeFailedResponseHandler } from './hume-error';
|
|
|
11
11
|
import { HumeSpeechAPITypes } from './hume-api-types';
|
|
12
12
|
|
|
13
13
|
// https://dev.hume.ai/reference/text-to-speech-tts/synthesize-file
|
|
14
|
-
const
|
|
14
|
+
const humeSpeechModelOptionsSchema = z.object({
|
|
15
15
|
/**
|
|
16
16
|
* Context for the speech synthesis request.
|
|
17
17
|
* Can be either a generationId for retrieving a previous generation,
|
|
@@ -82,7 +82,9 @@ const humeSpeechCallOptionsSchema = z.object({
|
|
|
82
82
|
.nullish(),
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
export type
|
|
85
|
+
export type HumeSpeechModelOptions = z.infer<
|
|
86
|
+
typeof humeSpeechModelOptionsSchema
|
|
87
|
+
>;
|
|
86
88
|
|
|
87
89
|
interface HumeSpeechModelConfig extends HumeConfig {
|
|
88
90
|
_internal?: {
|
|
@@ -117,7 +119,7 @@ export class HumeSpeechModel implements SpeechModelV3 {
|
|
|
117
119
|
const humeOptions = await parseProviderOptions({
|
|
118
120
|
provider: 'hume',
|
|
119
121
|
providerOptions,
|
|
120
|
-
schema:
|
|
122
|
+
schema: humeSpeechModelOptionsSchema,
|
|
121
123
|
});
|
|
122
124
|
|
|
123
125
|
// Create request body
|
package/src/index.ts
CHANGED