---
title: "AI Gateway Speech Quickstart: Transcription and TTS"
description: Generate spoken audio from text and transcribe audio back to text through Vercel AI Gateway using a coding agent, cURL, or the AI SDK.
url: "https://vercel.com/docs/ai-gateway/getting-started/speech"
last_updated: 2026-12-02
related:
  - /docs/ai-gateway/pricing
  - /docs/ai-gateway/modalities/text-to-speech
  - /docs/ai-gateway/modalities/speech-to-text
  - /docs/ai-gateway/getting-started/realtime
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# AI Gateway Speech Quickstart: Transcription and TTS

Generate speech from text through AI Gateway, save the audio, and transcribe it back to text.

## Generate and transcribe speech

### Use a coding agent

Paste this prompt into a coding agent with terminal access:

**Agent prompt**

```text
Add a text-to-speech and speech-to-text round trip through AI Gateway in the current environment. Use the AI Gateway skill for this task. If it is unavailable, run npx skills add vercel/vercel-plugin --skill ai-gateway, then find and read its SKILL.md before continuing. Reuse the environment's language, framework, package manager, and AI client when possible, choose AI Gateway SDKs or APIs that support speech generation and transcription, and add only required dependencies. Read AI_GATEWAY_API_KEY from the environment. If it is missing, run npx vercel@latest whoami and pause for login if needed. Determine the team, then run npx vercel@latest --scope <team-slug> ai-gateway api-keys create --name <descriptive-name>. Capture stdout directly into AI_GATEWAY_API_KEY for the request or existing ignored secret storage, and never expose the value. Use openai/tts-1 and openai/gpt-transcribe, save the audio, print the transcript, run the result, and report the output.
```

### Run the Node.js example

Use [Node.js 22.18 or later](https://nodejs.org/) and a team with available [AI Gateway Credits](/docs/ai-gateway/pricing). Export `AI_GATEWAY_API_KEY` in your current shell. If you need a key, open the [Create API Key dialog](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway%2Fapi-keys%3FshowCreateKeyModal%3Dtrue\&title=AI+Gateway+API+Keys).

```bash filename="Terminal"
export AI_GATEWAY_API_KEY="your_ai_gateway_api_key"
```

Install the AI SDK:

```bash filename="Terminal"
pnpm add ai@latest
```

Create `index.mts`:

```typescript filename="index.mts"
import {
  experimental_generateSpeech as generateSpeech,
  experimental_transcribe as transcribe,
} from 'ai';
import { writeFile } from 'node:fs/promises';

const text = 'Thanks for trying AI Gateway.';
const speech = await generateSpeech({
  model: 'openai/tts-1',
  text,
  voice: 'alloy',
  outputFormat: 'mp3',
});

await writeFile('speech.mp3', speech.audio.uint8Array);

const transcript = await transcribe({
  model: 'openai/gpt-transcribe',
  audio: speech.audio.uint8Array,
});

console.log(transcript.text);
```

Run the script:

```bash filename="Terminal"
node index.mts
```

## Next steps

- Generate speech with the [Text to Speech guide](/docs/ai-gateway/modalities/text-to-speech)
- Transcribe recorded or streaming audio with the [Speech to Text guide](/docs/ai-gateway/modalities/speech-to-text)
- Build live, two-way voice conversations with the [Realtime quickstart](/docs/ai-gateway/getting-started/realtime)

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
