fix: diagnose and reduce STT 400 errors
- sttProxy now returns detailed upload error info (code, error string, php limits) - sttProxy accepts fallback upload field name 'file' in addition to 'audio' - reject empty audio payloads with explicit message - client: guard against very short/empty blobs before POST to /stt-proxy
This commit is contained in:
parent
311a7bce4b
commit
bfd155510a
|
|
@ -259,8 +259,33 @@ class Home extends BaseController
|
|||
}
|
||||
|
||||
$file = $this->request->getFile('audio');
|
||||
if ($file === null || ! $file->isValid()) {
|
||||
return $this->response->setStatusCode(400)->setJSON(['error' => 'No valid audio file received']);
|
||||
if ($file === null) {
|
||||
// Fallback key for compatibility with alternate STT clients.
|
||||
$file = $this->request->getFile('file');
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'error' => 'No audio file received',
|
||||
'expected_field' => 'audio',
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $file->isValid()) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'error' => 'Invalid uploaded audio file',
|
||||
'upload_error_code' => $file->getError(),
|
||||
'upload_error' => $file->getErrorString(),
|
||||
'upload_max_filesize' => (string) ini_get('upload_max_filesize'),
|
||||
'post_max_size' => (string) ini_get('post_max_size'),
|
||||
]);
|
||||
}
|
||||
|
||||
$fileSize = (int) $file->getSize();
|
||||
if ($fileSize <= 0) {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'error' => 'Empty audio received',
|
||||
]);
|
||||
}
|
||||
|
||||
$lang = (string) ($this->request->getPost('lang') ?? 'en-IN');
|
||||
|
|
@ -294,7 +319,7 @@ class Home extends BaseController
|
|||
->setJSON(['error' => 'STT server unreachable', 'detail' => $curlErr]);
|
||||
}
|
||||
|
||||
$decoded = json_decode($body, true);
|
||||
$decoded = json_decode((string) $body, true);
|
||||
if ($decoded === null) {
|
||||
return $this->response->setStatusCode(502)
|
||||
->setJSON(['error' => 'Invalid response from STT server']);
|
||||
|
|
|
|||
|
|
@ -1207,6 +1207,11 @@
|
|||
medicalSttTarget = '';
|
||||
setMedicalMicButtonState('');
|
||||
|
||||
if (!blob || !blob.size || blob.size < 1024) {
|
||||
$('.jsError').removeClass('text-success text-muted').addClass('text-danger').text('Recording too short. Please record for at least 1-2 seconds.');
|
||||
return;
|
||||
}
|
||||
|
||||
sendMedicalAudioToServer(blob, targetForTranscript).then(function(transcript) {
|
||||
appendTranscriptToField(targetForTranscript, transcript);
|
||||
$('.jsError').removeClass('text-danger text-muted').addClass('text-success').text('Medical speech text added.');
|
||||
|
|
@ -1361,6 +1366,11 @@
|
|||
stopComplaintsMediaStream();
|
||||
setComplaintsMicListening(false);
|
||||
|
||||
if (!blob || !blob.size || blob.size < 1024) {
|
||||
$('.jsError').removeClass('text-success text-muted').addClass('text-danger').text('Recording too short. Please record for at least 1-2 seconds.');
|
||||
return;
|
||||
}
|
||||
|
||||
sendComplaintsAudioToServer(blob).then(function(transcript) {
|
||||
appendTranscriptToComplaints(transcript);
|
||||
$('.jsError').removeClass('text-danger text-muted').addClass('text-success').text('Complaints speech text added.');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user