Skip to content

OpenAI TTS-1

Brief: Convert text to speech using OpenAI TTS-1.


Overview

  • Method: POST
  • Path: /v1/audio/speech
  • Content-Type: application/json

Authentication

  • Header: Authorization: Bearer <token>
  • Supports bearer token authentication

Request Body Parameters

ParameterTypeRequiredDescription
modelstringYesModel name, either tts-1 or tts-1-hd
inputstringYesText to convert into speech, up to 4096 characters
voicestringYesVoice style, options include alloy, echo, fable, onyx, nova, shimmer
response_formatstringNoAudio format, default mp3. Supported values: mp3, opus, aac, flac, wav, pcm
speedstringNoPlayback speed, default 1, range 0.25 to 4.0
stream_formatstringNoOutput mode, audio for raw audio, sse for server-sent events. Default: audio

curl Example

bash
curl -X POST "https://api.gpt.ge/v1/audio/speech" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxx" \
  -d '{
    "model": "tts-1",
    "input": "Hello, this is a text-to-speech test.",
    "voice": "alloy",
    "response_format": "mp3",
    "speed": "1"
  }'

JavaScript (fetch) Example

javascript
fetch('https://api.gpt.ge/v1/audio/speech', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer sk-xxxx'
  },
  body: JSON.stringify({
    model: 'tts-1',
    input: 'Hello, this is a text-to-speech test.',
    voice: 'alloy',
    response_format: 'mp3',
    speed: '1'
  })
}).then(r => r.blob()).then(console.log);

Python (requests) Example

python
import requests

response = requests.post(
    'https://api.gpt.ge/v1/audio/speech',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer sk-xxxx'
    },
    json={
        'model': 'tts-1',
        'input': 'Hello, this is a text-to-speech test.',
        'voice': 'alloy',
        'response_format': 'mp3',
        'speed': '1'
    }
)
print(response.status_code)
print(response.content[:20])

Response Example (200)

text
<binary audio data returned directly, such as an MP3 file>

Note: The response typically returns the audio content directly in the selected format.