> ## 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.

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.

## 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?

Hear is $0.001 per audio minute; synchronous nonempty requests round up to a
started minute per request, and empty transcripts are free. Speak is $0.04 per
generated audio minute, metered by output duration. LLM and hosting costs are
separate. See [current pricing](https://pyai.com/pricing).

## 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.