Mindket

Text to speech with AI: make a voice that sounds natural

A black banner titled "AI voice and music" over the line "Speech, voice cloning, songs and dubbing".

Text to speech turns written text into spoken audio. OpenAI's speech endpoint takes a model, your text and a voice, plus an instructions field that sets tone, pace and accent, and open models such as Kokoro run on your own computer. A natural result comes from a well-chosen voice, clear direction and a check on how names and numbers are read.

In this lesson

  • Send one request to a speech endpoint and save the answer as an audio file.
  • Write a short direction for tone, pace and accent, and change one thing per try.
  • Spell out names, acronyms and codes the way they should be said.
  • Pick the route that fits the job: a hosted API, or a model on your own computer.
  • Tell listeners when a voice is AI-generated.
All courses
On this page
  1. Before you start
  2. Make a speech file with OpenAI's speech endpoint
  3. Direct the voice: tone, pace, accent and pronunciation
  4. Watch OpenAI introduce the speech model
  5. Run an open model on your own computer: Kokoro
  6. Which route fits the job
  7. Dates that decide what you build on
  8. Common mistakes
  9. Try it yourself
  10. Next lesson: voice cloning
  11. Check yourself
  12. Frequently asked questions
  13. Sources

Before you start

Text to speech (TTS) means a program reads written text aloud in a synthetic voice. This lesson covers two routes. The first calls OpenAI's speech endpoint, which needs an API key and a terminal with curl, and the OpenAI API quickstart shows how to get a key. The second runs Kokoro, a small open model, with Python on your own computer.

One date shapes the first route. OpenAI's guide marks tts-1, tts-1-hd and gpt-4o-mini-tts as deprecated, with a shutdown on 6 January 2027, and points new work to gpt-realtime-2.1-mini through the Realtime API. That is a different workflow, and the page says the model is not supported on /v1/audio/speech. Until the shutdown, the Speech API examples keep working, and they teach what every route shares: a voice, a direction and an output format.

OpenAI's usage policies also ask you to tell listeners that the voice is AI-generated and not a human voice. Plan the spoken line or the caption for that now, since adding it later is easy to forget.

Make a speech file with OpenAI's speech endpoint

The request has three required parts, the model, the text and the voice, and one optional part that matters here, instructions. The command below is the one from OpenAI's guide. It sends a sentence and a short direction, and writes the answer to speech.mp3.

curl https://api.openai.com/v1/audio/speech \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "input": "Today is a wonderful day to build something people love!",
    "voice": "coral",
    "instructions": "Speak in a cheerful and positive tone."
  }' \
  --output speech.mp3
  1. Put your API key in the OPENAI_API_KEY environment variable.
  2. Run the command above in a terminal. The guide's Python, JavaScript, Go, Java, C# and Ruby tabs send the same four fields.
  3. Open speech.mp3 and listen. MP3 is the default format.
  4. Change voice to marin or cedar. The guide's voice list names 13 built-in voices (its introduction says 11) and recommends those two for the best quality.
  5. Ask for wav or pcm with response_format when you stream the audio to speakers. The guide recommends them for the fastest response, and says pcm is raw 24 kHz, 16-bit samples with no header.
  6. Change one field and run it again. A single change per try tells you which field did what.
From OpenAI's text to speech guide, read on 6 November 2026.
Output formatThe guide says it is for
MP3General use, and the default
OpusInternet streaming and communication, low latency
AACDigital audio compression, preferred by YouTube, Android and iOS
FLACLossless compression, favored for archiving
WAVUncompressed audio for low-latency work that should skip decoding
PCMRaw 24 kHz, 16-bit samples with no header

Direct the voice: tone, pace, accent and pronunciation

The instructions field takes plain language. OpenAI's guide says it can steer accent, emotional range, intonation, impressions, speed of speech, tone and whispering, and gives one line as its example. For longer directions, OpenAI's guide to prompting Realtime voice models writes them as short labelled sections. Those are written for Realtime models, so read them as wording to borrow, not as a promise for the speech endpoint.

The block below joins three of that guide's separate examples into one direction and leaves out its Length line, which is about turns in a conversation. The guide says to keep the pronunciation list short and to add a word when you hear it said wrong.

# Personality & Tone
## Personality
- Friendly, calm and approachable expert customer service assistant.
## Tone
- Warm, concise, confident, never fawning.
## Pacing
- Deliver your audio response fast, but do not sound rushed.
- Do not modify the content of your response, only increase speaking speed for the same response.

# Reference Pronunciations
When voicing these words, use the respective pronunciations:
- Pronounce “SQL” as “sequel.”
- Pronounce “PostgreSQL” as “post-gress.”
- Pronounce “Kyiv” as “KEE-iv.”
- Pronounce "Huawei" as “HWAH-way”
  • Pace. In the Realtime API the speed setting changes playback rate, not how the model composes speech. To sound faster, the guide adds a pacing instruction like the one above.
  • Accent. The guide says a vague line such as "Sound Australian." can drift or switch language. It writes the accent as a few stable traits: "Speak English with a light Australian accent", keep it stable from the first word to the last, do not exaggerate it.
  • Codes and numbers. For phone numbers, order IDs and codes, the guide adds: speak each character separately, separated by hyphens (for example 4-1-5), and repeat the number exactly.
  • Limits of direction. The guide says prompting steers accent, pacing and delivery but does not replace voice design. A branded voice calls for a custom voice, which the next lesson covers.
  • Repetition. Sample phrases can be overused. A variety rule ("Do not repeat the same sentence twice") keeps a long read from sounding robotic.
