📄 ai-sdk/docs/ai-sdk-core/speech

File: speech.md | Updated: 11/15/2025

Source: https://ai-sdk.dev/docs/ai-sdk-core/speech

AI SDK

Menu

v5 (Latest)

AI SDK 5.x

AI SDK by Vercel

AI SDK 6 Beta

Foundations

Overview

Providers and Models

Prompts

Tools

Streaming

Getting Started

Navigating the Library

Next.js App Router

Next.js Pages Router

Svelte

Vue.js (Nuxt)

Node.js

Expo

Agents

Agents

Building Agents

Workflow Patterns

Loop Control

AI SDK Core

Overview

Generating Text

Generating Structured Data

Tool Calling

Model Context Protocol (MCP) Tools

Prompt Engineering

Settings

Embeddings

Image Generation

Transcription

Speech

Language Model Middleware

Provider & Model Management

Error Handling

Testing

Telemetry

AI SDK UI

Overview

Chatbot

Chatbot Message Persistence

Chatbot Resume Streams

Chatbot Tool Usage

Generative User Interfaces

Completion

Object Generation

Streaming Custom Data

Error Handling

Transport

Reading UIMessage Streams

Message Metadata

Stream Protocols

AI SDK RSC

Advanced

Reference

AI SDK Core

AI SDK UI

AI SDK RSC

Stream Helpers

AI SDK Errors

Migration Guides

Troubleshooting

Copy markdown

Speech

============================================================

Speech is an experimental feature.

The AI SDK provides the generateSpeech function to generate speech from text using a speech model.

import { experimental_generateSpeech as generateSpeech } from 'ai';import { openai } from '@ai-sdk/openai';
const audio = await generateSpeech({  model: openai.speech('tts-1'),  text: 'Hello, world!',  voice: 'alloy',});

Language Setting

You can specify the language for speech generation (provider support varies):

import { experimental_generateSpeech as generateSpeech } from 'ai';import { lmnt } from '@ai-sdk/lmnt';
const audio = await generateSpeech({  model: lmnt.speech('aurora'),  text: 'Hola, mundo!',  language: 'es', // Spanish});

To access the generated audio:

const audio = audio.audioData; // audio data e.g. Uint8Array

Settings


Provider-Specific settings

You can set model-specific settings with the providerOptions parameter.

import { experimental_generateSpeech as generateSpeech } from 'ai';import { openai } from '@ai-sdk/openai';
const audio = await generateSpeech({  model: openai.speech('tts-1'),  text: 'Hello, world!',  providerOptions: {    openai: {      // ...    },  },});

Abort Signals and Timeouts

generateSpeech accepts an optional abortSignal parameter of type AbortSignal that you can use to abort the speech generation process or set a timeout.

import { openai } from '@ai-sdk/openai';import { experimental_generateSpeech as generateSpeech } from 'ai';
const audio = await generateSpeech({  model: openai.speech('tts-1'),  text: 'Hello, world!',  abortSignal: AbortSignal.timeout(1000), // Abort after 1 second});

Custom Headers

generateSpeech accepts an optional headers parameter of type Record<string, string> that you can use to add custom headers to the speech generation request.

import { openai } from '@ai-sdk/openai';import { experimental_generateSpeech as generateSpeech } from 'ai';
const audio = await generateSpeech({  model: openai.speech('tts-1'),  text: 'Hello, world!',  headers: { 'X-Custom-Header': 'custom-value' },});

Warnings

Warnings (e.g. unsupported parameters) are available on the warnings property.

import { openai } from '@ai-sdk/openai';import { experimental_generateSpeech as generateSpeech } from 'ai';
const audio = await generateSpeech({  model: openai.speech('tts-1'),  text: 'Hello, world!',});
const warnings = audio.warnings;

Error Handling

When generateSpeech cannot generate a valid audio, it throws a AI_NoSpeechGeneratedError .

This error can arise for any the following reasons:

  • The model failed to generate a response
  • The model generated a response that could not be parsed

The error preserves the following information to help you log the issue:

  • responses: Metadata about the speech model responses, including timestamp, model, and headers.

  • cause: The cause of the error. You can use this for more detailed error handling.

    import { experimental_generateSpeech as generateSpeech, NoSpeechGeneratedError,} from 'ai';import { openai } from '@ai-sdk/openai'; try { await generateSpeech({ model: openai.speech('tts-1'), text: 'Hello, world!', });} catch (error) { if (NoSpeechGeneratedError.isInstance(error)) { console.log('AI_NoSpeechGeneratedError'); console.log('Cause:', error.cause); console.log('Responses:', error.responses); }}

Speech Models


| Provider | Model | | --- | --- | | OpenAI | tts-1 | | OpenAI | tts-1-hd | | OpenAI | gpt-4o-mini-tts | | ElevenLabs | eleven_v3 | | ElevenLabs | eleven_multilingual_v2 | | ElevenLabs | eleven_flash_v2_5 | | ElevenLabs | eleven_flash_v2 | | ElevenLabs | eleven_turbo_v2_5 | | ElevenLabs | eleven_turbo_v2 | | LMNT | aurora | | LMNT | blizzard | | Hume | default |

Above are a small subset of the speech models supported by the AI SDK providers. For more, see the respective provider documentation.

On this page

Speech

Language Setting

Settings

Provider-Specific settings

Abort Signals and Timeouts

Custom Headers

Warnings

Error Handling

Speech Models

Deploy and Scale AI Apps with Vercel.

Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.

Trusted by industry leaders:

  • OpenAI
  • Photoroom
  • leonardo-ai Logoleonardo-ai Logo
  • zapier Logozapier Logo

Talk to an expert