@series-inc/stowkit-cli 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,20 @@ function parseAudioInfo(stderr) {
57
57
  }
58
58
  return { sampleRate, numChannels };
59
59
  }
60
+ // ─── WAV data chunk extraction ──────────────────────────────────────────────
61
+ function extractWavData(wav) {
62
+ const view = new DataView(wav.buffer, wav.byteOffset, wav.byteLength);
63
+ let offset = 12; // skip RIFF header (4) + size (4) + WAVE (4)
64
+ while (offset + 8 <= wav.byteLength) {
65
+ const chunkId = String.fromCharCode(wav[offset], wav[offset + 1], wav[offset + 2], wav[offset + 3]);
66
+ const chunkSize = view.getUint32(offset + 4, true);
67
+ if (chunkId === 'data') {
68
+ return wav.slice(offset + 8, offset + 8 + chunkSize);
69
+ }
70
+ offset += 8 + chunkSize;
71
+ }
72
+ throw new Error('WAV data chunk not found');
73
+ }
60
74
  // ─── NodeAacEncoder ─────────────────────────────────────────────────────────
61
75
  export class NodeAacEncoder {
62
76
  async initialize() { }
@@ -105,8 +119,8 @@ export class NodeAudioDecoder {
105
119
  throw new Error(`FFmpeg decode failed (code ${code}): ${ffmpeg.getLastStderr()}`);
106
120
  }
107
121
  const wavBuf = ffmpeg.readFile('/output.wav');
108
- // Skip 44-byte WAV header to get raw PCM f32le data
109
- const rawBuf = wavBuf.slice(44);
122
+ // Find the "data" chunk — WAV headers can be longer than 44 bytes
123
+ const rawBuf = extractWavData(wavBuf);
110
124
  const rawF32 = new Float32Array(rawBuf.buffer, rawBuf.byteOffset, rawBuf.byteLength / 4);
111
125
  const numSamples = Math.floor(rawF32.length / numChannels);
112
126
  // Deinterleave
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@series-inc/stowkit-cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "stowkit": "./dist/cli.js"