From OpenAI's text to speech guide and its guide to prompting Realtime models, read on 6 November 2026.
What sounds offWhat to change
Flat, one-note deliveryAdd tone and emotion words to instructions, such as "cheerful and positive"
Too slow or too fastSay the pace in words, since the speed setting only changes playback in the Realtime API
A name or acronym said wrongList how it should sound: "SQL" as "sequel"
Digits blur togetherAsk for one character at a time, separated by hyphens
The accent wandersName the accent, say what stays stable and say not to exaggerate it
The same phrase keeps returningAdd a variety line

Watch OpenAI introduce the speech model

On 20 March 2025, four OpenAI team members introduced three audio models in the API, one of them the text to speech model behind the instructions field, and demonstrated it. The speech guide now lists that model as deprecated, so use the video for the idea of steering a voice and the guide for current dates.

OpenAI introduces and demonstrates three new audio models in the API, streamed on 20 March 2025 on its own channel.

Run an open model on your own computer: Kokoro

Kokoro is an open-weight model with 82 million parameters and a lightweight design. Its weights are Apache-licensed, so they can go into a product. The model card says it was trained only on permissive or non-copyrighted audio: public domain recordings, audio under licenses such as Apache or MIT, and synthetic audio from closed TTS models. Its README examples choose a named voice such as af_heart and show no reference clip. Version 1.0, published on 27 January 2025, ships 54 voices in 8 languages.

The package is kokoro. It also needs espeak-ng, a speech tool the README installs for English words outside its dictionary and for some other languages. The README's cell, trimmed below, writes one WAV file per chunk of text at 24,000 Hz.

pip install -q "kokoro>=0.9.4" soundfile
# espeak-ng: on Linux  apt-get -qq -y install espeak-ng
#            on Windows  run the .msi from the espeak-ng releases page

from kokoro import KPipeline
import soundfile as sf

pipeline = KPipeline(lang_code='a')   # 'a' => American English
text = '''Kokoro is an open-weight TTS model with 82 million parameters.'''
generator = pipeline(text, voice='af_heart')
for i, (gs, ps, audio) in enumerate(generator):
    print(i, gs, ps)
    sf.write(f'{i}.wav', audio, 24000)
  • lang_code picks the language and must match the voice: a American English, b British English, e Spanish, f French, h Hindi, i Italian, j Japanese, p Brazilian Portuguese, z Mandarin Chinese.
  • Japanese needs pip install misaki[ja] and Mandarin needs pip install misaki[zh].
  • On a Mac with Apple Silicon, the README sets PYTORCH_ENABLE_MPS_FALLBACK=1 to get GPU acceleration.
  • The model card links the full voice list (VOICES.md) and audio samples (SAMPLES.md).
  • The card warns that sites with kokoro in their domain name, such as kokorottsai_com, are not affiliated with the model and are likely scams.

Which route fits the job

A hosted API gives you direction in plain words and a finished voice. Kokoro costs nothing per file and keeps text on your machine, but you choose from its voices. Chatterbox takes a reference clip and has expression controls, with a catch in its status. For hosted tools beyond OpenAI, the AI voice generator lesson compares them.

Three ways to turn text into speech
OpenAI speech endpointKokoro-82MChatterbox
Runs on your own computerNoYesYes
Tone and pace set in plain wordsYesNot shown in its READMEPartly
Clones a voice from a clipPartlyNot shown in its READMEYes
LanguagesFollows Whisper's list, voices tuned for English8 languages, 54 voices23+ with Multilingual V3, English only for Turbo and Nano
License or termsOpenAI usage policiesApache-2.0MIT
Status on 6 November 2026Speech models shut down 6 January 2027Version 1.0 from January 2025Retired in August 2026, kept as an archive

Sources: OpenAI API docs: Text to speech (read November 6, 2026), Hugging Face: hexgrad/Kokoro-82M model card (read November 6, 2026), GitHub: resemble-ai/chatterbox README (read November 6, 2026), Hugging Face: ResembleAI/chatterbox model card (read November 6, 2026)

Dates that decide what you build on

Four dates from the vendors' own pages. The transcription shutdown matters again in the dubbing lesson, which starts from speech and ends in speech.

  1. Kokoro version 1.0 published

    54 voices in 8 languages, Apache-licensed weights.

    Source: Hugging Face: hexgrad/Kokoro-82M model card (read November 6, 2026)

  2. Chatterbox retired

    The repository stays public as an archive under the MIT license, with no support or updates.

    Source: GitHub: resemble-ai/chatterbox README (read November 6, 2026)

  3. OpenAI speech models shut down

    tts-1, tts-1-hd and gpt-4o-mini-tts stop working. Migrate to the Realtime API.

    Source: OpenAI API docs: Text to speech (read November 6, 2026)

  4. OpenAI transcription models shut down

    whisper-1, the gpt-4o-transcribe models and /v1/audio/translations stop working.

    Source: OpenAI API docs: File transcription (read November 6, 2026)

