Coming from librosa
This page is the lookup table: it maps librosa 1.0 onto
the audio_samples Python API, function by function. If you are deciding whether
to move, or doing the move, start with Moving from librosa. This page covers every public function of librosa (the core,
including librosa.convert), librosa.feature, effects, onset,
beat, decompose, filters, util, segment, sequence and
display. For each one it gives the Python equivalent and how closely it
matches, then collects every documented difference.
The librosa-compatible API is tested against golden fixtures produced by
librosa 1.0.0 and, where librosa is installed, against librosa directly (the
tests/test_librosa_*.py suites). The tolerances, and the reasons for them,
are in those tests.
Conventions
The audio carries its sample rate. librosa passes y and sr
separately. An AudioSamples holds the samples, the
sample rate and the channel layout, so its methods take no sr argument.
Free functions over NumPy arrays (audio_samples.spectral, features,
rhythm, effects, sequence, utils) keep librosa’s sr
keyword where librosa has one (some utils conversions call it
sample_rate).
Two entry points. librosa’s y= forms are AudioSamples methods.
librosa’s S=, onset_envelope=, chroma= and tg= forms, and the
filterbanks and helpers, are free functions in the submodules:
Submodule |
Contents |
|---|---|
|
STFT/ISTFT, dB conversions, mel filterbank, windows, MFCC from
a mel spectrogram, |
|
|
|
onset strength and detection, peak picking, tempograms, tempo, beat tracking, PLP |
|
phase vocoder, emphasis filters, HPSS, |
|
DTW, Viterbi, transition matrices, recurrence, RQA, |
|
unit, frame/time, tuning, octave and key conversions |
|
tones, chirps, other test signals and named example clips |
|
reading and writing audio files |
|
extrema, matching, interpolation, padding, sparse rows, zero crossings, tones and sweeps, argument checks |
|
array forms of methods with their extra options |
|
NNLS, pseudo-inverse, eigendecomposition, SVD |
|
mel and MFCC inversion |
|
NMF and |
|
semitone filterbank, IIR time-frequency representation |
|
path enhancement, time-lag filtering, clustering |
|
tuning, note, FJS, svara, mela and thaat names |
Methods return (channels, F, T). Every frame-wise method returns a
NumPy array with a leading channel axis, also for mono audio:
(channels, n_features, n_frames), and (channels, 1, n_frames) for
per-frame scalars such as the centroid or RMS. Onset envelopes and pitch tracks
are (channels, n_frames). librosa drops the leading axis for 1-D input, so
index [0] to get librosa’s mono shape:
import numpy as np
import audio_samples as aus
audio = aus.generation.sine_wave(440.0, 1.0, 22050, 0.5, dtype=np.float32)
S = audio.melspectrogram() # (1, 128, n_frames) for mono audio
S_mono = S[0] # librosa.feature.melspectrogram(y=y, sr=sr).shape
Free functions follow librosa’s shapes exactly (a 1-D signal gives a 2-D STFT, a scalar gives a Python float).
Keyword names follow librosa 1.0. Parameter names and keyword-only markers
are librosa’s, so audio.mfcc_frames(n_mfcc=13, lifter=22, top_db=80.0)
means what librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13, lifter=22) means.
Defaults equal librosa’s except where librosa’s default changes the data
without being asked (an 80 dB dynamic-range floor, tuning estimation, beat
trimming, unseeded random phases, snapping to zero crossings) and where the
value has to come from the caller (the sr of the free functions, the hop
length of frames computed elsewhere, the trim threshold); see
Defaults that differ from librosa. inspect.signature and help()
work on every function. Unsupported librosa options raise ValueError or
TypeError; they are never silently ignored.
Output precision follows the input. AudioSamples analysis methods
return float32 / complex64 arrays for uint8, int16, int24
and float32 audio, and float64 / complex128 arrays for int32
and float64 audio (the smallest float type that holds every sample value
exactly). Free functions over NumPy arrays compute in float32 for a
float32 or complex64 array and in float64 for any other input
(lists, integer arrays, float16 and float64 arrays are converted to
float64). Audio-returning methods (time_stretch, preemphasis,
trim_db, …) return the receiver’s sample type; the static
reconstructions (istft_matrix, icqt, griffinlim_cqt,
griffinlim_audio) take dtype= and otherwise return float32 audio
for a single-precision matrix and float64 audio for anything else.
librosa also keeps float32 for float32 input, but several of its bases
(mel, chroma, CQT wavelets) default to single precision even for float64
input; pass dtype=np.float64 to librosa to compare float64 output to
round-off. Integer audio is converted with this library’s audio-aware scaling:
negative values are divided by 2**(bits-1) and positive ones by
2**(bits-1) - 1 (librosa’s buf_to_float divides both by
2**(bits-1)), so compare with float audio.
Non-finite audio raises. As librosa’s valid_audio does (“Audio buffer
is not finite everywhere”), the librosa-compatible methods raise
ValueError when the audio contains a NaN or an infinity. This is slightly
stricter than librosa, which skips the check in a few functions (e.g.
preemphasis). Free functions over arrays do not check.
Errors. Invalid parameters raise ValueError naming the parameter
("n_fft: must be a positive integer, got -1"), wrong types TypeError,
and failures inside a computation RuntimeError.
The GIL is released. File reads, to_mono, resample and the heavy
computations (STFT, CQT, features, pitch tracking, onset envelopes, beat tracking,
effects, DTW) run without the GIL, so several Python threads can analyse different
signals in parallel. Exceptions that hold it: a Python callable given as aggregate
or prior, tempo’s tempo estimate (not its onset envelope) and
StreamedAudioReader. See Threads and free-threaded Python for what threads may share and for
free-threaded Python.
Some librosa names belong to other methods. Where a method of the library’s
own API has a librosa name, the librosa-compatible version has another name
(see Methods that are not librosa-compatible): stft_matrix (not
stft), mfcc_frames (not mfcc), spectral_centroid_frames (not
spectral_centroid), trim_db (not trim), split_db (not
split), harmonic_percussive (not hpss).
Examples
Each example runs as written (librosa’s call is in the comment). A generated
tone takes the place of librosa.load; read a file with
audio_samples.io.read("file.wav").
STFT and inverse STFT
import numpy as np
import audio_samples as aus
# librosa: y, sr = librosa.load(...); here the audio carries its rate.
y = aus.generation.sine_wave(440.0, 1.0, 22050, 0.5, dtype=np.float64)
assert y.sample_rate == 22050
# D = librosa.stft(y) -> librosa (1025, 44); here (channels, 1025, 44)
D = y.stft_matrix()
assert D.shape == (1, 1025, 44) and D.dtype == np.complex128
# y_hat = librosa.istft(D, length=len(y))
y_hat = aus.AudioSamples.istft_matrix(D, sample_rate=22050, length=y.samples_per_channel())
assert np.allclose(y_hat.to_numpy(), y.to_numpy(), atol=1e-9)
Mel spectrogram in dB, MFCC and deltas
import numpy as np
import audio_samples as aus
from audio_samples import spectral
y = aus.generation.sine_wave(440.0, 1.0, 22050, 0.5, dtype=np.float64)
# S = librosa.feature.melspectrogram(y=y, sr=sr)
S = y.melspectrogram()
assert S.shape == (1, 128, 44)
# S_db = librosa.power_to_db(S, ref=np.max) (librosa's default top_db is 80)
S_db = spectral.power_to_db(S, ref=np.max, top_db=80.0)
assert abs(S_db.max()) < 1e-9 and S_db.min() >= -80.0
# mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13); librosa.feature.delta(mfcc, order=2)
mfcc = y.mfcc_frames(n_mfcc=13, top_db=80.0)
d2 = spectral.delta(mfcc, order=2)
assert mfcc.shape == d2.shape == (1, 13, 44)
Spectral features and chroma
import numpy as np
import audio_samples as aus
y = aus.generation.sine_wave(440.0, 1.0, 22050, 0.5, dtype=np.float64)
centroid = y.spectral_centroid_frames() # librosa.feature.spectral_centroid(y=y, sr=sr)
rms = y.rms_frames() # librosa.feature.rms(y=y)
zcr = y.zero_crossing_rate_frames() # librosa.feature.zero_crossing_rate(y)
assert centroid.shape == rms.shape == zcr.shape == (1, 1, 44)
assert abs(centroid[0, 0, 20] - 440.0) < 20.0
chroma = y.chroma_stft(tuning=None) # librosa.feature.chroma_stft(y=y, sr=sr)
assert chroma.shape == (1, 12, 44)
assert chroma[0, 9, 20] == 1.0 # pitch class A
Onsets, tempo and beats
import numpy as np
import audio_samples as aus
# A decaying click every 0.5 s (120 BPM) for 4 s.
sr = 22050
x = np.zeros(4 * sr)
for k in range(8):
x[k * sr // 2 : k * sr // 2 + 200] = np.exp(-np.arange(200) / 30.0)
y = aus.AudioSamples.new_mono(x, sr)
env = y.onset_strength() # librosa.onset.onset_strength(y=y, sr=sr)
assert env.shape[0] == 1 # (channels, n_frames); env[0] is librosa's
onset_times = y.onset_detect(units="time") # librosa.onset.onset_detect(..., units="time")
assert len(onset_times) >= 7
# librosa.beat.beat_track(y=y, sr=sr, units="time") (librosa trims by default)
tempo, beats = y.beat_track(units="time", trim=True)
assert abs(float(tempo[0]) - 120.0) < 5.0 and len(beats) > 0
Effects and resampling
import numpy as np
import audio_samples as aus
y = aus.generation.sine_wave(440.0, 1.0, 22050, 0.5, dtype=np.float64)
n = y.samples_per_channel()
fast = y.time_stretch(2.0) # librosa.effects.time_stretch(y, rate=2.0)
assert fast.samples_per_channel() == n // 2
up = y.pitch_shift(2.0) # librosa.effects.pitch_shift(y, sr=sr, n_steps=2)
assert up.samples_per_channel() == n
trimmed, (start, end) = y.trim_db(top_db=60.0) # librosa.effects.trim(y)
assert trimmed.samples_per_channel() == end - start
y16 = y.resample(16000, "high") # librosa.resample(y, orig_sr=22050, target_sr=16000)
assert y16.samples_per_channel() == 16000
Pitch tracking
import numpy as np
import audio_samples as aus
y = aus.generation.sine_wave(220.0, 0.5, 22050, 0.5, dtype=np.float64)
f0 = y.yin(fmin=65.4, fmax=2093.0) # librosa.yin(y, fmin=65.4, fmax=2093.0, sr=sr)
assert abs(f0[0, 11] - 220.0) < 1.0
f0, voiced_flag, voiced_prob = y.pyin(fmin=65.4, fmax=2093.0) # librosa.pyin(...)
assert voiced_flag[0, 11] and abs(f0[0, 11] - 220.0) < 2.0
Equivalence tables
Status values:
equivalent: same results as librosa with the same arguments, to floating-point round-off; event outputs (frames, beats, paths) identical.
with differences: the same algorithm with a documented difference in dtype, options or edge cases (see the notes and Differences from librosa).
not provided: no counterpart, with the reason.
AudioSamples.x is a method (audio.x(...)); spectral.x,
features.x, rhythm.x, effects.x, sequence.x, utils.x,
arrays.x, linalg.x, inverse.x, factorization.x,
pitch_filterbank.x, segment.x, notation.x, generation.x and io.x are functions in the audio_samples submodule of that name.
python -m audio_samples.migrate applies these tables to your code, call by
call (see Checking your code). It reads the same facts from
audio_samples/_migrate_table.py, and the test suite checks that module
against these tables.
Core: audio
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
No automatic resampling to 22050 Hz or mixing to mono: the file’s own
rate, channels and sample type are kept ( |
|
|
with differences |
An |
|
|
with differences |
Block reader over WAV/FLAC with its own interface:
|
|
|
with differences |
|
|
|
with differences |
Audio only; no |
|
|
with differences |
Own windowed-sinc resampler, not soxr; |
|
|
equivalent |
Default method is the channel average |
|
|
with differences |
|
|
|
with differences |
No pad or trim to a common length |
|
|
with differences |
First channel only; unbiased estimate: |
|
|
equivalent |
Burg’s method; one row per channel |
|
|
with differences |
Returns a count, not a boolean mask; use |
|
|
with differences |
float64 output unless |
|
|
with differences |
No |
|
|
with differences |
No |
|
|
equivalent |
|
|
|
equivalent |
As |
Core: spectral representations
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
equivalent |
All |
|
|
with differences |
A bin count that does not match |
|
|
with differences |
2-D complex64 or complex128 input |
|
|
equivalent |
|
|
|
equivalent |
The deprecated |
|
|
with differences |
|
|
|
with differences |
The two lower rates use this library’s resampler |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
As above |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
Lower-case names |
Core: constant-Q
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
Octave decimation uses this library’s resampler, not soxr: the top octave matches to round-off, lower octaves to ~1e-4 of the peak |
|
|
with differences |
As |
|
|
equivalent |
No resampling involved (librosa’s |
|
|
with differences |
Low octaves as |
|
|
with differences |
Upsampling uses this library’s resampler |
|
|
with differences |
|
Core: pitch, tuning and harmonics
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
equivalent |
|
|
|
equivalent |
Returns |
|
|
equivalent |
|
|
|
equivalent |
Pools all channels, as librosa does |
|
|
equivalent |
|
|
|
with differences |
Linear interpolation along the frequency axis; |
|
|
equivalent |
Interpolants other than linear, and other axes, need a 1-D frequency grid |
|
|
equivalent |
Interpolants other than linear, and other axes, need a 1-D frequency grid |
Core: unit conversions (librosa.convert)
The librosa-compatible conversions in audio_samples.utils are vectorised
like librosa’s: a scalar gives a Python number, an array-like an array of the
same shape. They take librosa’s sr keyword or sample_rate;
one of them is required (librosa defaults to 22050), and so is hop_length
where librosa defaults it to 512. The note-name functions take a scalar or an
array-like; for an array they return a list of names or an array of values.
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
equivalent |
|
|
|
with differences |
Positional |
|
|
equivalent |
|
|
|
with differences |
Positional |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
Positional |
|
|
with differences |
Default is HTK; librosa’s default is Slaney |
|
|
with differences |
As above |
|
|
with differences |
As above |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
Returns |
|
|
with differences |
Integer MIDI 0..127 (an array gives a list of names); ASCII |
|
|
with differences |
Name or sequence of names; grammar and limits as |
|
|
with differences |
Name or sequence of names; librosa’s grammar (accidentals, cents suffix); the octave is required and the result is in 0..127 |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
Lower-case name |
|
|
equivalent |
Lower-case name |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
Recognises any ratio built from the primes up to 23 |
|
|
with differences |
As |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
librosa.feature
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
float64 mel basis (librosa’s default float32 basis: ~1e-7 relative) |
|
|
with differences |
float64 mel basis; |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
A band with no FFT bin raises |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
A rank-deficient fit raises (NumPy warns and returns a minimum-norm solution) |
|
|
with differences |
Output precision follows the sample type (librosa’s default
|
|
|
equivalent |
|
|
|
with differences |
float64 chroma basis; |
|
|
with differences |
Inherits the CQT resampler difference; |
|
|
with differences |
As |
|
|
with differences |
As |
|
|
with differences |
As |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
The method returns |
|
|
with differences |
Custom |
|
|
equivalent |
|
|
|
with differences |
|
|
|
with differences |
A better fit than librosa’s early-stopped L-BFGS-B; energy within 15 % |
|
|
with differences |
As |
|
|
equivalent |
|
|
|
with differences |
|
librosa.effects
Audio-to-audio effects return a new AudioSamples of the input’s sample
type; each has an _in_place twin (time_stretch_in_place, …).
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
equivalent |
Exactly |
|
|
with differences |
Final resampling by this library’s resampler, not soxr (~68 dB SNR);
|
|
|
equivalent |
The function takes |
|
|
equivalent |
|
|
|
with differences |
Returns |
|
|
with differences |
int64 |
|
|
equivalent |
|
|
|
with differences |
|
|
|
with differences |
As |
|
|
with differences |
As |
librosa.onset and librosa.beat
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
equivalent |
float64 mel basis |
|
|
with differences |
The method’s |
|
|
with differences |
Mono audio only; |
|
|
with differences |
No events give an empty array (librosa raises) |
|
|
with differences |
Mono audio only; |
|
|
equivalent |
librosa.decompose
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
No scikit-learn needed; |
|
|
equivalent |
Kernel sizes, power, margins, |
|
|
with differences |
Dense or |
librosa.filters
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
equivalent |
Periodic ( |
|
|
with differences |
float64 weights (librosa |
|
|
with differences |
float64 weights |
|
|
with differences |
|
|
|
with differences |
complex128 filters (librosa: complex64) |
|
|
with differences |
An explicit |
|
|
with differences |
Always evaluates the formula; librosa returns a table value for named windows (up to ~1e-4 relative apart) |
|
|
equivalent |
float64 output unless |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
librosa.util
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
1-D input, last-axis framing. A writable copy by default; |
|
|
equivalent |
|
|
|
with differences |
1-D input |
|
|
with differences |
An empty index list gives one segment |
|
|
equivalent |
|
|
|
with differences |
Pads only; a longer signal is returned unchanged |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
Index outputs are int64; ties between targets at one position may pick another of the equal targets |
|
|
with differences |
Index outputs are int64; with |
|
|
with differences |
A matrix |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
A complex scalar gives a float rather than a 0-d array |
|
|
with differences |
Integer angles give complex128 |
|
|
equivalent |
|
|
|
with differences |
Positions out of increasing order reorder the axes |
|
|
with differences |
C order for every axis; same values |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
Also 3-byte samples; |
|
|
equivalent |
|
|
|
with differences |
Stable sort, so equal keys keep their order |
|
|
with differences |
Returns |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
– |
not provided |
Deprecation plumbing of librosa itself |
|
|
with differences |
Returns audio rather than a file path. The clips are synthesised, so they are not
librosa’s recordings; see |
|
|
with differences |
Returns a list of names rather than printing a table |
|
|
with differences |
One sentence on a synthesised clip |
|
|
with differences |
Any letter case matches with |
|
– |
not provided |
Citation helper of librosa itself |
librosa.segment and librosa.sequence
All in audio_samples.sequence, on (n_features, n_frames) arrays.
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
|
|
|
with differences |
As |
|
|
equivalent |
Dense input |
|
|
equivalent |
Dense input |
|
|
equivalent |
The convolution options are |
|
|
equivalent |
Returns a callable object
|
|
|
equivalent |
No scikit-learn needed; a |
|
|
equivalent |
|
|
|
equivalent |
int64 paths |
|
|
equivalent |
|
|
|
with differences |
Same scores; the path through the second column follows the move actually taken (librosa stores a wrong back-pointer there) |
|
|
equivalent |
int64 states (librosa: uint16) |
|
|
equivalent |
As |
|
|
with differences |
States are |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
librosa.display
The plots are in audio_samples.mpl, under this library’s names.
librosa |
audio_samples |
status |
notes |
|---|---|---|---|
|
|
with differences |
Every axis type, |
|
|
with differences |
Takes |
|
|
with differences |
Returned by |
|
|
with differences |
|
|
|
with differences |
|
|
|
with differences |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
Keywords are |
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
equivalent |
|
|
|
with differences |
|
Differences from librosa
These are the differences documented in the API reference (Spectral Analysis, Features, Tonal, Constant-Q and Pitch Analysis, Rhythm: Onsets, Tempo and Beats, Effects and Decomposition, Sequence Alignment and Decoding) and in the Rust crate’s migration guide, gathered by theme.
Shapes and types
The channel axis is always present on
AudioSamplesmethods:(channels, F, T)for frame-wise features,(channels, T)for onset envelopes and pitch tracks,(channels, 1)for a static tempo. Index[0]for librosa’s mono shape.tempogram_ratiowithaggregatekeeps a(channels, n_factors, 1)shape where librosa drops the last axis.Output precision follows the input (see Conventions). Several librosa bases default to single precision even for
float64input. Here they are computed infloat64and rounded once to the output type, sofloat64output differs from librosa’s defaults by about 1e-7 relative:the mel basis (
filters.mel, hencemelspectrogram,mfcc,onset_strength);the chroma basis (
filters.chroma,chroma_stft);CQT wavelets (
filters.wavelet): librosa’scomplex64filters move its top-octave CQT by up to ~4e-8 of the peak;rmsand the RMS behindtrim_db/split_db: librosa computes the mean square infloat32, so forfloat64audio a frame within ~1e-6 dB oftop_dbcan be classified differently.
clicksandwindow_sumsquarereturnfloat64unless givendtype=numpy.float32;cq_to_chroma,wavelet, the filterbanks and the frequency weightings are tables and returnfloat64; tempo estimates and tuning are alwaysfloat64.yin,pyin,tempogram,tempogram_ratioandhybrid_tempogramreturnfloat32forfloat32input (librosa promotes them tofloat64), and so do the costs, scores and matrices of thesequencefunctions (librosa accumulates them infloat64).dtype=arguments that select a librosa output precision are accepted and ignored where documented (griffinlim).Integer outputs are int64 (librosa:
uint16Viterbi states,intppaths).viterbi_binarystates areboolunlessdtype=numpy.uint16(librosa’s) ornumpy.int64is asked for. Event detectors return 1-Dint64frames or samples, orfloat64times, chosen with librosa’sunits=.Integer audio scaling.
int16/int32audio is converted with this library’s asymmetric scaling (negative values by2**(bits-1), positive by2**(bits-1) - 1); librosa’sbuf_to_floatdivides both by2**(bits-1): up to one LSB apart.Sequence and recurrence functions take 2-D
(n_features, n_frames)input with the defaultaxis=-1layout and return dense arrays;sparse=Truegivesarrays.SparseRows(recurrence_matrix,cross_similarity).
Defaults that differ from librosa
Pass librosa’s value explicitly to reproduce a librosa call.
Argument |
librosa |
audio_samples |
|---|---|---|
|
80 |
|
|
-80 |
|
|
|
|
|
|
|
|
unseeded |
|
|
|
|
|
60 |
required |
|
22050 |
required |
|
512 |
required |
The onset envelope (onset_strength and everything built on it) and
spectral_contrast keep librosa’s 80 dB floor, which is part of those
features’ definitions. All other defaults equal librosa’s.
Resampling (no soxr)
librosa.resampledefaults to soxr (res_type="soxr_hq"). This library has its own delay-free Kaiser-windowed sinc resampler;AudioSamples.resample(sr, "high")is designed after soxr_hq’s passband and attenuation. Measured againstlibrosa.resamplefrom 22050 Hz: 129 to 135 dB SNR in the middle of a band-limited signal, 59 to 104 dB at its abrupt edges, 50 to 58 dB on white noise.AudioSamples.resampledefaults to"fast"; pass"high"for librosa-like quality.The output length is exactly
ceil(n * target / orig)(librosa computes it in floating point and can be one sample longer). Fractional rates and librosa’sscaleare not supported.Operations that resample internally inherit the difference:
pitch_shift(~68 dB SNR; itsres_typeselects this library’s quality,"soxr_hq"maps to"high");cqt,vqt,hybrid_cqt,chroma_cqt,chroma_cens,chroma_vqt,tonnetz(top octave to round-off, decimated octaves ~1e-4 of the peak, the size of the difference between librosa’s ownsoxr_hqandsoxr_vhq);icqtandgriffinlim_cqt(upsampling stages).res_typeon these selects this library’s resampler quality.
Errors where librosa warns or fails late
Situation |
librosa |
audio_samples |
|---|---|---|
|
silently returns |
|
|
infers |
|
|
treated as |
|
|
|
|
rank-deficient |
|
error |
|
raises |
empty array |
|
empty array |
|
|
dense ( |
|
|
warns |
accepted silently |
|
warns |
zero rows, silently |
|
names any frequency |
|
Randomness
griffinlimwithinit="random"(librosa’s default) draws phases from this library’s RNG, not NumPy’s, so results differ from librosa’s for the same seed (both are valid reconstructions).rngdefaults to the seed 0, so repeated calls give the same output;rng=Nonedraws a new seed on every call (librosa’s default). A NumPy generator (or anything elsenumpy.random.default_rngtakes) asrng/random_stategives one seed drawn from it, which advances it; its stream is not reproduced.init=Noneis deterministic and matches librosa to round-off.griffinlim_cqtdefaults toinit=None;init="random"draws its phases asgriffinlimdoes.
Options reached through array forms
audio_samples.forms holds array forms of methods, for options that an
AudioSamples makes unnecessary or that need another input:
forms.read_segmentandforms.stream_blocks:offset,duration,sr,fill_valueandres_type. They read the whole file first.forms.get_duration:S,n_fft,hop_length,centerandpath.forms.to_mono,forms.to_stereoandforms.to_multi: several signals of different lengths,pad,norm,downmixandout.forms.resampleandforms.pitch_shift:scaleandfix.forms.stftandforms.istft:dtypeandout, which copies the result into the buffer.forms.reassigned_spectrogram:S.forms.chroma_cqt,forms.chroma_censandforms.chroma_vqt:C,Vand the smoothingwindow.forms.tempogram_ratio: customfreqs.forms.onset_strength:feature.forms.onset_detectandforms.beat_track:sparse=False.forms.frame:axisandsubok.forms.salience:kindandaxis.
arrays.zero_crossings, arrays.tone and arrays.chirp take threshold,
ref_magnitude, pad, zero_pos and phi.
notation.midi_to_note, notation.hz_to_note, notation.note_to_midi and
notation.note_to_hz take octave, cents, key, unicode and
round_midi. Cents round to the nearest whole cent; librosa truncates the rounded
value, which can give one cent less.
Options that are not supported
Each raises ValueError or TypeError instead of being ignored:
harmonic/percussive:mask=True. librosa documents that it returns the masks, but it returns the inverse STFT of the mask taken as a spectrogram, which is not a signal of the input. The masks areeffects.hpss(S, mask=True);io.readandio.StreamedAudioReader: formats other than WAV and FLAC (MP3, Ogg and the others libsndfile reads).
Deliberate behavioural differences
window_bandwidth: librosa returns a hard-coded table value for named windows and ignoresn; here the formula is always evaluated (up to ~1e-4 relative apart, e.g. Blackman 1.72697 vs 1.72676).harmonic/percussive/harmonic_percussive: librosa accepts awindowargument but always uses Hann; herewindowis used.rqa: librosa stores the wrong back-pointer for a(-2, -1)move into the second column, so its backtracking can step outside the matrix. The scores are identical; the path here follows the move actually taken.syncwith an empty index list returns one segment[0, n_frames); librosa returns zero columns.chroma_stftwith an oddn_fft: librosa’s tuning estimate re-infers the FFT length as2 * (bins - 1); here the givenn_fftis used.recurrence_matrix: exact brute-force neighbour search (librosa uses scikit-learn, whose distances can differ by round-off); librosa’s connectivity tie-breaking is reproduced.time_stretch: on input containing exact digital silence the phases of near-zero bins are ill-conditioned and round-off is amplified (~30 dB SNR there, as for librosa against itself with a 1e-15 perturbation).
Methods that are not librosa-compatible
These methods belong to the library’s own API and differ from librosa’s function of the same purpose. Use the librosa-compatible name in the last column.
Method |
Difference from librosa |
librosa-compatible API |
|---|---|---|
|
Use the |
|
|
Symmetric window, no mel norm, absolute dB floor, unnormalised DCT, lifter 22 |
|
|
One value per signal from a single FFT; power-weighted |
|
|
One whole-signal rate in Hz |
|
|
One whole-signal value |
|
|
Different detection functions and peak picker |
|
|
Beat grid at a given tempo; global-autocorrelation tempo |
|
|
Its own mask blend and window conventions |
|
|
Threshold individual samples in absolute dBFS |
|
|
Fixed-length chunking |
|
|
One estimate per buffer or uncentred frames |
|
|
HTK scale by default |
the same functions with |
|
Rounds to the nearest frame |
|
|
Rounds (librosa truncates) |
|
|
|
|
|
Zero-pads trailing windows |
|
|
Asymmetric integer scaling |
– |