---
title: Analysis
order: 7
summary: Tempo and beats, spectrum, and silence.
---

<!-- Generated by tools/generate-docs.bxs from the BIF classes. Do not edit; change the Javadoc and run it again. -->

Tempo and beats, spectrum, and silence.

## audioBpm

Detect the tempo of audio and where its beats fall

```js
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

```js
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

```js
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.

## audioFft

Get the frequency spectrum of one window of audio

```js
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

```js
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

```js
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.

