Skip to content

Python メータリングと信号ヘルパー API ​

レベルとステレオのメータリング関数、および信号とフレーミングのヘルパー(プリエンファシス、無音のトリムと分割、フレーム分割とパディング、ピーク検出、正規化、テンポグラム関数)のリファレンスです。特徴抽出は Python 特徴抽出 API、エフェクト関数は Python エフェクト API にあります。インストール、クイックスタート、その他の API ファミリーは Python API の索引ページを参照してください。

メータリング関数 ​

レベル、ダイナミクス、ステレオイメージを測る単体メーターです。有限でない入力は拒否されます。ステレオメーターは left と right が同じ長さである必要があります。sample_rate は必須です。

python
# Sample-peak in dBFS over the buffer.
def metering_peak_db(samples: Sequence[float] | list[float], sample_rate: int) -> float: ...

# RMS level in dBFS over the buffer.
def metering_rms_db(samples: Sequence[float] | list[float], sample_rate: int) -> float: ...

# Crest factor in dB (peak_db - rms_db); ``None`` for silence.
def metering_crest_factor_db(
    samples: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# Crest factor in dB across both channels of a stereo pair; ``None`` for silence.
def metering_crest_factor_db_stereo(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# DC offset (mean) of the buffer in linear amplitude.
def metering_dc_offset(samples: Sequence[float] | list[float], sample_rate: int) -> float: ...

# Fraction of analysis frames whose RMS is below ``threshold_db``.
def metering_silence_ratio(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    threshold_db: float = -45.0,
    frame_length: int = 1024,
    hop_length: int = 256,
) -> float: ...

# Inter-sample (true) peak in dBFS.
def metering_true_peak_dbtp(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    oversample_factor: int | None = None,
) -> float: ...

# Detect contiguous runs of clipped samples.
def metering_detect_clipping(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    threshold_db: float | None = None,
    min_region_samples: int | None = None,
) -> ClippingReport: ...

# Sliding-window dynamic range for mono audio (high_percentile - low_percentile, in dB).
def metering_dynamic_range(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    window_sec: float | None = None,
    hop_sec: float | None = None,
    low_percentile: float | None = None,
    high_percentile: float | None = None,
) -> DynamicRangeReport: ...

# Uncentered correlation (cosine similarity) between equal-length channels.
def metering_stereo_correlation(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# Stereo width as ``sqrt(side_energy / mid_energy)``.
def metering_stereo_width(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# Mid/side point series for a (left, right) stereo pair.
def metering_vectorscope(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
    max_points: int | None = None,
) -> VectorscopeReport: ...

# Phase-scope point series plus summary stats for a stereo pair.
def metering_phase_scope(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
    max_points: int | None = None,
) -> PhaseScopeReport: ...

# Welch-averaged magnitude / power / dB spectrum over a whole mono buffer.
def metering_spectrum(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    n_fft: int | None = None,
    apply_octave_smoothing: bool = False,
    octave_fraction: int | None = None,
    db_ref: float | None = None,
    db_amin: float | None = None,
) -> SpectrumReport: ...

# True single-frame mono magnitude / power / dB spectrum (one Hann-windowed FFT).
def metering_spectrum_frame(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    frame_offset: int = 0,
    n_fft: int | None = None,
    apply_octave_smoothing: bool = False,
    octave_fraction: int | None = None,
    db_ref: float | None = None,
    db_amin: float | None = None,
) -> SpectrumReport: ...
関数説明
metering_peak_dbサンプルピーク(dBFS)
metering_rms_dbRMS レベル(dBFS)
metering_crest_factor_dbクレストファクター。ピーク − RMS(dB)
metering_crest_factor_db_stereo両チャンネルから測るクレストファクター。ピークは 2 つのうち大きい方、RMS は両チャンネルをまとめて計算する
metering_dc_offset平均(DC)オフセット、リニア振幅
metering_silence_ratioRMS が threshold_db を下回る解析フレームの割合。既定は threshold_db=-45.0、frame_length=1024、hop_length=256
metering_true_peak_dbtpサンプル間ピーク(ISP、True Peak)を dBTP で返す。oversample_factor は 1..16 の 2 の冪で、省略すると既定の 4
metering_detect_clippingクリップしたサンプルの連続区間。threshold_db はクリップとみなす dBFS レベルで [-120, 0](既定はリニア 0.999 に相当するレベル)、min_region_samples 既定 1
metering_dynamic_rangeスライディングウィンドウのダイナミックレンジ。window_sec/hop_sec は省略で既定(3 秒 / 1 秒)で、明示した 0 は拒否されます。low_percentile/high_percentile は [0, 1] の順位で、省略時は 0.10 / 0.95、0.0 は最小 RMS のウィンドウを要求します
metering_stereo_correlation非中心化相関(コサイン類似度)、−1..1
metering_stereo_widthミッド/サイドのステレオ幅
metering_vectorscopeミッド/サイドの点系列。max_points を省略すると 1 サンプル 1 点で、指定すると決定的に間引き、バケットごとに最大半径のサンプルを残します(バッファ長以上の値ではすべてのサンプルを残します)
metering_phase_scopeフェーズスコープ(リサージュ)の点系列と要約統計。max_points は点群を同じ規則で間引き、要約統計は常にフル解像度の信号で計算します
metering_spectrumバッファ全体の Welch 平均による振幅/パワー/dB スペクトラム(Hann 窓・50% オーバーラップの n_fft フレームを平均。単一フレームのスナップショットではない)。n_fft/octave_fraction/db_ref/db_amin は省略で既定値(2048 / 3 / 1.0 / 下限値)で、明示した 0 は拒否されます
metering_spectrum_frame真の単一フレームスペクトラム(Hann 窓 FFT 1 回)。[frame_offset, frame_offset + n_fft) の範囲を処理し、末尾はゼロパディング。n_fft/octave_fraction/db_ref/db_amin は省略で既定値で、明示した 0 は拒否されます

ダウンミックスを metering_crest_factor_db(...) に渡すのではなく、metering_crest_factor_db_stereo(...) を使ってください。0.5 * (left + right) のダウンミックスは逆相のペアを打ち消してしまうため、RMS を小さく見積もり、その分クレストファクターを大きく見せます。位相を反転させた正弦波のペアでは、ステレオメーターは信号そのもののクレストファクターである 3.01 dB を返します。ダウンミックスは無音になり、測るべきクレストファクターがありません。左右の長さが違う場合は SonareValueError を送出します。

信号とフレーミングのヘルパー ​

対応する librosa 関数の挙動に合わせています。各ヘルパーが対応する librosa 関数は librosa 互換性 を参照してください。

各ヘルパーの位置づけ

  • preemphasis / deemphasis:高域を持ち上げる/戻す古典的な 1 タップ IIR の前処理。
  • trim_silence / split_silence:前後無音のトリムや、無音区間での区切り出し。
  • frame_signal / pad_center / fix_length / fix_frames:固定フレーム DSP に通す前のフレーミング・サイズ揃え。
  • peak_pick / vector_normalize:オンセット強度のような 1 次元信号からのピーク検出と、ベクトルのノルム正規化。
  • pcen:メルスペクトログラム向けの動的レンジ圧縮(ノイズ・音量変動に強い特徴量)。
  • tonnetz:クロマグラムを 6 次元のハーモニック空間へ射影。コード関係や転調解析に有効。
  • tempogram / plp:オンセット包絡線から構築するテンポ表現(自己相関、または mode="cosine")と、支配的なパルスの抽出。
  • fourier_tempogram / cyclic_tempogram / tempogram_ratio:FFT ベースのテンポグラム、オクターブ畳み込みの循環テンポグラム、テンポ比特徴量。
python
# Apply librosa-compatible pre-emphasis; returns a float32 array.
def preemphasis(
    samples: Sequence[float] | list[float],
    coef: float = 0.97,
    zi: float | None = None,
) -> np.ndarray: ...

# Apply inverse pre-emphasis; returns a float32 array.
def deemphasis(
    samples: Sequence[float] | list[float],
    coef: float = 0.97,
    zi: float | None = None,
) -> np.ndarray: ...
関数説明
preemphasisプリエンファシス(librosa.effects.preemphasis)
deemphasisディエンファシス(librosa.effects.deemphasis)
python
# Trim leading/trailing silence and return a :class:`TrimResult`.
def trim_silence(
    samples: Sequence[float] | list[float],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> TrimResult: ...

# Return non-silent intervals as an int64 array of shape ``(n_intervals, 2)``.
def split_silence(
    samples: Sequence[float] | list[float],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> np.ndarray: ...

# Return the intervals where any of several takes of one part is sounding.
def split_silence_common(
    signals: Sequence[Sequence[float]],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> np.ndarray: ...

# Return what :func:`split_silence_common` returns, plus why.
def split_silence_common_with_report(
    signals: Sequence[Sequence[float]],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> SplitSilenceCommonWithReportResult: ...
関数説明
trim_silencelibrosa.effects.trim。TrimResult(.audio、.start_sample、.end_sample。アンパックはできません)を返す
split_silencelibrosa.effects.split。非無音区間をサンプル単位で返す
split_silence_common同じパートの複数テイクがすべて無音になっている区切り位置。signals はシーケンスのシーケンスを 1 つ取るため、信号数と各信号の長さが食い違うことがない
split_silence_common_with_report同じ区切り位置に加えて、silence_ceiling_db、max_signal_intervals、min_signal_intervals を持つレポートを返す
python
# Slice a signal into frames.
def frame_signal(
    samples: Sequence[float] | list[float],
    frame_length: int,
    hop_length: int,
) -> np.ndarray: ...

# Pad an array by centering it within target size; returns a float32 array.
def pad_center(
    values: Sequence[float] | list[float],
    target_size: int,
    pad_value: float = 0.0,
) -> np.ndarray: ...

# Crop or pad an array to exact length; returns a float32 array.
def fix_length(
    values: Sequence[float] | list[float],
    target_size: int,
    pad_value: float = 0.0,
) -> np.ndarray: ...

# Adjust frame indices to fit within bounds; returns an int32 array.
def fix_frames(
    frames: Sequence[int] | list[int],
    x_min: int = 0,
    x_max: int | None = None,
    pad: bool = True,
) -> np.ndarray: ...

# Pick peaks using librosa.util.peak_pick-compatible parameters.
def peak_pick(
    values: Sequence[float] | list[float],
    pre_max: int,
    post_max: int,
    pre_avg: int,
    post_avg: int,
    delta: float,
    wait: int,
) -> np.ndarray: ...

# Normalize a vector (float32 array) by its maximum magnitude, L1, L2 or power norm.
def vector_normalize(
    values: Sequence[float] | list[float],
    norm: NormType = 'max',
    threshold: float = 0.0,
) -> np.ndarray: ...
関数説明
frame_signallibrosa.util.frame。形状 (frame_length, n_frames) を返す
pad_centerlibrosa.util.pad_center
fix_lengthlibrosa.util.fix_length
fix_frameslibrosa.util.fix_frames。x_max は上限(その値を含む)で、省略(None)すると上限なしです。-1 は拒否されます
peak_picklibrosa.util.peak_pick。ピーク位置のインデックスを返す
vector_normalizelibrosa.util.normalize。norm: "max"(既定)、"l1"、"l2"、"power"
python
# Apply per-channel energy normalization to a spectrogram.
def pcen(
    values: npt.ArrayLike,
    sr: int = 22050,
    hop_length: int = 512,
    time_constant: float = 0.4,
    gain: float = 0.98,
    bias: float = 2.0,
    power: float = 0.5,
    eps: float = 1e-06,
) -> np.ndarray: ...

# Compute Tonnetz from a chromagram.
def tonnetz(chromagram: npt.ArrayLike) -> np.ndarray: ...
関数説明
pcenlibrosa.pcen。入力は形状 (n_bins, n_frames) のメルスペクトログラム
tonnetzlibrosa.feature.tonnetz。入力は (n_chroma, n_frames)、(6, n_frames) を返す
python
# Compute a tempogram as a float32 array of shape ``(win_length, n_frames)``.
def tempogram(
    onset_envelope: Sequence[float] | list[float],
    sr: int = 22050,
    hop_length: int = 512,
    win_length: int = 384,
    center: bool = True,
    norm: bool = True,
    mode: TempogramMode = 'autocorrelation',
) -> np.ndarray: ...

# Compute the Fourier (FFT-based) tempogram magnitude.
def fourier_tempogram(
    onset_envelope: Sequence[float] | list[float],
    sr: int = 22050,
    hop_length: int = 512,
    win_length: int = 384,
    center: bool = True,
) -> np.ndarray: ...

# Compute a cyclic tempogram as a float32 array of shape ``(n_bins, n_frames)``.
def cyclic_tempogram(
    onset_envelope: Sequence[float] | list[float],
    sample_rate: int,
    hop_length: int = 512,
    win_length: int = 384,
    bpm_min: float = 60.0,
    n_bins: int = 60,
) -> np.ndarray: ...

# Aggregate tempogram magnitudes at integer ratios of a reference tempo.
def tempogram_ratio(
    tempogram: npt.ArrayLike,
    sr: int = 22050,
    hop_length: int = 512,
    factors: Sequence[float] | list[float] | None = None,
) -> np.ndarray: ...

# Compute predominant local pulse from an onset envelope (float32, one value per frame).
def plp(
    onset_envelope: Sequence[float] | list[float],
    sr: int = 22050,
    hop_length: int = 512,
    tempo_min: float | None = None,
    tempo_max: float | None = None,
    win_length: int = 384,
) -> np.ndarray: ...
関数説明
tempogramlibrosa.feature.tempogram。mode: "autocorrelation"(既定)または "cosine"
fourier_tempogramFFT ベースのテンポグラム(オンセット包絡線の STFT)
cyclic_tempogramオクターブ畳み込みの循環テンポグラム
tempogram_ratioテンポグラムからのテンポ比特徴量
plplibrosa.beat.plp。Predominant Local Pulse