JavaScript/TypeScript 特徴抽出 API
音声を受け取る関数は、(samples, sampleRate, options?) か、1 つのリクエストオブジェクト({ samples, sampleRate, ...options })のどちらかで呼び出します。sampleRate に既定値はなく必須で、リクエストが宣言していないキーは TypeError で拒否されます。このページのブロックは WASM パッケージ(@libraz/libsonare)の型宣言から取っています。Node パッケージも同じフィールドを宣言しています。両パッケージとも、remix と remixAlignedIntervals の intervals に Int32Array | ArrayLike<number> を受け付けます。位置引数形式のない関数には「request form only」と添えています。Matrix2D は { data: Float32Array, rows: number, cols: number } の行優先の行列で、ビン数 nBins・フレーム数 nFrames の行列なら rows = nBins、cols = nFrames です。
ステム分離と区間を揃えたリミックスは ステムとリミックス API、ピッチ検出とノート・打撃音の関数は ピッチとノート API にあります。
特徴抽出
stft(samples, sampleRate, options?) 中負荷
短時間フーリエ変換(STFT)を計算します。フレーム、ビン、ウィンドウ長の意味は スペクトログラムと STFT を参照してください。
function stft(request: StftRequest): StftResult
function stft(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<StftRequest>,
): StftResult
interface StftRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
db?: boolean; // When true the result also carries `db`, the magnitude in decibels. Default false.
phase?: boolean; // When true the result also carries `phase` in radians. Default false.
}
interface StftResult {
nFft: number; // FFT size in samples.
hopLength: number; // Hop length in samples of the analysis.
sampleRate: number; // Sample rate in Hz of the analysed audio.
magnitude: Matrix2D; // Rows are `nFft / 2 + 1` bins, cols are frames.
power: Matrix2D; // Rows are `nFft / 2 + 1` bins, cols are frames.
db?: Matrix2D; // Magnitude in decibels, rows are bins and cols are frames; present only when `db` was requested.
phase?: Matrix2D; // Phase in radians, rows are bins and cols are frames; present only when `phase` was requested.
}melSpectrogram(samples, sampleRate, options?) 中負荷
メルスペクトログラムを計算します。人間のピッチ知覚に合わせた周波数表現です。メル・MFCC・音色 も参照してください。訪問者が選んだファイルから計算して canvas に描く手順は ブラウザでメルスペクトログラムを描く にあります。
function melSpectrogram(request: MelSpectrogramRequest): MelSpectrogramResult
function melSpectrogram(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<MelSpectrogramRequest>,
): MelSpectrogramResult
interface MelSpectrogramRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
nMels?: number; // Mel bands. Default 128.
fminHz?: number; // Lowest band edge in Hz. Default 0.
fmaxHz?: number; // Highest band edge in Hz. Omit to use Nyquist; a supplied value must be positive and at most Nyquist.
htk?: boolean; // Use the HTK mel formula instead of Slaney. Default `false`.
}
interface MelSpectrogramResult {
sampleRate: number; // Sample rate in Hz of the analysed audio.
hopLength: number; // Hop length in samples of the analysis.
nFft: number; // FFT size of the source STFT.
fminHz: number; // Lower Mel band edge in Hz as applied.
fmaxHz: number; // Upper Mel band edge in Hz as applied: the Nyquist when the request left it at 0.
htk: boolean; // `true` for the HTK Mel formula, `false` for Slaney.
power: Matrix2D; // Linear power; rows are mel bands, cols are frames.
db: Matrix2D; // The dB form of `power`; rows are mel bands, cols are frames.
}結果は順変換のパラメータを持っているので、それをそのまま逆変換ヘルパーに渡せます。melToStft({ power: mel.power, sampleRate: mel.sampleRate, nFft: mel.nFft, fminHz: mel.fminHz, fmaxHz: mel.fmaxHz, htk: mel.htk }) のように指定します(逆特徴量 を参照)。power と db は Matrix2D({ data, rows, cols })なので、帯域数とフレーム数は rows と cols です。
melFrequencies(request) と melFilterbank(request)
音声を使わずに Mel 尺度そのものを得る関数です。melFrequencies は Mel 尺度上で等間隔に並ぶ点を Hz で返し、両端を含みます。Mel スペクトログラムの行にラベルを付けるのに使えます。nMels 帯域のスペクトログラムの帯域 r は、melFrequencies({ nMels: nMels + 2, fminHz, fmaxHz, htk }) の点 r から立ち上がり、点 r + 1 で頂点に達し、点 r + 2 まで下がります。サンプルレートを受け取らないため fmaxHz の既定値は 11025 Hz で、スペクトログラムの既定値に合わせるときはナイキスト周波数を渡します。melFilterbank はフィルタを行列で返します。行が帯域、列が nFft / 2 + 1 個の FFT ビンで、自前のパワースペクトルにバンクを掛けるときに使います。ブラウザでメルスペクトログラムを描く では、この方法で行にラベルを付けています。
function melFrequencies(request: MelFrequenciesRequest): Float32Array
interface MelFrequenciesRequest {
nMels?: number; // Number of points, at least 1. Default 128.
fminHz?: number; // First point in Hz. Default 0.
fmaxHz?: number; // Last point in Hz; greater than `fminHz`. Default 11025.
htk?: boolean; // HTK mel formula instead of Slaney. Default false.
}
function melFilterbank(request: MelFilterbankRequest): Matrix2D
interface MelFilterbankRequest {
sampleRate: number; // Sample rate in Hz the spectrum was taken at.
nFft: number; // FFT size; the filterbank spans its `nFft / 2 + 1` bins.
nMels?: number; // Number of bands, in [1, 4096]. Default 128.
fminHz?: number; // Lower edge of the lowest band in Hz. Default 0.
fmaxHz?: number; // Upper edge of the highest band in Hz. Absent means the Nyquist; when given it must be greater than 0 and at most the Nyquist.
htk?: boolean; // HTK mel formula instead of Slaney. Default false.
norm?: MelNorm; // Band weighting. Default `'slaney'`.
}mfcc(samples, sampleRate, options?) 中負荷
順変換と逆変換の lifter には有限の非負値を指定します。0 はリフタリングを無効にします。逆変換では、float32 で 0 に丸められる負値も受け付けません。
MFCC(メル周波数ケプストラム係数)を計算します。スペクトル包絡のコンパクトな表現です。メル・MFCC・音色 も参照してください。
function mfcc(request: MfccRequest): MfccResult
function mfcc(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<MfccRequest>,
): MfccResult
interface MfccRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
nMels?: number; // Mel bands. Default 128.
fminHz?: number; // Lowest band edge in Hz. Default 0.
fmaxHz?: number; // Highest band edge in Hz. Omit to use Nyquist; a supplied value must be positive and at most Nyquist.
htk?: boolean; // Use the HTK mel formula instead of Slaney. Default `false`.
nMfcc?: number; // Coefficients kept. Default 20.
lifter?: number; // Finite, nonnegative cepstral lifter. Zero means no liftering.
}
interface MfccResult {
sampleRate: number; // Sample rate in Hz of the analysed audio.
hopLength: number; // Hop length in samples of the analysis.
nFft: number; // FFT size in samples of the source STFT.
nMels: number; // Mel bands the coefficients were taken from.
fminHz: number; // Lower Mel band edge in Hz as applied.
fmaxHz: number; // Upper Mel band edge in Hz as applied: the Nyquist when the request left it at 0.
htk: boolean; // `true` for the HTK Mel formula, `false` for Slaney.
lifter: number; // Cepstral lifter applied to the coefficients; 0 means none.
coefficients: Matrix2D; // Rows are coefficients, cols are frames.
}fminHz/fmaxHz で Mel 帯域の端を制限でき、htk: true で Slaney ではなく HTK の Mel 式を使います。lifter は librosa の lifter 引数に対応し、高次のケプストラム係数を弱めるケプストラム/正弦リフタリングを行います(0 でリフタリングなし)。逆変換ヘルパー(melToStft、melToAudio、mfccToMel、mfccToAudio)も対応する fminHz/fmaxHz/htk フィールドを取ります。順変換の結果がこれらの値を持っているので、そのまま渡せば往復の結果が一致します。
chroma(samples, sampleRate, options?) 中負荷
クロマグラム(ピッチクラス分布)を計算します。すべての周波数を 12 のピッチクラス(C, C#, D, ..., B)にマッピングします。クロマ特徴量 も参照してください。
function chroma(request: ChromaRequest): ChromaResult
function chroma(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<ChromaRequest>,
): ChromaResult
interface ChromaRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
interface ChromaResult {
sampleRate: number; // Sample rate in Hz of the analysed audio.
hopLength: number; // Hop length in samples of the analysis.
features: Matrix2D; // Rows are chroma bins, cols are frames.
meanEnergy: number[]; // Mean energy of each chroma bin over all frames.
}スペクトル特徴
function spectralCentroid(request: SpectralCentroidRequest): Float32Array
function spectralCentroid(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralCentroidRequest>,
): Float32Array
interface SpectralCentroidRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
function spectralBandwidth(request: SpectralBandwidthRequest): Float32Array
function spectralBandwidth(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralBandwidthRequest>,
): Float32Array
interface SpectralBandwidthRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
p?: number; // Norm exponent. Default 2.
}
function spectralRolloff(request: SpectralRolloffRequest): Float32Array
function spectralRolloff(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralRolloffRequest>,
): Float32Array
interface SpectralRolloffRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
rollPercent?: number; // Energy fraction below the rolloff frequency. Default 0.85.
}
function spectralFlatness(request: SpectralFlatnessRequest): Float32Array
function spectralFlatness(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralFlatnessRequest>,
): Float32Array
interface SpectralFlatnessRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
function spectralContrast(request: SpectralContrastRequest): Matrix2D
function spectralContrast(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralContrastRequest>,
): Matrix2D
interface SpectralContrastRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
nBands?: number; // Contrast bands above the lowest. Default 6.
fminHz?: number; // Upper edge of the lowest band, in Hz. Default 200.
quantile?: number; // Quantile separating peaks from valleys. Default 0.02.
}
function polyFeatures(request: PolyFeaturesRequest): Matrix2D
function polyFeatures(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<PolyFeaturesRequest>,
): Matrix2D
interface PolyFeaturesRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
order?: number; // Polynomial order. Default 1.
}
function zeroCrossingRate(request: ZeroCrossingRateRequest): Float32Array
function zeroCrossingRate(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<ZeroCrossingRateRequest>,
): Float32Array
interface ZeroCrossingRateRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
frameLength?: number; // Frame length in samples. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
function zeroCrossings(request: ZeroCrossingsRequest): Int32Array
function zeroCrossings(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<ZeroCrossingsRequest>,
): Int32Array
interface ZeroCrossingsRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Audio sample rate in Hz, an integer in [8000, 384000]; required for the shared call shape, not read by the computation.
threshold?: number; // Magnitude below which a sample counts as zero. Default 1e-10.
refMagnitude?: boolean; // Scale `threshold` by the maximum absolute sample. Default `false`.
pad?: boolean; // Report index 0 as a crossing when the input has samples. Default `true`.
zeroPos?: boolean; // Treat the sign of zero as positive. Default `true`.
}
function rmsEnergy(request: RmsEnergyRequest): Float32Array
function rmsEnergy(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<RmsEnergyRequest>,
): Float32Array
interface RmsEnergyRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
frameLength?: number; // Frame length in samples. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}biquadFilter(request)
モノラル音声を、バターワースのハイパス/ローパス(order は 2 か 4)、またはバンドパス/ノッチのバイクアッドでフィルタリングします。リクエスト形式のみです。type で応答を選び、type が読まない周波数フィールドは省略する必要があります。highPass / lowPass では cutoffHz、bandPass / notch では centerHz と bandwidthHz を使います。zeroPhase: true はフィルターを前向きと後ろ向きに通して位相ずれをなくします。結果は入力と同じ長さです。
function biquadFilter(request: BiquadFilterRequest): Float32Array
interface BiquadFilterRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate in Hz, an integer in `[8000, 384000]`; there is no default.
type: BiquadFilterType; // Filter response.
order?: number; // 2, or 4 for `highPass` / `lowPass` (a two-section cascade). Default 2.
zeroPhase?: boolean; // Run the filter forward and backward for zero phase shift. Default `false`.
cutoffHz?: number; // Corner in Hz inside `(0, sampleRate / 2)`; `highPass` / `lowPass` only.
centerHz?: number; // Center in Hz inside `(0, sampleRate / 2)`; `bandPass` / `notch` only.
bandwidthHz?: number; // Bandwidth in Hz, above 0; `bandPass` / `notch` only.
}波形ピーク WASM/Node
チャンネルごとの min/max バケットで、全サンプル配列を UI に送らずに波形の概観を描けます。samplesPerBucket でバケット幅を指定し(既定 512)、waveformPeakPyramid はズームレベルごとに 1 つのレポートを返します。どちらも channels 配列(チャンネルごとに 1 本の Float32Array、長さは同じ)を 1 つ受け取るリクエスト形式のみです。
function waveformPeaks(request: WaveformPeaksRequest): WaveformPeaksReport
function waveformPeakPyramid(request: WaveformPeakPyramidRequest): WaveformPeaksReport[]
interface WaveformPeaksRequest {
channels: Float32Array[]; // One `Float32Array` per channel, equal lengths.
samplesPerBucket?: number; // Bucket width in samples. Default 512.
}
interface WaveformPeakPyramidRequest {
channels: Float32Array[]; // One `Float32Array` per channel, equal lengths.
samplesPerBucketLevels?: number[]; // Bucket widths in samples, one per zoom level. Default [512, 1024, 2048, 4096].
}
interface WaveformPeaksReport {
min: Float32Array[]; // Per-channel bucket minima: `min[c]` holds `bucketCount` values.
max: Float32Array[]; // Per-channel bucket maxima: `max[c]` holds `bucketCount` values.
bucketCount: number; // Number of buckets per channel.
samplesPerBucket: number; // Bucket width in samples.
}CQT / VQT / NNLS クロマ / 逆変換 / ラウドネス
これらは単なる追加特徴量ではなく、目的が違います。
| 目的 | 使う API | 理由 |
|---|---|---|
| 音楽的なピッチ軸の表現 | cqt(...), pseudoCqt(...), hybridCqt(...) | オクターブ方向に音高と対応しやすい Constant-Q 表現です。擬似/ハイブリッド版はビンごとの速度と精度のバランスを変えます。 |
| 帯域幅を調整したピッチ表現 | vqt(...) | CQT に近く、低域の安定性を調整できます。gamma を省略すると ERB 由来の自動帯域幅になり、gamma: 0 は CQT と等価です。負の値や有限でない値(NaN を含む)の gamma は RangeError を投げます。自動にするときは NaN を渡さず省略してください。 |
| コード検出向けのクロマ | chromaCqt(...), nnlsChroma(...), chromaCens(...), bassChroma(...) | Constant-Q、NNLS、CENS、低域寄りのクロマは、通常の STFT クロマよりコードや低音域の処理に向く場合があります。 |
| スペクトル形状の詳細 | spectralContrast(...), polyFeatures(...), zeroCrossings(...), onsetStrengthMulti(...) | librosa 互換のコントラスト帯域、多項式係数、ゼロ交差インデックス、マルチバンドオンセット強度を返します。 |
| ピッチ/チューニングずれ | pitchTuning(...), estimateTuning(...) | 検出済み周波数(pitchTuning({ frequencies })、リクエスト形式のみ)または音声(estimateTuning)から、全体のチューニングずれをセント単位で推定します。12 ビン/オクターブのとき値は [-50, 50) に収まり、解析オプションの tuningCents と同じ単位です。tuningToReferenceHz(...) と referenceHzToTuning(...) で Hz 単位の基準ピッチと相互に変換できます。 |
| 分解とリミックス | decompose(...), decomposeStems(...), decomposeStemsLinked(...), nnFilter(...), remix(...), remixAlignedIntervals(...), phaseVocoder(...), hpss({ ..., withResidual: true }) | NMF 分解、初期化方式を選べる NMF、モノラル/連動マルチチャンネルのステム出力、近傍フィルタ、区間リミックス、チャンネル間で一貫したカット位置、時間スケーリング、残差付き HPSS。 |
| 特徴量や音声の近似復元 | melToStft, melToAudio, mfccToMel, mfccToAudio, cqtToAudio, vqtToAudio | 可視化、デバッグ、特徴量の往復確認に使います。CQT/VQT の入力は振幅行列です。 |
| 配信向けラウドネス測定 | lufs, lufsMultichannel, momentaryLufs, shortTermLufs, ebur128LoudnessRangeLu | ITU-R BS.1770 / EBU R128 系のラウドネス値。マルチチャンネル Integrated LUFS と LRA(ラウドネスレンジ。曲全体でラウドネスがどれだけ変動するか)も含みます。LUFS も参照してください。 |
const cqtResult = cqt(samples, sampleRate, { hopLength: 512, fminHz: 32.7, nBins: 84, binsPerOctave: 12 });
const vqtResult = vqt({ samples, sampleRate, hopLength: 512, fminHz: 32.7, nBins: 84, binsPerOctave: 12 });
const pseudo = pseudoCqt(samples, sampleRate);
const hybrid = hybridCqt(samples, sampleRate);
const cqtChroma = chromaCqt(samples, sampleRate);
const nnls = nnlsChroma(samples, sampleRate, { hopLength: 512 }); // a Matrix2D
const cens = chromaCens(samples, sampleRate);
const bass = bassChroma(samples, sampleRate);
const loudness = lufs(samples, sampleRate);
const contrast = spectralContrast(samples, sampleRate);
const poly = polyFeatures(samples, sampleRate);
const crossings = zeroCrossings(samples, sampleRate);
const onsetBands = onsetStrengthMulti(samples, sampleRate);
const tuning = estimateTuning(samples, sampleRate);
const offset = pitchTuning({ frequencies: pitch.f0 });
const { w, h } = decompose({ s: spectrogram, nComponents: 8 }); // spectrogram is a Matrix2D
const warmStarted = decompose({ s: spectrogram, nComponents: 8, nIter: 50, beta: 2.0, init: 'nndsvd' });
const filtered = nnFilter({ s: spectrogram });
const remixed = remix(samples, sampleRate, { intervals: Int32Array.from([0, sampleRate, sampleRate, 2 * sampleRate]) });
const stretched = phaseVocoder(samples, sampleRate, { speedRatio: 1.5 });
const hpssResidual = hpss({ samples, sampleRate, withResidual: true });
const multichannel = lufsMultichannel({ channels: [left, right], sampleRate });
const lra = ebur128LoudnessRangeLu(samples, sampleRate);
const reconstructed = melToAudio({ power: mel.power, sampleRate: mel.sampleRate, nFft: mel.nFft, hopLength: mel.hopLength, fminHz: mel.fminHz, fmaxHz: mel.fmaxHz, htk: mel.htk });
const cqtPreview = cqtToAudio({ magnitude: cqtResult.magnitude, sampleRate, hopLength: 512, fminHz: 32.7, binsPerOctave: 12 });
const vqtPreview = vqtToAudio({
magnitude: vqtResult.magnitude,
sampleRate,
hopLength: 512,
fminHz: 32.7,
binsPerOctave: 12,
nIter: 32,
});chromaCqt(samples, sampleRate, { hopLength?, nChroma?, binsPerOctave? }) は librosa.feature.chroma_cqt に直接対応します(対数周波数/Constant-Q でのピッチ畳み込み。chromaCens も同じオプション、bassChroma は hopLength と nChroma を取ります)。一方 nnlsChroma(samples, sampleRate, options?) は別物の音符活性化クロマで、NNLS(非負最小二乗法)で倍音の漏れを抑えます。コードや低音域の処理ではこちらの方がすっきりする場合が多いです。Matrix2D を返し、options は enableStftBlend、stftBlendWeight、stftBlendNFft、hopLength(既定 512)です。
Constant-Q 系とその仲間のリクエストインターフェースです。
以下のリクエストはいずれも { samples: Float32Array; sampleRate: number } を継承します。cqt、vqt、pseudoCqt、hybridCqt、chromaCens、chromaCqt、bassChroma、nnlsChroma、onsetStrengthMulti、estimateTuning、phaseVocoder、lufs、momentaryLufs、shortTermLufs は、リクエストオブジェクトか (samples, sampleRate, options?) のどちらでも呼べます。ただし phaseVocoder の options は必須です(speedRatio)。pitchTuning、decompose、nnFilter、lufsMultichannel はリクエスト形式のみです。lufs(...) が必ず返すのは integratedLufs です。400 ms または 3 秒の完全な窓が入力に収まらない場合、momentary と short-term の値は省略され、Max-M と Max-S も同様です。無音、または 3 秒ブロックがゲートを通らない場合は loudnessRangeLu も省略されるため、これらの値を使う前に存在を確認してください。
interface CqtRequest extends SampleInput {
hopLength?: number; // Hop length in samples; default 512.
fminHz?: number; // Lowest bin frequency in Hz; default 32.70319566257483 (C1).
nBins?: number; // Number of frequency bins; default 84.
binsPerOctave?: number; // Bins per octave; default 12.
filterScale?: number; // Filter length scale factor, finite and greater than 0; default 1 (librosa's).
}
interface VqtRequest extends CqtRequest {
gamma?: number; // Bandwidth offset; omit for the automatic ERB-derived value, 0 is equivalent to CQT.
}
interface PseudoCqtRequest extends CqtRequest {}
interface HybridCqtRequest extends CqtRequest {}
interface ChromaCensRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
hopLength?: number; // Hop in samples. Default 512.
nChroma?: number; // Chroma bins. Default 12.
binsPerOctave?: number; // Constant-Q bins per octave; a multiple of `nChroma`. Default 36.
}
interface ChromaCqtRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
hopLength?: number; // Hop in samples. Default 512.
nChroma?: number; // Chroma bins. Default 12.
binsPerOctave?: number; // Constant-Q bins per octave; a multiple of `nChroma`. Default 36.
}
interface BassChromaRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
hopLength?: number; // Hop in samples. Default 512.
nChroma?: number; // Chroma bins. Default 12.
}
interface NnlsChromaRequest extends SampleInput {
enableStftBlend?: boolean; // Blend an STFT chroma into the NNLS chroma. Default `true`.
stftBlendWeight?: number; // Weight of the blended STFT chroma. Default `0.55`.
stftBlendNFft?: number; // FFT size in samples of the blended STFT chroma. Default `4096`.
hopLength?: number; // Hop length in samples. Default `512`.
}
interface OnsetStrengthRequest extends SampleInput {
nFft?: number; // FFT size in samples. Default `2048`.
hopLength?: number; // Hop length in samples. Default `512`.
nMels?: number; // Mel bands the flux is taken over. Default `128`.
}
interface OnsetStrengthMultiRequest extends OnsetStrengthRequest {
nBands?: number; // Number of onset bands; default 3.
}
interface EstimateTuningRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
resolution?: number; // Resolution of the search, as a fraction of a bin. Default 0.01.
binsPerOctave?: number; // Bins per octave the offset is measured in. Default 12.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
interface PitchTuningRequest {
frequencies: Float32Array; // Frequencies in Hz to estimate the tuning offset from.
resolution?: number; // Resolution of the search, as a fraction of a bin. Default 0.01.
binsPerOctave?: number; // Bins per octave the offset is measured in. Default 12.
}
interface DecomposeRequest {
s: Matrix2D; // Non-negative spectrogram: rows are features, cols are frames.
nComponents: number; // Number of NMF components, a positive integer.
nIter?: number; // Multiplicative-update iterations, a positive integer. Default 50.
beta?: number; // Beta divergence: 2 = Frobenius (default), 1 = Kullback-Leibler.
init?: NmfInit; // Initialisation, `'random'` (default, deterministic seed) or `'nndsvd'`.
}
interface DecomposeResult {
w: Matrix2D; // Component matrix: rows are features, cols are components.
h: Matrix2D; // Activation matrix: rows are components, cols are frames.
}
interface NnFilterRequest {
s: Matrix2D; // Spectrogram to filter: rows are features, cols are frames.
aggregate?: NnFilterAggregate; // Neighbour aggregation. Default `'mean'`.
k?: number; // Neighbours per frame, a positive integer. Default 7.
width?: number; // Frames either side of a frame excluded from its neighbours, a non-negative integer. Default 1.
}
interface PhaseVocoderRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate in Hz, an integer in `[8000, 384000]`; there is no default.
speedRatio: number; // Playback speed as a ratio, finite: above 1 is faster and shorter, below 1 slower and longer, the opposite sense of a note's `stretchRatio`. Required.
nFft?: number; // FFT size: an even integer in `[4, 2147483646]`. Default 2048.
hopLength?: number; // Hop in samples, in `(0, nFft / 2]`. Default `nFft / 4`, rounded down.
}
interface LufsMultichannelRequest {
channels: Float32Array[]; // One `Float32Array` per channel, equal lengths.
sampleRate: number; // Sample rate of the channels in Hz. Required.
}
interface CqtResult {
hopLength: number; // Hop length in samples.
sampleRate: number; // Sample rate in Hz.
magnitude: Matrix2D; // Rows are CQT bins, cols are frames.
frequencies: Float32Array; // Center frequency (Hz) of each of the `nBins` bins.
gamma: number; // Bandwidth offset in Hz the transform ran with: for `vqt`, the resolved value (the ERB-derived one when `gamma` was omitted); 0 for the three constant-Q transforms.
}
interface LufsResult {
integratedLufs: number; // Integrated loudness over the whole signal, in LUFS. `-Infinity` when nothing passes the gate. Never absent: the integrated measurement clamps to the input.
momentaryLufs?: number; // Final complete 400 ms window, not Max-M. `-Infinity` for zero energy; absent when the signal is shorter than one window.
shortTermLufs?: number; // Final complete 3 s window, not Max-S. `-Infinity` for zero energy; absent when the signal is shorter than one window (a 1 s signal has no short-term reading).
maxMomentaryLufs?: number; // Maximum 400 ms window (EBU R128 Max-M). `-Infinity` for zero energy; absent when the signal is shorter than one window.
maxShortTermLufs?: number; // Maximum 3 s window (EBU R128 Max-S). `-Infinity` for zero energy; absent when the signal is shorter than one window.
loudnessRangeLu?: number; // Loudness range in LU. Absent for silence and when no 3 s block passes the gates: a spread, not a level, so never `-Infinity`.
}近い CLI コマンドです。これらはすべて Python CLI と C++ CLI の両方にあります。
sonare nnls-chroma song.wav
sonare lufs song.wav --json
sonare cqt song.wav
sonare vqt song.wav
sonare mel-to-audio song.wav -o mel-preview.wav逆再構成
WASM ビルドには逆再構成ヘルパーが同梱されており、メルスペクトログラムや MFCC 行列からスペクトルや音声へ、ブラウザ内で完結して戻せます。処理の流れ、往復のレシピ、CLI の対応コマンド(sonare mel-to-audio、sonare mfcc-to-audio)は 逆変換特徴量 にあります。
| 関数 | 戻り値 | 備考 |
|---|---|---|
melToStft({ power, sampleRate?, nFft?, fminHz?, fmaxHz?, htk? }) | Matrix2D of magnitudes (rows are bins, cols are frames) | メルフィルターバンクの擬似逆変換 |
melToAudio({ power, sampleRate?, nFft?, hopLength?, fminHz?, fmaxHz?, nIter?, htk? }) | Float32Array | Griffin-Lim による音声合成 |
mfccToMel({ coefficients, nMels?, lifter? }) | Matrix2D of mel power (rows are mel bands, cols are frames) | 逆 DCT でメルスペクトログラムへ。順変換で使った lifter を渡す |
mfccToAudio({ coefficients, nMels?, sampleRate?, nFft?, hopLength?, fminHz?, fmaxHz?, nIter?, htk?, lifter? }) | Float32Array | MFCC → メル → 音声を一度に。順変換で使った lifter を渡す |
ロスのある往復: これらは振幅を再構成し、位相を Griffin-Lim で推定するため、出力は近似です。ソニフィケーション・試聴・可視化には十分ですが、ビット精度の復元には使えません。処理の流れと注意点は 逆変換特徴量 を参照してください。