Get Task Result
Retrieve the audio file generated by a completed voice cloning task.
Request Information
- Method:
GET
- Endpoint:
/api/instant/task-result
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
task_id | string | Yes | The task ID to retrieve |
api_key | string | Yes | Your unique API key |
Prerequisites
- Task status must be
completed
- Use Task Status Query to confirm task completion
Response
Success Response (200 OK)
{
"audio_url": "https://pub-86e8fdaa1c484bfb856e9d0f2cf54e2a.r2.dev/1748144964376_0791dacf_voice_clone_result_d24db52d-c6ea-4722-b630-723bae3eb6dd.mp3"
}
Error Response
- 400 Bad Request: Missing required parameters
- 404 Not Found: Task does not exist or not completed
- 410 Gone: Audio file has expired
Example Request
curl -X GET "https://aivoiceclonefree.com/api/instant/task-result?task_id=1406bf34-735c-4b21-98ac-a135b2afb1c8&api_key=your_api_key_here"
Audio File Information
- Format: MP3
- Validity: Audio links are typically valid for 24-48 hours
- Download: Audio files can be downloaded directly via the returned URL
Complete Async Workflow Example
JavaScript Complete Example
class VoiceCloneAPI {
constructor(apiKey, baseUrl = 'https://aivoiceclonefree.com') {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
}
// Create async task
async createTask(audioFile, text) {
const formData = new FormData();
formData.append('audio', audioFile);
formData.append('text', text);
formData.append('api_key', this.apiKey);
const response = await fetch(`${this.baseUrl}/api/instant/create-task`, {
method: 'POST',
body: formData
});
return response.json();
}
// Query task status
async getTaskStatus(taskId) {
const response = await fetch(
`${this.baseUrl}/api/instant/task-status?task_id=${taskId}&api_key=${this.apiKey}`
);
return response.json();
}
// Get task result
async getTaskResult(taskId) {
const response = await fetch(
`${this.baseUrl}/api/instant/task-result?task_id=${taskId}&api_key=${this.apiKey}`
);
return response.json();
}
// Complete async cloning workflow
async cloneVoiceAsync(audioFile, text) {
try {
// 1. Create task
console.log('Creating voice cloning task...');
const taskResponse = await this.createTask(audioFile, text);
const taskId = taskResponse.task_id;
console.log(`Task ID: ${taskId}`);
// 2. Poll status
console.log('Waiting for task completion...');
let status = 'pending';
const maxAttempts = 20;
const interval = 30000; // 30 seconds
for (let i = 0; i < maxAttempts && status !== 'completed' && status !== 'failed'; i++) {
await new Promise(resolve => setTimeout(resolve, interval));
const statusResponse = await this.getTaskStatus(taskId);
status = statusResponse.status;
console.log(`Status check ${i + 1}: ${status}`);
}
// 3. Get result
if (status === 'completed') {
console.log('Task completed, getting result...');
const result = await this.getTaskResult(taskId);
console.log('Audio file URL:', result.audio_url);
return result;
} else {
throw new Error(`Task failed or timed out, final status: ${status}`);
}
} catch (error) {
console.error('Error during voice cloning:', error);
throw error;
}
}
}
// Usage example
const api = new VoiceCloneAPI('your_api_key_here');
// Get audio file (e.g., from file input)
const audioInput = document.getElementById('audioFile');
const audioFile = audioInput.files[0];
const text = "This is the long text content to be synthesized...";
api.cloneVoiceAsync(audioFile, text)
.then(result => {
console.log('Voice cloning completed!');
console.log('Audio URL:', result.audio_url);
// Can create audio element for playback or provide download link
const audio = new Audio(result.audio_url);
audio.play();
})
.catch(error => {
console.error('Error:', error);
});
Python Complete Example
import requests
import time
class VoiceCloneAPI:
def __init__(self, api_key, base_url='https://aivoiceclonefree.com'):
self.api_key = api_key
self.base_url = base_url
def create_task(self, audio_file_path, text):
"""Create async task"""
with open(audio_file_path, 'rb') as audio_file:
files = {'audio': audio_file}
data = {
'text': text,
'api_key': self.api_key
}
response = requests.post(
f'{self.base_url}/api/instant/create-task',
files=files,
data=data
)
return response.json()
def get_task_status(self, task_id):
"""Query task status"""
params = {
'task_id': task_id,
'api_key': self.api_key
}
response = requests.get(
f'{self.base_url}/api/instant/task-status',
params=params
)
return response.json()
def get_task_result(self, task_id):
"""Get task result"""
params = {
'task_id': task_id,
'api_key': self.api_key
}
response = requests.get(
f'{self.base_url}/api/instant/task-result',
params=params
)
return response.json()
def clone_voice_async(self, audio_file_path, text):
"""Complete async cloning workflow"""
try:
# 1. Create task
print('Creating voice cloning task...')
task_response = self.create_task(audio_file_path, text)
task_id = task_response['task_id']
print(f'Task ID: {task_id}')
# 2. Poll status
print('Waiting for task completion...')
status = 'pending'
max_attempts = 20
interval = 30 # 30 seconds
for i in range(max_attempts):
if status in ['completed', 'failed']:
break
time.sleep(interval)
status_response = self.get_task_status(task_id)
status = status_response['status']
print(f'Status check {i + 1}: {status}')
# 3. Get result
if status == 'completed':
print('Task completed, getting result...')
result = self.get_task_result(task_id)
print('Audio file URL:', result['audio_url'])
return result
else:
raise Exception(f'Task failed or timed out, final status: {status}')
except Exception as e:
print(f'Error during voice cloning: {e}')
raise
# Usage example
if __name__ == '__main__':
api = VoiceCloneAPI('your_api_key_here')
try:
result = api.clone_voice_async(
'path/to/audio/sample.mp3',
'This is the long text content to be synthesized...'
)
print('Voice cloning completed!')
print('Audio URL:', result['audio_url'])
# Can download audio file
audio_response = requests.get(result['audio_url'])
with open('generated_voice.mp3', 'wb') as f:
f.write(audio_response.content)
print('Audio file downloaded as generated_voice.mp3')
except Exception as e:
print(f'Error: {e}')
Notes
- File Validity: Audio file links are typically valid for 24-48 hours, please download promptly
- Network Timeout: Recommend setting appropriate network timeout values
- Error Handling: Implement proper error handling and retry mechanisms
- Resource Cleanup: Delete local temporary files after download completion
Last updated on