OpenAI Audio
Official Documentation
Introduction
OpenAI Audio API provides three main functions:
- Text-to-Speech (TTS) - Convert text to natural speech
- Speech-to-Text (STT) - Transcribe audio to text
- Audio Translation - Translate non-English audio to English text
Request Examples
curl https://www.unodetech.xyz/v1/audio/speech \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello, world!",
"voice": "alloy"
}' \
--output speech.mp3Supported Models
tts-1: Standard model with fast response timetts-1-hd: High-quality model with better audio quality
Supported Voices
The voice parameter accepts different voice options:
- alloy: Balanced and natural voice
- coral: Warm and soft, feminine, suitable for lifestyle and customer service
- echo: Deep and stable, masculine, suitable for system prompts or explanatory text
- fable: Light and story-like, suitable for audiobooks or storytelling
- onyx: Deep and heavy, masculine, suitable for formal or professional scenarios
- nova: Bright and young, feminine, suitable for lively content or creative scenarios
- shimmer: Clear and light, feminine, suitable for short prompts or educational content
- sage: Calm and natural, neutral, suitable for explanations or neutral narration
curl https://www.unodetech.xyz/v1/audio/transcriptions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/audio.mp3" \
-F model="whisper-1"Response Example:
{
"text": "Hello, world!"
}curl https://www.unodetech.xyz/v1/audio/translations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/chinese.mp3" \
-F model="whisper-1"Response Example:
{
"text": "Hello, world!"
}Request
Endpoints
Text-to-Speech
POST /v1/audio/speechConvert text to speech.
Speech-to-Text
POST /v1/audio/transcriptionsTranscribe audio to text in the input language.
Audio Translation
POST /v1/audio/translationsTranslate audio to English text.
Authentication Method
Include the following in the request header for API key authentication:
Authorization: Bearer $API_KEYWhere $API_KEY is your API key.
Request Body Parameters
Text-to-Speech
Speech-to-Text
Audio Translation
Response
Successful Response
Returns binary audio file content.
Basic JSON Format
{
"text": "Transcribed text content"
}Detailed JSON Format
{
"task": "transcribe",
"language": "english",
"duration": 8.47,
"text": "Complete transcribed text",
"segments": [
{
"id": 0,
"seek": 0,
"start": 0.0,
"end": 3.32,
"text": "Segmented transcribed text",
"tokens": [50364, 440, 7534],
"temperature": 0.0,
"avg_logprob": -0.286,
"compression_ratio": 1.236,
"no_speech_prob": 0.009
}
]
}{
"text": "Translated English text"
}Error Response
When a request encounters an issue, the API will return an error response object, with HTTP status codes in the 4XX-5XX range.
Common Error Status Codes
400 Bad Request: Invalid request parameters401 Unauthorized: Invalid API key or not provided429 Too Many Requests: Exceeded API call limit500 Internal Server Error: Server internal error
Error response example:
{
"error": {
"message": "Unsupported file format",
"type": "invalid_request_error",
"param": "file",
"code": "invalid_file_format"
}
}Last updated on
