Skip to content

Choose an Audio Edit: Stretch, Shift or Retune ​

Editing DSP rewrites decoded audio samples. It changes the tempo, the pitch, one note, a time-frequency region or the character of a voice, instead of only measuring the sound. This page picks the edit, lists every call with its spelling in each binding, and holds the pitch and position units they share.

The calls themselves are on Change Tempo Without Changing Pitch and Pitch Correction, with Spectral Editing, Note Editing in Audio and Vocal Editing for the rest. If you only want to measure BPM, key, chords, or features, start with Getting Started instead.

If semitone, MIDI note number, or formant are unfamiliar, read Editing Basics first — this page assumes that vocabulary.

DSP vs editing

DSP means Digital Signal Processing: measuring or transforming audio as a signal. The editing DSP here does more than measure BPM or key; it rewrites the sound itself, changing pitch, duration, or vocal character.

Which Edit Do You Need? ​

GoalUseWhere
Make a clip longer or shorter without changing the notetimeStretchTime-stretch
Move the whole clip up or down in pitchpitchShiftPitch shift
Nudge a vocal note toward a target notepitchCorrectToMidi, pitchCorrectTimevaryingPitch correction
Snap a vocal line or a whole recording to a scale or keypitchCorrectTimevarying (scale mode), autoTunePitch correction
Hold or shorten one note regionnoteStretchRegion selection
Attenuate or heal a time-frequency regionspectralEditSpectral editing
Change vocal charactervoiceChangeTime-stretch and pitch-shift
Process live voice blocks with presetsRealtimeVoiceChangerRealtime voice changer
Where each edit starts and ends
timeStretch,pitchShiftpitchCorrectToMidi,autoTunespectralEditDecoded samplesTime and pitchPitch correctionSpectral editEdited samples
Every offline edit takes decoded samples and returns new samples; none changes its input. Note edits and voice change take the same route through the time-and-pitch family.

Units: notes, samples, and seconds ​

Every call below takes pitch as a MIDI note number or a semitone count, and positions as samples or seconds. These two tables are the conversions the examples rely on.

MIDI note numbers ​

A MIDI note number represents pitch as a semitone index. Each whole number is one semitone, and fractional values are allowed.

Two anchors are worth memorizing:

NoteMIDI note numberFrequency
C4 (middle C)60about 261.63 Hz
A469440 Hz

Every octave adds 12. For example, C4 is 60, so C5 is 72.

For the full mapping table and the freq ↔ midi formula, see Editing Basics.

Samples and seconds ​

Every edit position can be given in samples or in seconds. Give one spelling per bound; supplying both is refused.

CallSamplesSecondsPython (seconds)
spectralEdit regionstartSample / endSamplestartSec / endSecstart_sec / end_sec
noteStretch, noteMoveonsetSample / offsetSample; noteMove also targetOnsetSampleonsetSec / offsetSec; targetOnsetSeconset_sec / offset_sec; target_onset_sec
renderNotes, renderPercussiveEvents input recordsonsetSample / offsetSample; edit timeOffsetSamplesonsetSec / offsetSec; timeOffsetSeconset_sec / offset_sec; time_offset_sec
Vocal setSourceSpansourceStartSample, sourceEndSample, destinationStartSample, destinationLengthSamplesthe same names ending Secsource_start_sec and the matching fields
Vocal splitsourceSamplesourceSeccut_source_sample / cut_source_sec
Vocal render rangestartSample / endSamplestartSec / endSecstart_sec / end_sec keywords
  • Seconds are rounded to the nearest sample at the call's sample rate (a vocal session's own rate for the vocal rows).
  • The seconds forms of the note and percussive rows belong to the input records (NoteObjectInput, NoteEditInput, PercussiveEventInput, PercussiveEventEditInput). The records extractNotes and extractPercussiveEvents return carry samples only, and are accepted back as they are.
  • A negative position is refused: RangeError on WASM and Node, SonareValueError in Python.
  • -1 is not a "to the end" sentinel. Omit an end bound to take the input's edge (Python: None).

If a position comes from analysis, keep the sample value; it avoids a second rounding.

Functions ​

Parameters like f0Hz (a per-frame pitch contour), hopLength, and voiced are defined under Time-varying pitch correction below.

TaskWASM / browser JavaScriptPython
Shift the whole signal without changing durationpitchShift({ samples, sampleRate, pitchSemitones })pitch_shift(samples, sample_rate, pitch_semitones)
Time-stretch the whole signal without changing pitchtimeStretch({ samples, sampleRate, speedRatio })time_stretch(samples, sample_rate, speed_ratio)
Correct from one MIDI note to anotherpitchCorrectToMidi({ samples, sampleRate, currentMidi, targetMidi })pitch_correct_to_midi(samples, sample_rate, current_midi, target_midi)
Follow a per-frame pitch contour toward a notepitchCorrectTimevarying({ samples, sampleRate, f0Hz, hopLength, targetMode: 'midi', targetMidi })pitch_correct_timevarying(samples, sample_rate, f0_hz, hop_length, target_mode="midi", target_midi=...)
Snap a contour to a musical scale (automatic pitch correction)pitchCorrectTimevarying({ samples, sampleRate, f0Hz, hopLength, targetMode: 'scale', ... })pitch_correct_timevarying(samples, sample_rate, f0_hz, hop_length, target_mode="scale", scale_root=..., ...)
Snap a whole recording to a detected or named keyautoTune({ samples, sampleRate, key, retuneAmount })auto_tune(samples, sample_rate, key, retune_amount=...)
Stretch only a note regionnoteStretch({ samples, sampleRate, onsetSample, offsetSample, stretchRatio })note_stretch(samples, sample_rate, onset_sample, offset_sample, stretch_ratio)
Edit a time-frequency regionspectralEdit({ samples, sampleRate, ops, ...options })spectral_edit(samples, sample_rate, ops, ...)
Shift pitch and formants independentlyvoiceChange({ samples, sampleRate, pitchSemitones, formantFactor, formantMode? })voice_change(samples, sample_rate, pitch_semitones, formant_factor, formant_mode="relative")
Stateful realtime voice preset chainRealtimeVoiceChangerRealtimeVoiceChanger
One-shot realtime voice preset renderrealtimeVoiceChangerRender({ channels, sampleRate, config? })realtime_voice_changer_render(samples, sample_rate, config=..., num_channels=1)

Positional or request object

WASM and Node accept either positional arguments (samples, then sample rate, then an options object holding the edit amount) or a single request object with the same names; pick one style per file. realtimeVoiceChangerRender is request-only.

effects.modulation.ensemble and saturation.ampSim are creative inserts rather than functions on a raw buffer; load them on a strip as described on Effects Inserts.

Practical Notes ​

These APIs are intentionally lightweight editing tools, not a full non-destructive pitch editor. For transparent vocals, keep pitch correction intervals small and avoid extreme formant factors. For sound design, larger pitchSemitones and formantFactor moves are valid, but expect stronger artifacts.

Why big moves sound worse

These transforms work by analyzing the sound into short overlapping frames and re-spacing or re-pitching them. Small shifts stay close to the original frames and sound clean; large shifts force the engine to invent material that was never recorded, so you hear smearing, a "watery" or robotic quality, and a less natural voice. That is why the advice is to keep correction intervals small for transparent results.

Two resynthesis engines sit behind these calls, and they fail differently: pitchShift, pitchCorrectToMidi and voiceChange stretch and resample (formants move with the pitch), while the contour-following correctors and the vocal session repitch grain by grain (formants stay roughly in place). Two resynthesis engines lists which call uses which.