> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pyai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add speech to your AI SDK app

> Give your app voice input and spoken answers with PyAI Hear and Speak through AI SDK 7. Keep your existing LLM and use your PyAI key on the server.

> [!NOTE]
>
> Using OpenClaw? Install the live PyAI skills for task-based speech and calling from ClawHub. See the [OpenClaw setup guide](https://docs.pyai.com/guides/openclaw.md) for install commands, permissions and example prompts.

Give users a way to speak to your app and hear its answers. Use **Hear** for
transcription and **Speak** for speech synthesis while keeping your existing
LLM, tools and application logic.

> [!NOTE]
>
> This integration calls PyAI directly. It does not require or establish a PyAI
> listing in Vercel AI Gateway. Your PyAI account handles speech billing.

## Try Hear and Speak before integrating

[Open the live voice demo](https://pyai-voice-demo-wfls74alya-uc.a.run.app/?source=ai-sdk):
record a question about PyAI, see Hear's transcript, and listen to Speak's reply.
You can also type. The product answers are scripted; transcription and speech
use real PyAI APIs. Three free questions, no signup required; daily demo limits apply.

The hosted demo is a standalone Hear + Speak reference app. To use these APIs in
your own application, [get a free API key](https://console.pyai.com/playground?signup=1\&path=api\&utm_source=docs.pyai.com\&utm_medium=guide\&utm_campaign=ai-sdk\&utm_content=quickstart\&intent=ai-sdk-speech-demo)
and follow the setup below. The demo also includes a signup link.

## Install

Use Node.js 22 or newer, on the server:

```bash theme={null}
npm install ai@7.0.153 @ai-sdk/openai@4.0.102
export PYAI_API_KEY=your_server_side_key
```

The key needs `speak:synthesize` and `hear:transcribe`. Never expose it in browser
code or a public environment variable.

## Speak, then transcribe

```js theme={null}
import { createOpenAI } from '@ai-sdk/openai';
import { generateSpeech, transcribe } from 'ai';

if (!process.env.PYAI_API_KEY) throw new Error('Set PYAI_API_KEY');
const pyai = createOpenAI({
  baseURL: 'https://api.pyai.com/v1',
  apiKey: process.env.PYAI_API_KEY,
});

const reply = await generateSpeech({
  model: pyai.speech('pyai-speak'),
  text: 'Your appointment is confirmed.',
  voice: 'stock_emma_en_gb',
  outputFormat: 'wav',
  maxRetries: 0,
  abortSignal: AbortSignal.timeout(30_000),
});

const transcript = await transcribe({
  model: pyai.transcription('pyai-hear'),
  audio: reply.audio.uint8Array,
  maxRetries: 0,
  abortSignal: AbortSignal.timeout(30_000),
});
console.log(transcript.text);
```

This makes two requests and consumes your PyAI quota or credit. Retries are
disabled so an uncertain billed request is not automatically submitted again.
Inspect the error before retrying. The example buffers a complete WAV and uses
synchronous transcription; it is not a realtime or streaming recipe.

## Runnable example and verification

[Download the runnable example and its contract tests](https://github.com/atomsai/pyai-speech-integrations/tree/main/ai-sdk).
The same helper passed a live Speak → Hear round trip on October 25, 2026:
a 2.48-second WAV was transcribed correctly, with two successful requests and
no retries. This verifies the integration path; it is not a latency SLA or a
multilingual quality benchmark.

## Choose languages and voices

Hear supports 29 recognition languages with automatic detection. Speak's stock
catalog spans 17 language groups. Select a suitable voice from
`GET https://api.pyai.com/v1/voices` and consult the
[language table](https://docs.pyai.com/reference/language-support.md). Test your application's accents,
audio conditions and preferred voices before production rollout.

## What does it cost?

See the [PyAI pricing page](https://pyai.com/pricing) for current Hear and Speak
rates and billing details. LLM and hosting costs are separate.

## Is customer audio used for training?

PyAI's default no-training warranty covers customer inputs and outputs for
shared/general model training. This is separate from retention; see the
[privacy policy](https://pyai.com/legal/privacy).

## Build a streaming voice agent

For streaming audio and your own turn policy, use the
[LiveKit Agents](https://docs.pyai.com/guides/livekit-agents.md) or [Pipecat](https://docs.pyai.com/guides/pipecat.md) Python
integration. For a managed conversational session, see [Omni](https://docs.pyai.com/guides/omni-overview.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.