Repository navigation
react-native-audio-analyzer@4.0.0
·
2 commits
to main
since this release
Major Changes
-
e3a7431Thanks @exzos28! - v4: decode once, render many.New API:
analyzeAudio(source, options)decodes a file once, on a background thread with bounded memory, and returnsPeaks: min, max and RMS per bucket asFloat32Arrays. Options:maxBuckets(default 100 000) or an exactframesPerBucket,splitChannels, astart/endrange, cancellation withAbortSignalandonProgress.resample(peaks, bars, { metric, start, end, channel })andresampleMinMax(peaks, bars, options)turn peaks into any number of bars over any time range without decoding again. RMS is weighted by frames; for peaks every bucket belongs to exactly one bar, so a transient is never lost or drawn twice.peaksLevel(peaks, { metric, percentile })computes a reference level over the whole file;normalize/normalizeMinMaxscale values linearly or in decibels against it, so zooming never rescales the waveform.waveformPathbuilds SVG/Skia paths;fitBarscomputes how many bars fit.useWaveform(source, options)React hook: status, progress, cancellation on unmount or source change,barsas a plain array, display errors reported as state, and analysis options kept separate from display options.waveformPresets.chat,.playerand.editor: plain option objects tuned for voice messages, scrubbers and precise views.getAudioInfo(source)returns format, sample rate, channel count and duration.encodePeaks/decodePeaksserialize peaks in a versioned, forward-compatible binary format (8, 16 or 32 bits per value).- Sources can be file paths,
file://URIs,http(s)://URLs (downloaded and cached),{ uri, headers }orArrayBuffers with encoded audio. load(url, { headers })shares concurrent downloads of the same URL and headers;clearCache()andgetCacheSize(). Headers are never forwarded to another origin on redirects.
Breaking changes:
computeAmplitudeis removed. Useresample(await analyzeAudio(source), n)oruseWaveform.- The v3 example helpers (
scale,sample,robustScale,trimmedScale) are replaced byresample,normalizeandpeaksLevel. load()only acceptshttp:///https://URLs. Files are cached by the full URL in the app's caches directory; non-2xx responses reject and are never cached; interrupted downloads no longer leave truncated files behind. Files cached by v3 are not reused;clearCache()removes them andgetCacheSize()counts them.- Requires
react-native-nitro-modules^0.37.1.
Fixes:
- Analysis no longer drops the last frames when the container states a shorter duration than the decoder delivers: without an
end, it reads to the end of the stream. - Fractional or negative sample counts no longer read out of bounds or divide by zero.
- Android: the downloader has the no-argument constructor that Nitro's autolinking requires, and follows redirects between
httpandhttps. - miniaudio is compiled with optimizations even in debug builds. Previously Android debug builds compiled it at -O0 (Gradle's
cppFlagsdon't apply to C files), which made a 6-minute MP3 take ~10 s instead of ~0.2 s on an emulator; iOS Debug had the same issue. - miniaudio updated to 0.11.25 and built decode-only (no playback/capture backends), which shrinks the native binary and drops the AVFoundation/OpenSL ES dependencies.
- New formats: OGG Vorbis on every platform (built-in, via stb_vorbis), and everything the operating system can decode through a platform decoder called directly from C++ — AAC/M4A on iOS and Android, ALAC/AIFF/CAF on iOS, Opus on Android.
getAudioInforeports the detected codec and which decoder was used.