@audio/pitch-pyin

中文文档
2.1.0发布于 2026/10/12MITTypeScriptES Module近 30 天下载 4061

pYIN — probabilistic YIN (Mauch & Dixon, 2014)

原始使用文档

@audio/pitch-pyin npm MIT

pYIN — probabilistic YIN (Mauch & Dixon, 2014)

npm install @audio/pitch-pyin
import pyin, { track, notes } from '@audio/pitch-pyin'

Mauch & Dixon, 2014. Probabilistic YIN — runs YIN at multiple thresholds weighted by a Beta(2, 18) prior, producing a distribution over candidate pitches instead of a single hard pick. More robust than YIN on ambiguous frames.

let result = pyin(samples, { fs: 44100 })
// → { freq: 440.1, clarity: 0.92, candidates: [{ freq: 440.1, prob: 0.85 }, ...] }
ParamDefault
fs44100Sample rate (Hz)
minFreq50Minimum detectable frequency (Hz)
maxFreq2000Maximum detectable frequency (Hz)

Unlike the other atoms, the single-frame result also carries candidates — the full posterior over detected periods, sorted by probability, each { freq, prob } with prob normalized to sum to 1 across candidates. clarity is the (clamped) total probability mass captured by the candidate set, not a single-peak confidence.

Over a sequence of frames, track runs pYIN's second stage and notes segments its result into notes:

let { times, f0, voiced, prob } = track(samples, { fs: 44100 })   // frame i at i·hopSize/fs, f0 0 where unvoiced
let events = notes(samples, { fs: 44100 })                        // → [{ time, duration, freq, midi, clarity }, ...]

let write = notes({ fs: 44100 })   // streaming, track too
write(block)                       // → the notes finished so far
write()                            // → the rest
ParamDefault
frameSize2048 at 44.1 kHzFrame (samples): the shortest power of 2 whose YIN window holds a period of minFreq
hopSize256 at 44.1 kHzHop (samples), ≈ 5.8 ms
lag4096Frames within which every frame is decided: a stream runs at most this far behind its input
minDuration0.1notes: shortest note kept (s)
candidatesYIN'sStage 1: another observation model for the HMM, such as @audio/neural-pitch's

track Viterbi-decodes pYIN's pitch HMM. States are 0.1-semitone bins from minFreq to maxFreq, voiced or unvoiced; pitch moves at most 35.92 octaves per second and voicing switches with probability 0.01 (librosa.pyin's defaults). Voiced states take half their candidates' probability (the Vamp plugin's yinTrust), which keeps an unvoiced path open, so a leap between notes is not followed an octave off. A frame is decided once every Viterbi path through it agrees, or, if they have not met within lag frames, along the best path then (fixed-lag decoding, as the pYIN Vamp plugin): memory stays bounded at any length, and a stream with a short lag decides each frame a fixed latency behind its input. Against librosa.pyin 1.0: the difference function is YIN's own (librosa zero-extends the frame, which pulls low pitches sharp), candidates in one bin add up, and f0 is the candidate inside the decoded bin, not the bin centre.

notes is Tony's note model, with the pYIN Vamp plugin's parameters and output: attack, stable and silent states for 3 pitches per semitone. Vibrato and a scoop into a note stay inside it; the same pitch played again starts a new note where the level rises 1/0.7-fold within two frames; a fast glide joins the notes at its ends, a slow one steps through the notes it passes. freq is the median pitch of the note's frames, clarity their mean voiced probability.

candidates replaces stage 1 and leaves the HMM and the note model as they are. It has candidates.js's signature: (frameSize, fs, minFreq, maxFreq) → run, where run(frame) returns the candidate count after filling run.freq, run.prob (each candidate's pitch probability, at most 1 in all) and run.rms (the level the note onsets read); run.frameSize and run.lead set how many samples a frame holds and how many of them precede its time. Without it the output is the same, bit for bit.

Use when: Ambiguous pitched content — breathy vocals, noisy recordings, or when you need a pitch posterior for downstream HMM tracking. Melody of a voice or solo instrument: smoothed f0 with voicing (track), note events (notes).
Not for: Polyphonic audio: one pitch per frame.
Ref: Mauch & Dixon, "pYIN: A Fundamental Frequency Estimator Using Probabilistic Threshold Distributions", ICASSP 2014. Mauch et al., "Computer-aided Melody Note Transcription Using the Tony Software: Accuracy and Efficiency", TENOR 2015.


Part of @audio/pitch — the pitch family umbrella. This README is generated from the umbrella docs.

MIT © audiojs

版本与发布记录

@audio/pitch-pyin 共发布 4 个版本,首次发布于 2026/07/09;过去 12 个月发布了 4 个版本。

版本发布日期距今
2.1.0latest2026/10/1226 天前
2.0.02026/09/291 个月前
1.0.12026/07/113 个月前
1.0.02026/07/094 个月前

关于 @audio/pitch-pyin 的常见问题

@audio/pitch-pyin 是什么?

pYIN — probabilistic YIN (Mauch & Dixon, 2014)

如何安装 @audio/pitch-pyin?

在项目目录运行 npm install @audio/pitch-pyin,或使用 pnpm add / yarn add / bun add。

@audio/pitch-pyin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@audio/pitch-pyin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@audio/pitch-pyin 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@audio/pitch-pyin 可以商用吗?

@audio/pitch-pyin 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@audio/pitch-pyin 的下载量有多少?

根据 npm 官方下载统计,@audio/pitch-pyin 在 2026/10/07 – 2026/11/05 这 30 天内被下载 4,061 次,日均约 135 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@audio/pitch-pyin 还在维护吗?

最新版本 2.1.0 发布于 2026/10/12(26 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/07/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。