Skip to content

Sonify API

Hear a data series as pitch over time - an accessibility aid ("hear the trend"): low values map to low notes, high values to high notes, so a rising series sounds like it rises. For the demo with a play button, see the Insights guide.

Try it - press play to hear the trend (the bars are the pure valuesToTones() output):

sonify · hear the trend

Each value becomes a pitch - low value, low note (220 Hz) up to a high note (880 Hz). A rising series sweeps up; a dip dips. sonify() is a graceful no-op without Web Audio, and valuesToTones() (the bars) is pure and testable. An accessibility win: the trend is now audible.

Import

ts
import { sonify, valuesToTones } from "@michi-vz/insights/sonify";
// also re-exported from the package root: import { sonify } from "@michi-vz/insights";

sonify - play a series

ts
await sonify(values, { duration: 3, minFreq: 220, maxFreq: 880 });

Schedules one tone per value via the Web Audio API. It is a graceful no-op where there is no AudioContext (SSR / jsdom / unsupported browsers), so it is safe to call anywhere.

valuesToTones - the pure mapping

ts
const tones = valuesToTones(values, { duration: 3 });
// → [{ time, duration, freq, value }, ...]

Deterministic and testable - the same input always yields the same tones (the demo draws these as bars). Non-finite values are ignored when computing the min/max range.

OptionTypeDefaultWhat it does
durationnumber3Total playback length, in seconds.
minFreqnumber220Pitch (Hz) mapped to the minimum value.
maxFreqnumber880Pitch (Hz) mapped to the maximum value.

Each Tone is { time, duration, freq, value } (seconds / seconds / Hz / source value).

Insights guide

Free and open source. MIT licensed.