Convert text to speech

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

Audio · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

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
terminal
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

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

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103