🎵 Sound Effect Generator
$text,
'prompt_influence' => (float)$promptInfluence
];
if (!empty($duration) && is_numeric($duration)) {
$data['duration_seconds'] = (float)$duration;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'xi-api-key: ' . $apiKey,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
$error = 'Connection error: ' . curl_error($ch);
curl_close($ch);
return false;
}
curl_close($ch);
if ($httpCode === 200) {
$filename = 'sound_effect_' . date('Y-m-d_H-i-s') . '.mp3';
$filepath = __DIR__ . '/generated/' . $filename;
if (!is_dir(__DIR__ . '/generated')) {
mkdir(__DIR__ . '/generated', 0755, true);
}
if (file_put_contents($filepath, $response)) {
// Send webhook for provenance tracking
try {
$webhookProcessor = new AudioWebhookProcessor();
$webhookData = [
'prompt' => $text,
'generation_type' => 'ElevenLabs Sound Effects',
'settings' => [
'prompt' => $text,
'duration_seconds' => $data['duration_seconds'] ?? 'auto',
'prompt_influence' => $data['prompt_influence'],
'model' => 'elevenlabs-sound-generation'
],
'audio_data' => $response, // Raw audio binary data
'client' => 'Oliver Agency',
'user_email' => 'sound-effects@oliver.agency',
'deliverable_number' => '1000000', // Default deliverable number
'additional_data' => [
'filename' => $filename,
'file_size' => strlen($response),
'generation_timestamp' => date('Y-m-d H:i:s'),
'api_endpoint' => 'elevenlabs-sound-generation'
]
];
$webhookSuccess = $webhookProcessor->sendGenerationData($webhookData);
if (!$webhookSuccess) {
error_log("Webhook failed for sound generation: " . $filename);
}
} catch (Exception $e) {
error_log("Webhook error: " . $e->getMessage());
}
return 'generated/' . $filename;
} else {
$error = 'Failed to save the generated sound file.';
return false;
}
} else {
$errorResponse = json_decode($response, true);
$error = 'API Error (' . $httpCode . '): ' . ($errorResponse['detail'] ?? 'Unknown error occurred');
return false;
}
}
?>
Error: