Skip to content

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).

string | Blob | File | MediaStream | HTMLMediaElement

Audio source

Streaming options

AudioContext

Web Audio context (default: new AudioContext())

number

Number of frames per block (default: 2048)

number

Duration to stream in seconds (default: null, entire file)

number

Fill value for incomplete blocks (default: 0.0)

number

Frame length for analysis (default: 2048)

number

Hop length between frames (default: 512)

boolean

Convert to mono (default: true)

number

Start time in seconds (default: 0.0)

Function

Callback for each audio block

Promise<AsyncGenerator<Float32Array<ArrayBufferLike>, any, any>>

Async generator yielding audio blocks

// Stream audio file in 2048-sample blocks
const 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 blocks
for await (const block of generator) {
// Process block
console.log('Block shape:', block.length);
}