Stream Whisper uploads with curl so large audio does not OOM.

This commit is contained in:
ben
2026-08-13 20:29:59 +02:00
parent 1898be4def
commit e77a18c49f
7 changed files with 488 additions and 42 deletions
+32
View File
@@ -0,0 +1,32 @@
<?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();