From 72e91e940c8ec93c52cc7cfaa0908361f098a6ef Mon Sep 17 00:00:00 2001 From: ifedan-ed Date: Sun, 29 Mar 2026 01:21:43 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20chunk=20size=20to=208KB=20=E2=80=94=20?= =?UTF-8?q?larger=20sizes=20cause=20AWS=20deserialization=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep 8KB CHUNK_SIZE (proven stable) but replace 10ms setTimeout delay with a microtask break every 16 chunks. This avoids the AWS SDK "Deserialization error: inspect {error}.\$response" while still eliminating the ~1.25s/MB artificial delay from the old 10ms sleep. --- src/utils/transcribeAWS.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/utils/transcribeAWS.js b/src/utils/transcribeAWS.js index 2e8b414..ad3d378 100644 --- a/src/utils/transcribeAWS.js +++ b/src/utils/transcribeAWS.js @@ -59,11 +59,16 @@ function convertToPCM(inputBuffer) { } async function* makeAudioStream(buffer) { - // Send chunks as fast as possible — AWS handles backpressure via HTTP/2 flow control. - // Larger chunks (32KB) reduce overhead and speed up streaming significantly. - var streamChunkSize = 32768; // 32 KB (AWS max per event frame) - for (var i = 0; i < buffer.length; i += streamChunkSize) { - yield { AudioEvent: { AudioChunk: buffer.slice(i, i + streamChunkSize) } }; + // 8KB chunks — larger sizes cause AWS SDK deserialization errors + // ("to see the raw response, inspect the hidden field {error}.$response"). + // No artificial delay between chunks; yield with a microtask break + // to avoid blocking the event loop without adding real latency. + for (var i = 0; i < buffer.length; i += CHUNK_SIZE) { + yield { AudioEvent: { AudioChunk: buffer.slice(i, i + CHUNK_SIZE) } }; + // Microtask break every 16 chunks (~128KB) to keep event loop responsive + if ((i / CHUNK_SIZE) % 16 === 15) { + await new Promise(function(r) { setImmediate(r); }); + } } }