From eb291014ba4804ff7a8305d41e5223c76b8e0592 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 22 May 2026 16:50:57 +0300 Subject: [PATCH] Update test_elevenlabs.php for direct logging --- backend/public/test_elevenlabs.php | 52 +++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/backend/public/test_elevenlabs.php b/backend/public/test_elevenlabs.php index 1842197..1b3f5ae 100644 --- a/backend/public/test_elevenlabs.php +++ b/backend/public/test_elevenlabs.php @@ -57,28 +57,50 @@ echo "\n--- Generating Speech with ElevenLabs ---\n"; $testText = "مرحباً بك! أنا مساعدك الذكي من نبيه، كيف يمكنني مساعدتك اليوم؟"; echo "Text to generate: \"{$testText}\"\n"; -// We pass an empty/dummy Gemini API Key and systemPrompt because we are only testing ElevenLabs TTS path -$response = GeminiService::generateAudioResponse( - 'dummy_gemini_key', - 'dummy_system_prompt', - $testText, - 'Puck', - $elApiKey, - $elVoiceId -); +// Execute ElevenLabs TTS directly in this test script to get detailed error logs +$url = 'https://api.elevenlabs.io/v1/text-to-speech/' . $elVoiceId; -if ($response && !empty($response['audio'])) { +$payload = json_encode([ + 'text' => $testText, + 'model_id' => 'eleven_multilingual_v2', + 'voice_settings' => [ + 'stability' => 0.5, + 'similarity_boost' => 0.8 + ] +]); + +echo "Sending API request to: {$url}...\n"; +$ch = curl_init($url); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_POST, true); +curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); +curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'xi-api-key: ' . $elApiKey +]); +curl_setopt($ch, CURLOPT_TIMEOUT, 30); + +$response = curl_exec($ch); +$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); +$curlError = curl_error($ch); +curl_close($ch); + +echo "HTTP Status Code: {$httpCode}\n"; +if ($curlError) { + echo "cURL Error: {$curlError}\n"; +} + +if ($httpCode === 200) { echo "✅ [ElevenLabs] Speech generation successful!\n"; - echo "ℹ️ [ElevenLabs] Audio MimeType: {$response['mimeType']}\n"; - echo "ℹ️ [ElevenLabs] Audio size: " . strlen($response['audio']) . " base64 chars\n"; + echo "ℹ️ [ElevenLabs] Audio size: " . strlen($response) . " bytes\n"; // Save to test file - $binaryAudio = base64_decode($response['audio']); $outputPath = __DIR__ . '/test_elevenlabs_out.mp3'; - file_put_contents($outputPath, $binaryAudio); + file_put_contents($outputPath, $response); echo "✅ [ElevenLabs] Audio successfully written to: " . basename($outputPath) . "\n"; } else { - echo "❌ [ElevenLabs] Speech generation failed. Check error log or verify API Key quota/limits.\n"; + echo "❌ [ElevenLabs] Speech generation failed.\n"; + echo "Response: " . $response . "\n"; } echo "\n=== Diagnostics Complete ===\n";