本页还没有译文
本页 31 段还没译成Español,下面显示的是英文原文。Hume
还没翻译译自英文(ai-sdk.dev)本页 31 段都还没译
The Hume provider contains support for the Hume text-to-speech (TTS) API.
Hume models are not currently available through AI Gateway, so the opening example uses @ai-sdk/hume directly. See Using AI Gateway below for supported alternatives.
import { generateSpeech } from 'ai';
import { hume } from '@ai-sdk/hume';
import { writeFile } from 'node:fs/promises';
const { audio } = await generateSpeech({
model: hume.speech(),
text: 'Hello, world!',
outputFormat: 'mp3',
});
await writeFile('speech.mp3', audio.uint8Array);Using AI Gateway
The current AI Gateway model catalog does not list Hume models. Use @ai-sdk/hume for the APIs on this page. To use other speech models through Gateway, install ai and configure a Gateway API key:
pnpm add ainpm install aiyarn add aibun add aiSet an AI Gateway API key in your environment:
export AI_GATEWAY_API_KEY=your_api_key_hereVercel deployments can also use OIDC authentication. See the Gateway documentation for supported models and APIs.
Using @ai-sdk/hume
For direct access to Hume, install ai and @ai-sdk/hume:
pnpm add ai @ai-sdk/humenpm install ai @ai-sdk/humeyarn add ai @ai-sdk/humebun add ai @ai-sdk/humeSet your Hume API credential in the HUME_API_KEY environment variable:
export HUME_API_KEY=your_api_key_hereNote
The following sections document the direct @ai-sdk/hume provider, including
its model factories and settings. Gateway model and feature availability can
differ.
Provider Instance
You can import the default provider instance hume from @ai-sdk/hume:
import { hume } from '@ai-sdk/hume';If you need a customized setup, you can import createHume from @ai-sdk/hume and create a provider instance with your settings:
import { createHume } from '@ai-sdk/hume';
const hume = createHume({
// custom settings, e.g.
fetch: customFetch,
});You can use the following optional settings to customize the Hume provider instance:
-
apiKey string
API key that is being sent using the
X-Hume-Api-Keyheader. It defaults to theHUME_API_KEYenvironment variable. -
headers Record<string,string>
Custom headers to include in the requests.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation. Defaults to the global
fetchfunction. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing.
Speech Models
You can create models that call the Hume speech API
using the .speech() factory method.
const model = hume.speech();You can pass standard speech generation options like voice, speed, instructions, and outputFormat:
import { generateSpeech } from 'ai';
import { hume } from '@ai-sdk/hume';
const result = await generateSpeech({
model: hume.speech(),
text: 'Hello, world!',
voice: 'd8ab67c6-953d-4bd8-9370-8fa53a0f1453',
speed: 1.0,
instructions: 'Speak in a friendly, conversational tone.',
outputFormat: 'mp3',
});Supported Parameters
-
text string (required)
The text to convert to speech.
-
voice string
The voice ID to use for the generated audio. Defaults to
'd8ab67c6-953d-4bd8-9370-8fa53a0f1453'. -
speed number
Speech rate multiplier.
-
instructions string
Description or instructions for how the text should be spoken.
-
outputFormat string
The audio format to generate. Supported values:
'mp3','pcm','wav'. Defaults to'mp3'.
Note
The language parameter is not supported by Hume speech models and will be
ignored with a warning.
Provider Options
You can pass additional provider-specific options using the providerOptions argument:
import { generateSpeech } from 'ai';
import { hume } from '@ai-sdk/hume';
import { type HumeSpeechModelOptions } from '@ai-sdk/hume';
const result = await generateSpeech({
model: hume.speech(),
text: 'Hello, world!',
providerOptions: {
hume: {
context: {
generationId: 'previous-generation-id',
},
} satisfies HumeSpeechModelOptions,
},
});The following provider options are available:
-
context object
Context for the speech synthesis request. Can be either:
{ generationId: string }- ID of a previously generated speech synthesis to use as context.{ utterances: Utterance[] }- An array of utterance objects for context, where each utterance has:textstring (required) - The text content.descriptionstring - Instructions for how the text should be spoken.speednumber - Speech rate multiplier.trailingSilencenumber - Duration of silence to add after the utterance in seconds.voiceobject - Voice configuration, either{ id: string, provider?: 'HUME_AI' | 'CUSTOM_VOICE' }or{ name: string, provider?: 'HUME_AI' | 'CUSTOM_VOICE' }.
Model Capabilities
| Model | Instructions | Speed | Output Formats |
|---|---|---|---|
default | ✓ | ✓ | mp3, pcm, wav |