Common mistakes

  • Starting a new product on gpt-4o-mini-tts with no plan for its shutdown date.
  • Asking for "an Australian accent" with nothing about what should stay stable, then hearing it drift.
  • Using the speed setting to change how a line is delivered, when it only changes playback in the Realtime API.
  • Letting a phone number or order ID run together instead of asking for one character at a time.
  • Using a Kokoro lang_code that does not match the voice, or leaving out espeak-ng.
  • Piling pronunciations into one long list, when the guide says to keep it short and add words as you hear them wrong.
  • Leaving out the line that tells listeners the voice is AI-generated.

Try it yourself

  • Make speech.mp3 with the request above, then change only voice to marin and compare the two files.
  • Write a direction for one paragraph of your own, with a pace line and the pronunciation of one name, and check that the name comes out right.
  • Read a made-up order ID once with no rule and once with the hyphen rule, and listen for the difference.
  • Run the Kokoro cell, then switch lang_code and voice together to another language the README lists.

Next lesson: voice cloning

Choosing a built-in voice is one thing. Making a voice that sounds like a specific person is another, and it comes with consent rules. Voice cloning covers how it works, what OpenAI and the open models ask of you and what to check before you clone anything.

Check yourself

  1. Which field of OpenAI's speech request sets tone, pace and accent in plain words?

    Show answer

    C. instructions The guide says instructions steers accent, emotional range, intonation, speed of speech, tone and whispering. The other fields set the text, the voice and the file format.

  2. When does the guide say tts-1, tts-1-hd and gpt-4o-mini-tts shut down?

    Show answer

    B. 6 January 2027 The guide marks the three models deprecated and gives 6 January 2027 as the shutdown date. 26 February 2027 is the date for the transcription models.

  3. Which of these does the Kokoro model card state?

    Show answer

    D. It has 82 million parameters and Apache-licensed weights The card calls Kokoro an open-weight model with 82 million parameters and Apache-licensed weights. Version 1.0 lists 54 voices in 8 languages, and the pip package runs on your own computer.

  4. A phone number is read as one blur of digits. What does OpenAI's Realtime prompting guide suggest?

    Show answer

    A. Ask for one character at a time, separated by hyphens The guide adds a rule to speak each character separately, separated by hyphens, and to repeat the number exactly.

Frequently asked questions

Can the speech endpoint play audio while it is still being made?

Yes. The guide says the endpoint streams audio with chunk transfer encoding, so playback can begin before the whole file exists. For the fastest start it recommends wav or pcm as the format.

Is there a free text to speech AI that runs offline?

Kokoro is one. It installs with pip and espeak-ng, runs on your own computer and picks from 54 voices. Its card says the weights are Apache-licensed, and its README examples pick a named voice.

Do I have to say a voice is AI-generated?

For OpenAI's voices, yes, because its usage policies call for a clear notice to the people listening. A line in the caption or description is the simplest place for it. Other tools set their own terms, so read each one.

Which languages can OpenAI text to speech speak?

The guide says the model generally follows Whisper's language list, which includes Chinese, Spanish, French, Hindi and Malay, and that the voices are optimized for English. You write the input text in the language you want.

How do I make text to speech sound less robotic?

Direct it in words: tone and pace, a stable accent, a short list of pronunciations and one character at a time for codes. Change one thing per try, since several changes at once hide which one helped.

Sources

  1. OpenAI API docs: Text to speech (read November 6, 2026)https://developers.openai.com/api/docs/guides/text-to-speech
  2. OpenAI API docs: Prompting Realtime models (read November 6, 2026)https://developers.openai.com/api/docs/guides/voice-prompting
  3. OpenAI API docs: File transcription (read November 6, 2026)https://developers.openai.com/api/docs/guides/speech-to-text
  4. Hugging Face: hexgrad/Kokoro-82M model card (read November 6, 2026)https://huggingface.co/hexgrad/Kokoro-82M
  5. GitHub: hexgrad/kokoro README (read November 6, 2026)https://github.com/hexgrad/kokoro
  6. GitHub: resemble-ai/chatterbox README (read November 6, 2026)https://github.com/resemble-ai/chatterbox
  7. Hugging Face: ResembleAI/chatterbox model card (read November 6, 2026)https://huggingface.co/ResembleAI/chatterbox
  8. YouTube: OpenAI, Audio Models in the API (read November 6, 2026)https://www.youtube.com/watch?v=lXb0L16ISAc

Share this lesson

Pick the right voice tool

Hosted voice platforms differ in free plans, limits and what they ask before cloning a voice. Mindket compares them side by side.

Compare voice tools

This lesson as Markdown · AI voice and music: speech, voice cloning and songs · All courses