[['parts' => [['text' => $prompt]]]], 'generationConfig' => ['responseMimeType' => 'application/json', 'temperature' => 0.7] ]; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60 ]); $res = curl_exec($ch); curl_close($ch); if (!$res) return null; $json = json_decode($res, true); $text = $json['candidates'][0]['content']['parts'][0]['text'] ?? ''; $text = preg_replace('/^```json\s*/i', '', $text); $text = preg_replace('/```\s*$/i', '', $text); return json_decode(trim($text), true); } /** * Step 2: Call external AI Video/Avatar API (e.g., HeyGen, Synthesia) * (Placeholder for future API integration) */ public static function triggerVideoGenerationApi(int $lessonId, string $scriptText): string { // TODO: Integrate with specific Video API (HeyGen, D-ID, Synthesia) // 1. Send $scriptText to API // 2. Receive Webhook or Poll for MP4 URL // 3. Download MP4 // 4. Pass MP4 to our VideoService::transcodeToHls() return "pending_api_integration"; } }