@audio/tune-snap

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

Pitch correction to a scale: each note's centre moved onto its note, its slow drift flattened, the voice's own cycles re-spaced along one pitch curve (Auto-Tune / Melodyne class)

原始使用文档

@audio/tune-snap npm MIT

Pitch correction to a scale: each note's centre moved onto its note, its slow drift flattened, the voice's own cycles re-spaced along one pitch curve (Auto-Tune / Melodyne class)

npm install @audio/tune-snap
import snap from '@audio/tune-snap'

snap(voice, { fs })                                  // chromatic, natural: centres on their notes, vibrato kept
snap(voice, { fs, scale: 'major', root: 2 })         // to D major
snap(voice, { fs, speed: 0 })                        // every moment on its note: the hard, stepped sound
snap(voice, { fs, strength: .5 })                    // half way there
snap([left, right], { fs })                          // a stereo voice, on one pitch and one set of cycles

The voice's pitch is pYIN's Viterbi path (Mauch & Dixon, ICASSP 2014) every 5 ms. The note each moment means is a Viterbi path over the scale's notes: a frame costs its squared distance from a note, a change of note costs what 40 ms a semitone away does, so a vibrato swinging past the midpoint between two notes stays on its note and a sung step moves to the next. Each note's centre, the median of its middle half, is moved onto its note; the part of its pitch slower than speed (drift, a held note sagging) is taken away and the faster part (vibrato, a scoop, a slide) kept. Between notes the shift crosses over a raised cosine, inside the gap between them, or speed long across a legato step. Then the voice's own glottal cycles are re-spaced along that curve, found on the same pitch (@audio/tune-curve, TD-PSOLA): formants, consonants and breath kept.

Nothing is cut out, shifted apart and crossfaded back over the dry voice, so no note comes in or out with a jump in pitch or a dip where two pitches cancel. Unvoiced audio passes as it is; a note already in tune is left as sung, and a take all in tune comes out sample for sample.

optionsdefault
fs44100Hz (sampleRate is read too)
scale'chromatic''major', 'minor', 'harmonic-minor', 'melodic-minor', 'pentatonic-major', 'pentatonic-minor', 'blues', 'dorian', 'mixolydian', 'whole', or the degrees as semitones above the root
root0the scale's root, semitones above C (2 is D, 9 is A)
a4440Hz, the tuning of A4
strength1how much of the correction is applied: 1 all, .5 half way, 0 none
speed80ms: how slow a motion within a note must be to be corrected away. 0 sets every moment on its note; 20 keeps 40% of a 5.5 Hz vibrato, 50 keeps 80%, 80 keeps 90% and takes away drift; 400 moves the notes' centres alone
tolerance8cents: a note whose centre, and its motion slower than speed, stay this close to its note is left as sung
minFreq, maxFreq60, 1000Hz, the pitch looked for

pitchOf(channels, opts) and correction(midi, opts) are the two halves before the retune: the pitch every 5 ms (MIDI, NaN unvoiced), and the shift in semitones that tunes it.

Measured

Eight solo singers of Vocadito (tracks 1, 5, 10, 14, 20, 27, 33, 38: 158 s, 2021, CC BY 4.0), chromatic. A note's pitch is the median of the corrected voice's pYIN pitch over the middle of each annotated note of 150 ms or more; periodicity is 1 less YIN's least normalized difference over 30 ms, its loss counted where the sung voice's exceeds 0.8.

notes within 10 cents of a semitonemean distanceperiodicity lost, 1% worst framestime per second of audio
as sung26%23.7 cents
tune-snap 1 (per-note PSOLA, crossfaded over dry)64%10.4 cents0.1797 ms
speed: 8071%8.4 cents0.0719 ms
speed: 096%2.6 cents0.17 (the steps between notes)19 ms

On a synthetic voice gliding from A3 30 cents sharp to C#4 40 cents flat in 80 ms, the glide kept its level within 1.2 dB and moved no faster than it was sung; tune-snap 1 dropped 3.2 dB where its shifted note crossed back into the dry glide, and YIN found no period there.

Use when: one voice, sung or played on a monophonic instrument, tuned to a scale: natural correction or the hard-tuned effect.
Not for: chords, mixes, a choir (one pitch per moment); retuning to a written melody, use @audio/tune-midi.


Part of @audio/tune, the tune family umbrella.

MIT © audiojs

版本与发布记录

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

版本发布日期距今
2.0.2latest2026/10/1226 天前
2.0.12026/10/1127 天前
2.0.02026/10/041 个月前
1.1.32026/07/113 个月前
1.1.22026/07/113 个月前
1.1.12026/07/103 个月前

关于 @audio/tune-snap 的常见问题

@audio/tune-snap 是什么?

Pitch correction to a scale: each note's centre moved onto its note, its slow drift flattened, the voice's own cycles re-spaced along one pitch curve (Auto-Tune / Melodyne class)

如何安装 @audio/tune-snap?

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

@audio/tune-snap 支持 TypeScript 吗?

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

@audio/tune-snap 支持 ESM 还是 CommonJS?

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

@audio/tune-snap 需要什么版本的 Node.js?

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

@audio/tune-snap 可以商用吗?

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

@audio/tune-snap 的下载量有多少?

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

@audio/tune-snap 还在维护吗?

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