---
title: "Convert text to speech"
description: "Generate natural-sounding audio from text using OpenAI's text-to-speech models."
url: "https://www.pixeltable.com/notebooks/audio-text-to-speech"
updated: "2026-04-10"
---

# Convert text to speech

Generate natural-sounding audio from text using OpenAI's text-to-speech models.

- **Type:** Notebook
- **Group:** Audio

## How it works

You add a computed column that converts text to audio. The audio is cached and only regenerated when the source text changes.

## What it covers

- Generate speech with OpenAI TTS
- Choose from multiple voice options
- Store text and audio together

## What it uses

- **Install:** `pip install pixeltable openai`
- **Environment variables it names:** `OPENAI_API_KEY`
- **Pixeltable calls:** `openai.speech()`, `pxt.create_table()`, `add_computed_column()`, `insert()`

## A look at the code

```python
# Add audio generation column
articles.add_computed_column(
    audio=speech(articles.content, model='tts-1', voice='alloy')
)
```

## Open it

- **Open in Colab:** https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/audio/audio-text-to-speech.ipynb
- **Docs page:** https://docs.pixeltable.com/howto/cookbooks/audio/audio-text-to-speech
- **Source on GitHub:** https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/audio/audio-text-to-speech.ipynb
