Download Asynchronous Task Result
The task result endpoint allows you to download the generated audio file from a completed asynchronous voice cloning task.
Endpoint
GET https://aivoiceclonefree.com/api/async-clone/task-result/{task_id}
Authentication
This endpoint requires authentication using your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Path Parameters
Parameter | Type | Required | Description |
---|---|---|---|
task_id | String | Yes | The unique identifier of a completed task |
Request Example
cURL
curl -X GET "https://aivoiceclonefree.com/api/async-clone/task-result/abc123def456ghi789" \
-H "Authorization: Bearer YOUR_API_KEY" \
--output "generated_audio.wav"
Python
import requests
task_id = "abc123def456ghi789"
url = f"https://aivoiceclonefree.com/api/async-clone/task-result/{task_id}"
headers = {
"Authorization": "Bearer YOUR_API_KEY"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
with open("generated_audio.wav", "wb") as audio_file:
audio_file.write(response.content)
print("Audio file downloaded successfully!")
else:
print(f"Error: {response.status_code}")
JavaScript
const taskId = "abc123def456ghi789";
fetch(`https://aivoiceclonefree.com/api/async-clone/task-result/${taskId}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
})
.then(response => {
if (response.ok) {
return response.blob();
}
throw new Error('Failed to download audio');
})
.then(audioBlob => {
// Create download link
const url = window.URL.createObjectURL(audioBlob);
const a = document.createElement('a');
a.href = url;
a.download = 'generated_audio.wav';
a.click();
window.URL.revokeObjectURL(url);
});
Response
Success Response (200 OK)
The response will be an audio file in WAV format containing the generated speech.
Headers:
Content-Type: audio/wav
Content-Length: [file_size]
Content-Disposition: attachment; filename="task_abc123def456ghi789.wav"
Error Responses
401 Unauthorized
{
"detail": "Invalid or missing API key"
}
403 Forbidden
{
"detail": "Access denied. Task belongs to another user"
}
404 Not Found
{
"detail": "Task not found or result not available"
}
409 Conflict
{
"detail": "Task not completed yet. Current status: processing"
}
410 Gone
{
"detail": "Task result has expired and is no longer available"
}
Complete Workflow Example
Here’s a complete example showing how to create a task, monitor its progress, and download the result:
Python Complete Example
import requests
import time
import json
class VoiceCloningClient:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://aivoiceclonefree.com/api"
self.headers = {"Authorization": f"Bearer {api_key}"}
def create_task(self, audio_file_path, text):
"""Create an asynchronous voice cloning task"""
url = f"{self.base_url}/async-clone/create-task"
with open(audio_file_path, "rb") as audio_file:
files = {"audio_file": audio_file}
data = {"text": text}
response = requests.post(url, headers=self.headers, files=files, data=data)
return response.json()
def check_status(self, task_id):
"""Check the status of a task"""
url = f"{self.base_url}/async-clone/task-status/{task_id}"
response = requests.get(url, headers=self.headers)
return response.json()
def download_result(self, task_id, output_path):
"""Download the generated audio file"""
url = f"{self.base_url}/async-clone/task-result/{task_id}"
response = requests.get(url, headers=self.headers)
if response.status_code == 200:
with open(output_path, "wb") as audio_file:
audio_file.write(response.content)
return True
return False
def clone_voice_async(self, audio_file_path, text, output_path, max_wait=600):
"""Complete async voice cloning workflow"""
# Step 1: Create task
print("Creating task...")
task_data = self.create_task(audio_file_path, text)
task_id = task_data["task_id"]
print(f"Task created: {task_id}")
# Step 2: Wait for completion
print("Waiting for completion...")
start_time = time.time()
while time.time() - start_time < max_wait:
status_data = self.check_status(task_id)
status = status_data["status"]
print(f"Status: {status}")
if status == "completed":
# Step 3: Download result
print("Downloading result...")
if self.download_result(task_id, output_path):
print(f"Audio saved to: {output_path}")
return True
else:
print("Failed to download result")
return False
elif status == "failed":
print(f"Task failed: {status_data.get('error', 'Unknown error')}")
return False
# Wait before next check
time.sleep(30)
print("Task did not complete within timeout")
return False
# Usage example
client = VoiceCloningClient("YOUR_API_KEY")
success = client.clone_voice_async(
audio_file_path="voice_sample.wav",
text="This is a long text that will be processed asynchronously...",
output_path="generated_speech.wav"
)
if success:
print("Voice cloning completed successfully!")
else:
print("Voice cloning failed.")
Result File Information
Audio Format
- Format: WAV (uncompressed)
- Sample Rate: 22,050 Hz
- Bit Depth: 16-bit
- Channels: Mono
File Availability
- Retention Period: 7 days after task completion
- Access: Only available to the task creator
- Downloads: Unlimited within retention period
Best Practices
- Download Promptly: Download results soon after completion
- Store Locally: Save important results to your own storage
- Error Handling: Always check response status before processing
- Retry Logic: Implement retry for temporary network failures
- File Validation: Verify downloaded file integrity
Troubleshooting
Common Issues
Issue | Cause | Solution |
---|---|---|
404 Not Found | Task ID doesn’t exist | Verify task ID is correct |
409 Conflict | Task not completed | Wait for task completion |
410 Gone | Result expired | Results are only available for 7 days |
Large file timeout | Network timeout | Use chunked download or increase timeout |
Download with Resume Support
def download_with_resume(url, headers, output_path):
"""Download with resume capability for large files"""
resume_pos = 0
if os.path.exists(output_path):
resume_pos = os.path.getsize(output_path)
headers['Range'] = f'bytes={resume_pos}-'
response = requests.get(url, headers=headers, stream=True)
mode = 'ab' if resume_pos > 0 else 'wb'
with open(output_path, mode) as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
return response.status_code == 200 or response.status_code == 206
Last updated on