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
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name, either tts-1 or tts-1-hd |
| input | string | Yes | Text to convert into speech, up to 4096 characters |
| voice | string | Yes | Voice style, options include alloy, echo, fable, onyx, nova, shimmer |
| response_format | string | No | Audio format, default mp3. Supported values: mp3, opus, aac, flac, wav, pcm |
| speed | string | No | Playback speed, default 1, range 0.25 to 4.0 |
| stream_format | string | No | Output 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.