/** * Streaming helpers — `audiobox/stream`. * * The `Audio` API holds an entire file in memory, which is the right default: * most audio a web app touches is a few minutes long, and random access makes * editing far simpler. It stops being right for long recordings, batch server * jobs, and anywhere memory is capped. * * These transforms work on chunks instead. They use the WHATWG Streams API, * available natively in browsers, Node 18+, Deno, Bun, and Cloudflare Workers — * so the same pipeline runs everywhere without a shim. */ import { decodeWav } from '../formats/wav.js'; import type { SampleFormat } from '../types.js'; import type { ResampleOptions } from '../dsp/resample.js'; /** A chunk of decoded audio flowing through a pipeline. */ export interface AudioChunk { /** Planar samples, one array per channel. */ channels: Float32Array[]; sampleRate: number; /** Frame index of this chunk's first sample within the whole stream. */ offset: number; } export interface PcmStreamOptions { sampleFormat?: SampleFormat; channels?: number; sampleRate?: number; littleEndian?: boolean; /** Frames per emitted chunk. Defaults to 8192. */ chunkFrames?: number; } /** * Converts a byte stream of raw PCM into {@link AudioChunk}s. * * Handles chunk boundaries that fall mid-frame — a network or file stream splits * wherever it likes, and a decoder that assumes whole frames per chunk produces * clicks or channel-swapped audio at every boundary. */ export declare function createPcmDecodeStream(options?: PcmStreamOptions): { readable: unknown; writable: unknown; }; /** Converts {@link AudioChunk}s back into raw PCM bytes. */ export declare function createPcmEncodeStream(options?: PcmStreamOptions): { readable: unknown; writable: unknown; }; /** Applies a gain, in decibels, to every chunk. */ export declare function createGainStream(db: number): { readable: unknown; writable: unknown; }; /** Converts every chunk to a different channel count. */ export declare function createChannelStream(count: number): { readable: unknown; writable: unknown; }; /** * Resamples a stream. * * Note the caveat: each chunk is resampled independently, so the filter has no * history across boundaries and a faint discontinuity can appear there. That is * an acceptable trade for constant memory on a long stream, but for a file you * will keep, decode fully and use `Audio.resample()`, which is continuous. */ export declare function createResampleStream(targetRate: number, options?: ResampleOptions): { readable: unknown; writable: unknown; }; /** * Collects a stream of chunks into a single WAV file. * * WAV's header declares the data length, which is not known until the stream * ends — so this buffers. It is a convenience for "stream in, file out", not a * constant-memory path. */ export declare function collectToWav(chunks: AsyncIterable, options?: { sampleFormat?: SampleFormat; }): Promise; /** Re-exported so a streaming pipeline can finish with a normal decode. */ export { decodeWav }; //# sourceMappingURL=index.d.ts.map