Analysis

Tempo and beats, spectrum, pictures of the waveform and the spectrogram, and silence.

On this page

Tempo and beats, spectrum, pictures of the waveform and the spectrogram, and silence.

audioBpm

Detect the tempo of audio and where its beats fall

audioBpm( audio, minBpm=60, maxBpm=200 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
minBpmdouble60Lowest tempo to consider. Defaults to 60.
maxBpmdouble200Highest tempo to consider. Defaults to 200.

Returns A struct with bpm (0 if there is no clear pulse), confidence (0 to 1) and beats, the beat times in seconds.

audioSpectrum

Get the level of audio in log spaced frequency bands, in dB

audioSpectrum( audio, bands=16, minHz=40, maxHz=16000, start=0, seconds=0 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
bandsinteger16How many bands. Defaults to 16.
minHzdouble40Lower edge of the first band. Defaults to 40.
maxHzdouble16000Upper edge of the last band, capped at half the sample rate. Defaults to 16000.
startdouble0Start in seconds. Defaults to 0.
secondsdouble0Length to analyse in seconds, 0 for the rest. Defaults to 0.

Returns An array of band levels in dB, lowest frequency first. -120 means nothing.

audioSpectrogram

Get the band levels of audio over time, for drawing or analysis

audioSpectrogram( audio, bands=16, frames=64, minHz=40, maxHz=16000 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
bandsinteger16How many bands. Defaults to 16.
framesinteger64How many time slices. Defaults to 64.
minHzdouble40Lower edge of the first band. Defaults to 40.
maxHzdouble16000Upper edge of the last band. Defaults to 16000.

Returns An array of frames, each an array of band levels in dB.

audioWaveformImage

Draws how loud a sound is over time, the way a player or an editor shows it. For each column of the picture the highest and lowest sample are drawn pale and the average level (RMS) solid, so a loud, steady sound and a sparse, peaky one look different. Silence is a thin line. The picture can go in a web page, a report or a podcast page.

audioWaveformImage( audio, width=800, height=160, format="", path="", color="#3b82f6", background="", style="filled", split=false )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
widthinteger800Pixels across, 8 to 8192. Defaults to 800.
heightinteger160Pixels down, 8 to 4096. Defaults to 160.
formatstring""svg or png. Left out, it follows the extension of path, and is svg when there is none.
pathstring""A file to write the picture to. Folders are created and an existing file is replaced.
colorstring"#3b82f6"The color of the waveform as a hex color, #rgb, #rrggbb or #rrggbbaa. Defaults to #3b82f6.
backgroundstring""The color behind it as a hex color. Left out it is transparent.
stylestring"filled"filled for a continuous shape, or bars for separate bars. Defaults to filled.
splitbooleanfalseTrue to give each channel of a stereo sound its own lane. Defaults to false, which draws both over one another.

Returns The absolute path of the file when path is given. Otherwise the SVG as a string, or the PNG as binary data.

audioSpectrogramImage

Draws which frequencies are in a sound and when: time runs across, frequency up (low at the bottom, on a log scale like hearing) and loudness is the color. A steady tone is a horizontal line, a drum hit a vertical smear, speech a pattern of bands. The color scale is set by the loudest point of the picture, so quiet and loud recordings both fill the range.

audioSpectrogramImage( audio, width=800, height=256, format="", path="", minHz=40, maxHz=16000, rangeDb=80, scale="magma" )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
widthinteger800Pixels across, 8 to 4000. Each column is one slice of time. Defaults to 800.
heightinteger256Pixels up, 8 to 512. Each row is one band of frequencies. Defaults to 256.
formatstring""png or svg. Left out, it follows the extension of path, and is png when there is none. The SVG holds the PNG, since a spectrogram has a color for every point.
pathstring""A file to write the picture to. Folders are created and an existing file is replaced.
minHzdouble40The lowest frequency shown. Defaults to 40.
maxHzdouble16000The highest frequency shown. Defaults to 16000.
rangeDbdouble80How many dB below the loudest point still show, 10 to 120. Defaults to 80.
scalestring"magma"The colors, from quiet to loud: magma, viridis or gray. Defaults to magma.

Returns The absolute path of the file when path is given. Otherwise the PNG as binary data, or the SVG as a string.

audioFft

Get the frequency spectrum of one window of audio

audioFft( audio, size=2048, start=0 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
sizeinteger2048FFT size, a power of two. Defaults to 2048.
startdouble0Where the window starts, in seconds. Defaults to 0.

Returns A struct with frequencies (Hz) and magnitudes (1 for a full scale sine), arrays of size/2+1 values.

audioDetectSilence

Find the silent stretches of audio

audioDetectSilence( audio, thresholdDb=-50, minSeconds=0.3 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
thresholdDbdouble-50Level below which audio counts as silent, in dB. Defaults to -50.
minSecondsdouble0.3The shortest silence to report. Defaults to 0.3.

Returns An array of structs with start, end and duration in seconds.

audioTrimSilence

Cut the silence off the start and the end of audio

audioTrimSilence( audio, thresholdDb=-50, pad=0 )
ArgumentTypeDefault
audioanyrequiredThe audio buffer.
thresholdDbdouble-50Level below which audio counts as silent, in dB. Defaults to -50.
paddouble0Seconds of silence to keep on each side. Defaults to 0.

Returns A new audio buffer.

Edit this page Download Markdown Last updated Nov 26, 2026, 11:36:03 AM Report an issue