Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(speech): copy base64 pcm out of the Buffer pool — alignment is not an API guarantee (Task 2 review)

enesda898c8cb4ab
diff --git a/src/core/speech/pcm.test.ts b/src/core/speech/pcm.test.ts
index ba06e36ca..c322920de 100644
--- a/src/core/speech/pcm.test.ts
+++ b/src/core/speech/pcm.test.ts
@@ -30,6 +30,8 @@ describe('pcm helpers', () => {
expect(Array.from(fromBuffer)).toEqual(Array.from(src))
const b64 = Buffer.from(float32ToInt16(src).buffer).toString('base64')
const fromB64 = decodePcmPayload(b64)
+ expect(fromB64[0]).toBeCloseTo(0.25, 2)
+ expect(fromB64[1]).toBeCloseTo(-0.25, 2)
expect(fromB64[2]).toBeCloseTo(0.75, 2)
})
})
diff --git a/src/core/speech/pcm.ts b/src/core/speech/pcm.ts
index d2acc8079..55948e529 100644
--- a/src/core/speech/pcm.ts
+++ b/src/core/speech/pcm.ts
@@ -47,7 +47,12 @@ export function pcmToWav(pcm: Float32Array, sampleRate = 16000): Uint8Array {
export function decodePcmPayload(payload: ArrayBuffer | string): Float32Array {
if (typeof payload === 'string') {
const raw = Buffer.from(payload, 'base64')
- return int16ToFloat32(new Int16Array(raw.buffer, raw.byteOffset, raw.byteLength / 2))
+ // Copy out of the Buffer pool: a typed-array view over raw.buffer would
+ // depend on the pool's (undocumented) alignment — an odd byteOffset makes
+ // Int16Array throw. The copy also detaches us from pool reuse.
+ const bytes = new Uint8Array(raw.byteLength)
+ bytes.set(raw)
+ return int16ToFloat32(new Int16Array(bytes.buffer))
}
return new Float32Array(payload)
}