rtrim($whisper_url, '/').'/v1/audio/transcriptions', CURLOPT_POST => true, CURLOPT_POSTFIELDS => array( 'file' => $cfile, 'model' => 'whisper-1', 'language' => $language, ), CURLOPT_HTTPHEADER => $api_key ? array('Authorization: Bearer '.$api_key) : array(), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 120, )); } else { // whisper.cpp server /inference curl_setopt_array($ch, array( CURLOPT_URL => rtrim($whisper_url, '/').'/inference', CURLOPT_POST => true, CURLOPT_POSTFIELDS => array( 'file' => $cfile, 'language' => $language, 'response_format' => 'json', ), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 120, )); } $resp = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); if ($err) api_fail('Whisper-Fehler: '.$err, 502); if ($status !== 200) api_fail('Whisper HTTP '.$status.': '.substr($resp, 0, 200), 502); $data = json_decode($resp, true); $text = ''; if (is_array($data)) { $text = $data['text'] ?? ($data['transcription'] ?? ''); } else { $text = (string) $resp; } $text = trim($text); api_ok(array('text' => $text, 'language' => $language));