Update test_elevenlabs.php for direct logging
This commit is contained in:
@@ -57,28 +57,50 @@ echo "\n--- Generating Speech with ElevenLabs ---\n";
|
|||||||
$testText = "مرحباً بك! أنا مساعدك الذكي من نبيه، كيف يمكنني مساعدتك اليوم؟";
|
$testText = "مرحباً بك! أنا مساعدك الذكي من نبيه، كيف يمكنني مساعدتك اليوم؟";
|
||||||
echo "Text to generate: \"{$testText}\"\n";
|
echo "Text to generate: \"{$testText}\"\n";
|
||||||
|
|
||||||
// We pass an empty/dummy Gemini API Key and systemPrompt because we are only testing ElevenLabs TTS path
|
// Execute ElevenLabs TTS directly in this test script to get detailed error logs
|
||||||
$response = GeminiService::generateAudioResponse(
|
$url = 'https://api.elevenlabs.io/v1/text-to-speech/' . $elVoiceId;
|
||||||
'dummy_gemini_key',
|
|
||||||
'dummy_system_prompt',
|
|
||||||
$testText,
|
|
||||||
'Puck',
|
|
||||||
$elApiKey,
|
|
||||||
$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] Speech generation successful!\n";
|
||||||
echo "ℹ️ [ElevenLabs] Audio MimeType: {$response['mimeType']}\n";
|
echo "ℹ️ [ElevenLabs] Audio size: " . strlen($response) . " bytes\n";
|
||||||
echo "ℹ️ [ElevenLabs] Audio size: " . strlen($response['audio']) . " base64 chars\n";
|
|
||||||
|
|
||||||
// Save to test file
|
// Save to test file
|
||||||
$binaryAudio = base64_decode($response['audio']);
|
|
||||||
$outputPath = __DIR__ . '/test_elevenlabs_out.mp3';
|
$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";
|
echo "✅ [ElevenLabs] Audio successfully written to: " . basename($outputPath) . "\n";
|
||||||
} else {
|
} 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";
|
echo "\n=== Diagnostics Complete ===\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user