Files
AndyTranscribe/tests/fixtures/whisper-sse-stub.php
T

33 lines
999 B
PHP

<?php
/**
* Tiny Whisper-compatible stub for curl transport tests.
* Speaks OpenAI-style /v1/audio/transcriptions SSE.
*/
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
if ($uri !== '/v1/audio/transcriptions' && $uri !== '/audio/transcriptions') {
http_response_code(404);
header('Content-Type: application/json');
echo '{"error":"not found"}';
return;
}
// Drain the multipart body without keeping it in a string longer than needed.
$stdin = fopen('php://input', 'rb');
if (is_resource($stdin)) {
while (! feof($stdin)) {
fread($stdin, 8192);
}
fclose($stdin);
}
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
echo "data: {\"type\":\"transcript.text.delta\",\"delta\":\"Hello \",\"end\":10}\n\n";
echo "data: {\"type\":\"transcript.text.delta\",\"delta\":\"from whisper.\",\"end\":30}\n\n";
echo "data: {\"type\":\"transcript.text.done\",\"text\":\"Hello from whisper.\",\"end\":40}\n\n";
flush();