Upload Voice
POST /api/voices/upload
Upload a new voice audio file via the API. The voice will be created with pending status and must be approved by an admin before it can be used in broadcasts. This endpoint uses multipart/form-data encoding for file upload.
Request Parameters
Section titled “Request Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Unique name for the voice (1-255 chars). Names are case-insensitive and must be unique per account. |
| audio | file | Yes | Audio file (max 10MB). Supported formats: mp3, wav, ogg, m4a, aac, webm, flac. |
Request Example
Section titled “Request Example”curl -X POST https://api.awajdigital.com/api/voices/upload \ -H "Authorization: Bearer your_api_token_here" \ -H "Accept: application/json" \ -F "name=my_voice_name" \ -F "audio=@/path/to/your/audio.mp3"// Browser JavaScript (Fetch API)const formData = new FormData();formData.append('name', 'my_voice_name');formData.append('audio', fileInput.files[0]); // from an <input type="file">
const response = await fetch('https://api.awajdigital.com/api/voices/upload', { method: 'POST', headers: { 'Authorization': 'Bearer your_api_token_here', 'Accept': 'application/json' }, body: formData});
const data = await response.json();console.log(data);// Node.js with axios and form-dataconst axios = require('axios');const FormData = require('form-data');const fs = require('fs');
async function uploadVoice() { try { const form = new FormData(); form.append('name', 'my_voice_name'); form.append('audio', fs.createReadStream('/path/to/your/audio.mp3'));
const response = await axios.post('https://api.awajdigital.com/api/voices/upload', form, { headers: { 'Authorization': 'Bearer your_api_token_here', 'Accept': 'application/json', ...form.getHeaders() } });
console.log(response.data); } catch (error) { console.error('Error:', error.response?.data || error.message); }}
uploadVoice();# Python with requestsimport requests
def upload_voice(): url = 'https://api.awajdigital.com/api/voices/upload' headers = { 'Authorization': 'Bearer your_api_token_here', 'Accept': 'application/json' } files = { 'audio': ('audio.mp3', open('/path/to/your/audio.mp3', 'rb'), 'audio/mpeg') } data = { 'name': 'my_voice_name' }
try: response = requests.post(url, headers=headers, files=files, data=data) print(response.json()) except requests.exceptions.RequestException as e: print(f'Error: {e}')
upload_voice()<?php// PHP with cURL$url = 'https://api.awajdigital.com/api/voices/upload';$token = 'your_api_token_here';
$ch = curl_init($url);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer ' . $token, 'Accept: application/json']);curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'name' => 'my_voice_name', 'audio' => new CURLFile('/path/to/your/audio.mp3', 'audio/mpeg', 'audio.mp3')]);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);curl_close($ch);
$result = json_decode($response, true);print_r($result);?>Success Response (201 Created)
Section titled “Success Response (201 Created)”{ "id": 4, "name": "my_voice_name", "status": "pending"}409 Conflict - Duplicate Voice Name
Section titled “409 Conflict - Duplicate Voice Name”A voice with the same name already exists in your account:
{ "message": "A voice with this name already exists"}413 Payload Too Large
Section titled “413 Payload Too Large”Audio file exceeds the 10MB size limit:
{ "message": "File size too large. Maximum allowed size is 10MB"}415 Unsupported Media Type
Section titled “415 Unsupported Media Type”Audio file format not supported:
{ "message": "Invalid file extension. Allowed extensions: mp3, wav, ogg, m4a, aac, webm, flac"}