Revert chunk size to 8KB — larger sizes cause AWS deserialization errors
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.
This commit is contained in:
parent
35f03ac0ba
commit
72e91e940c
1 changed files with 10 additions and 5 deletions
|
|
@ -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); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue