Text to speech (TTS)
curl --request POST \
--url https://openp.ai/v1/audio/speechimport requests
url = "https://openp.ai/v1/audio/speech"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://openp.ai/v1/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openp.ai/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openp.ai/v1/audio/speech"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openp.ai/v1/audio/speech")
.asString();require 'uri'
require 'net/http'
url = URI("https://openp.ai/v1/audio/speech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyOpenAI-compatible
Text to speech (TTS)
POST /v1/audio/speech — synthesize text into speech
POST
/
v1
/
audio
/
speech
Text to speech (TTS)
curl --request POST \
--url https://openp.ai/v1/audio/speechimport requests
url = "https://openp.ai/v1/audio/speech"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://openp.ai/v1/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openp.ai/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openp.ai/v1/audio/speech"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openp.ai/v1/audio/speech")
.asString();require 'uri'
require 'net/http'
url = URI("https://openp.ai/v1/audio/speech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodySynthesize text into natural-sounding speech.
Request
curl https://openp.ai/v1/audio/speech \
-H "Authorization: Bearer $OPENPAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello from OpenPAI",
"voice": "alloy",
"response_format": "mp3"
}' --output speech.mp3
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | tts-1 / tts-1-hd / gpt-4o-mini-tts |
input | string | ✅ | The text to synthesize (up to 4096 characters) |
voice | string | ✅ | Voice: alloy / echo / fable / onyx / nova / shimmer / coral / verse, etc. |
response_format | string | mp3 (default) / opus / aac / flac / wav / pcm | |
speed | number | 0.25 - 4.0 (default 1.0) | |
instructions | string | gpt-4o-mini-tts only; describe tone / style |
Response
Returns a binary audio stream directly, withContent-Type matching the chosen response_format:
| response_format | Content-Type |
|---|---|
mp3 | audio/mpeg |
opus | audio/ogg |
aac | audio/aac |
flac | audio/flac |
wav | audio/wav |
pcm | audio/pcm |
Python example
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://openp.ai/v1")
with client.audio.speech.with_streaming_response.create(
model="tts-1-hd",
voice="nova",
input="OpenPAI makes integrating LLMs simpler.",
) as resp:
resp.stream_to_file("output.mp3")
gpt-4o-mini-tts advanced
The next-gen TTS supports controlling tone viainstructions:
{
"model": "gpt-4o-mini-tts",
"voice": "coral",
"input": "Today's meeting results were excellent.",
"instructions": "Read in an excited, upbeat tone, slightly faster."
}
Streaming playback
Synthesis may take ≥ 1 second; in a browser or client you can receive it as a stream:with client.audio.speech.with_streaming_response.create(
model="tts-1",
voice="alloy",
input="...",
response_format="opus",
) as resp:
for chunk in resp.iter_bytes():
# play as you receive
play(chunk)