Docs Guides
Guide

Python Text-to-Speech

The Audio API `speech` endpoint (TTS) can:

Overview

The Audio API speech endpoint (TTS) can:

  • Read blog posts aloud
  • Generate multilingual audio
  • Stream audio in real time
Important: You must disclose that listeners are hearing AI-generated speech, not a human voice.

Basic usage

Example

from pathlib import Path from openai import OpenAI client = OpenAI( base_url="https://api.digislash.com/v1", api_key=key ) speech_file_path = Path(__file__).parent / "speech.mp3" response = client.audio.speech.create( model="tts-1", voice="alloy", input="Today is a wonderful day to build something people love!" ) response.stream_to_file(speech_file_path)
json

Features

Quality options

  • tts-1: lower latency, good for realtime
  • tts-1-hd: higher quality, may have less static

Voices

  • alloy
  • echo
  • fable
  • nova
  • shimmer
  • onyx

Output formats

FormatNotesBest for
MP3DefaultGeneral use
OpusLow latencyStreaming / comms
AACEfficientMobile playback
FLACLosslessArchiving
WAVUncompressedLow-latency apps
PCMRaw samples24kHz, 16-bit signed

Streaming

from openai import OpenAI client = OpenAI( base_url="https://api.digislash.com/v1", api_key=key ) response = client.audio.speech.create( model="tts-1", voice="alloy", input="Hello world! This is a streaming test.", ) response.stream_to_file("output.mp3")
json

Languages

Many languages, including:

  • Asian: Chinese, Japanese, Korean, etc.
  • European: English, French, German, etc.
  • Others: Arabic, Hindi, etc.
Note: Current voices are optimized mainly for English

FAQ

Q: How do I control emotion?

A: There is no direct control. Capitalization or grammar may change the output, but results vary.

Q: Can I create a custom voice?

A: Custom voices are not supported.

Q: Who owns the audio?

A: The creator owns it, but you must tell users it is AI-generated.