stream
stream(
source,options?):Promise<AsyncGenerator<Float32Array<ArrayBufferLike>,any,any>>
Defined in: packages/pleco-xa/src/scripts/xa-fileio.js:55
Chunked audio reader (NOT true streaming — honesty note, 2026-07-02).
The whole source is decoded up front via decodeAudioData, then yielded in
fixed-size sample windows: each block is blockLength SAMPLES and the
window advances by hopLength samples, so blockLength > hopLength yields
OVERLAPPING blocks. This is a simplified streaming contract — a true
frame-based streamer would count block_length in FRAMES of
frameLength/hopLength each and read incrementally. Memory use is O(file),
not O(block). For live input use createMediaStreamProcessor instead.
With blockLength === hopLength the blocks are non-overlapping and lossless: ceil(N / blockLength) blocks whose concatenation reproduces the decoded source exactly (proof: examples/web/file-io.html).
Parameters
Section titled “Parameters”source
Section titled “source”string | Blob | File | MediaStream | HTMLMediaElement
Audio source
options?
Section titled “options?”Streaming options
audioContext
Section titled “audioContext”AudioContext
Web Audio context (default: new AudioContext())
blockLength
Section titled “blockLength”number
Number of frames per block (default: 2048)
duration
Section titled “duration”number
Duration to stream in seconds (default: null, entire file)
fillValue
Section titled “fillValue”number
Fill value for incomplete blocks (default: 0.0)
frameLength
Section titled “frameLength”number
Frame length for analysis (default: 2048)
hopLength
Section titled “hopLength”number
Hop length between frames (default: 512)
boolean
Convert to mono (default: true)
offset
Section titled “offset”number
Start time in seconds (default: 0.0)
onBlock
Section titled “onBlock”Function
Callback for each audio block
Returns
Section titled “Returns”Promise<AsyncGenerator<Float32Array<ArrayBufferLike>, any, any>>
Async generator yielding audio blocks
Example
Section titled “Example”// Stream audio file in 2048-sample blocksconst file = document.getElementById('audio-input').files[0];const generator = await stream(file, { blockLength: 2048, mono: true, onBlock: (block) => { // Process each block in real-time const features = mfcc(block); console.log('Block features:', features); }});
// Iterate through blocksfor await (const block of generator) { // Process block console.log('Block shape:', block.length);}