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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
minBpm | double | 60 | Lowest tempo to consider. Defaults to 60. |
maxBpm | double | 200 | Highest 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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
bands | integer | 16 | How many bands. Defaults to 16. |
minHz | double | 40 | Lower edge of the first band. Defaults to 40. |
maxHz | double | 16000 | Upper edge of the last band, capped at half the sample rate. Defaults to 16000. |
start | double | 0 | Start in seconds. Defaults to 0. |
seconds | double | 0 | Length 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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
bands | integer | 16 | How many bands. Defaults to 16. |
frames | integer | 64 | How many time slices. Defaults to 64. |
minHz | double | 40 | Lower edge of the first band. Defaults to 40. |
maxHz | double | 16000 | Upper 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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
width | integer | 800 | Pixels across, 8 to 8192. Defaults to 800. |
height | integer | 160 | Pixels down, 8 to 4096. Defaults to 160. |
format | string | "" | svg or png. Left out, it follows the extension of path, and is svg when there is none. |
path | string | "" | A file to write the picture to. Folders are created and an existing file is replaced. |
color | string | "#3b82f6" | The color of the waveform as a hex color, #rgb, #rrggbb or #rrggbbaa. Defaults to #3b82f6. |
background | string | "" | The color behind it as a hex color. Left out it is transparent. |
style | string | "filled" | filled for a continuous shape, or bars for separate bars. Defaults to filled. |
split | boolean | false | True 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" )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
width | integer | 800 | Pixels across, 8 to 4000. Each column is one slice of time. Defaults to 800. |
height | integer | 256 | Pixels up, 8 to 512. Each row is one band of frequencies. Defaults to 256. |
format | string | "" | 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. |
path | string | "" | A file to write the picture to. Folders are created and an existing file is replaced. |
minHz | double | 40 | The lowest frequency shown. Defaults to 40. |
maxHz | double | 16000 | The highest frequency shown. Defaults to 16000. |
rangeDb | double | 80 | How many dB below the loudest point still show, 10 to 120. Defaults to 80. |
scale | string | "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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
size | integer | 2048 | FFT size, a power of two. Defaults to 2048. |
start | double | 0 | Where 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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
thresholdDb | double | -50 | Level below which audio counts as silent, in dB. Defaults to -50. |
minSeconds | double | 0.3 | The 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 )
| Argument | Type | Default | |
|---|---|---|---|
audio | any | required | The audio buffer. |
thresholdDb | double | -50 | Level below which audio counts as silent, in dB. Defaults to -50. |
pad | double | 0 | Seconds of silence to keep on each side. Defaults to 0. |
Returns A new audio buffer.