Skip to content

CLI Examples ​

End-to-end shell walkthroughs for the sonare CLI, split out from the CLI Reference index. The mastering and repair walkthrough is on the CLI Reference, under Mastering and Repair.

Basic Analysis Workflow ​

bash
# Quick BPM and key check
sonare bpm song.mp3
sonare key song.mp3

# All-in-one analysis with JSON output for scripting
sonare analyze song.mp3 --json > analysis.json

The analyze JSON ​

json
{
  "bpm": 119.781319,
  "bpm_confidence": 1,
  "key": {
    "root": 0,
    "mode": 0,
    "confidence": 0.916127682,
    "name": "C major"
  },
  "time_signature": {
    "numerator": 4,
    "denominator": 4,
    "confidence": 0.540867627
  },
  "beats": [
    {"time": 0.464399099, "strength": 22.697588},
    {"time": 0.975238085, "strength": 37.2648277}
  ],
  "downbeat_indices": [1, 5, 9, 13, 17, 21],
  "downbeat_phase": 1,
  "chords": [
    {"name": "C", "start": 0, "end": 0.975238085, "confidence": 1},
    {"name": "Am", "start": 0.975238085, "end": 1.97369611, "confidence": 1}
  ],
  "sections": [
    {"type": "unknown", "start": 0, "end": 5.96752834, "group": 0},
    {"type": "unknown", "start": 5.96752834, "end": 12, "group": 1}
  ],
  "timbre": {
    "brightness": 0.174766362,
    "warmth": 0.955615997,
    "density": 0.0476123132,
    "roughness": 0.432108253,
    "complexity": 1
  },
  "dynamics": {
    "dynamic_range_db": 0.749715805,
    "loudness_range_lu": 0.0721569061,
    "crest_factor": 18.7629089,
    "is_compressed": true
  },
  "rhythm": {
    "syncopation": 0.00552447326,
    "groove_type": "straight",
    "pattern_regularity": 0.953778565
  },
  "form": "??"
}

The arrays above are abbreviated. In particular, beats contains one {"time", "strength"} object per detected beat; it is not a beat count.

downbeat_indices indexes into beats rather than carrying times of its own, so finding the downbeats is a membership test against that array — beats[i] is a downbeat when i appears in downbeat_indices. downbeat_phase is the beat index the first downbeat falls on, which is how many beats of the first bar the take starts partway through.

Feature Summary Export ​

bash
# Export compact feature summaries
sonare mel song.mp3 --json > mel_features.json
sonare spectral song.mp3 --json > spectral_features.json
sonare chroma song.mp3 --json > chroma_features.json

Batch Processing ​

bash
# Analyze all MP3 files in directory
for f in *.mp3; do
  echo "Processing: $f"
  sonare analyze "$f" --json > "${f%.mp3}.json"
done

# Extract BPM from all files
for f in *.wav; do
  bpm=$(sonare bpm "$f" --json | jq -r '.bpm')
  echo "$f: $bpm BPM"
done

Mixing Workflow ​

mixing-presets, mixing-preset, mix, suggest-mix, and mix-strip are on both CLIs. They list the built-in scenes, print a scene as JSON loadable by the WASM, Python, Node, or C++ mixer APIs, render a scene, suggest a scene from a set of tracks, and run the single-input channel strip.

bash
# List the built-in mixer scene presets
sonare mixing-presets

# Print one preset's scene as JSON
# (--preset is one of: vocalReverbSend, drumBusSubgroup, commentaryDucking;
#  it defaults to vocalReverbSend when omitted)
sonare mixing-preset --preset vocalReverbSend > scene.json

# Load a built-in scene preset and render it to a stereo WAV
# (the vocalReverbSend strips are vocal and vocal-verb-return; the file feeds vocal)
sonare mix \
  --preset vocalReverbSend \
  --input vocal.wav \
  --sample-rate 48000 \
  -o mixed.wav

# Or load a scene from JSON (e.g. exported from `mixing-preset`), naming the strip a file feeds
sonare mix --scene scene.json --input vocal=take.wav -o mixed.wav
OptionDefaultDescription
--scene FILE—Mixer scene JSON. Give exactly one of --scene and --preset
--preset NAME—Built-in scene preset (mixing-presets lists them)
--input [ID=]WAV—One input per strip, repeatable; see below
-o, --output—Rendered stereo WAV
--sample-rate48000Mixer sample rate, 8000 to 384000; inputs are resampled to it

--scene and --preset are mutually exclusive: passing both is a usage error, and passing neither exits 2 as well rather than falling back to a default scene. A scene key the reader does not know (a misspelled faderDB, say) is refused with exit 5, naming the key; keys starting with $ or x- are exempt.

--input takes [ID=]WAV and repeats. An ID= prefix names the strip the file feeds; a bare path uses the file's base name as the id. A strip that no entry names is fed silence rather than dropped, which is what lets an assistant-suggested scene — whose effect returns are fed by sends, not by files — render without a silent WAV per return. Entries that name no strip at all are taken positionally instead, one per strip in scene order, and the two spellings cannot be mixed in one invocation: an entry naming a strip beside one that names none exits 3. Inputs shorter than the longest are padded rather than the set being truncated.

--input and -o/--output go together — either both or neither (otherwise exit 2), and without them mix just loads the scene and reports its strip count.

suggest-mix ​

suggest-mix goes the other way: hand it the individual tracks and the mixing assistant proposes a mixer scene, which mix --scene then renders.

bash
sonare suggest-mix \
  --input vocal=vocal.wav \
  --input drums=drums.wav \
  --tempo-bpm auto \
  --scene-out suggested.json

sonare mix --scene suggested.json --input vocal=vocal.wav --input drums=drums.wav -o suggested-mix.wav
OptionDefaultDescription
--input [ID=]WAV—One per track, repeatable, at least one. A stereo file keeps both channels, so the assistant can read its image; more than two are downmixed. Each file is read at its own rate and resampled onto --sample-rate; ID defaults to the file's base name
--sample-rate48000Shared analysis sample rate
--tempo-bpm BPM|auto—Tempo the suggested delay times are voiced against. auto detects it from the first --input; omitted, the transport's fallback tempo is used. A tempo must be finite and greater than 0
--params k=v,...—Assistant parameter overrides; malformed entries, non-numeric values, unknown keys, a tempoBpm clash with --tempo-bpm, or nFft / hopLength outside their domains are usage errors (exit 2) before any input is read. nFft must be an even integer in [2, 524288]; hopLength must be an integer in [1, 2147483647]
--scene-out FILE—Also write just the suggested scene, in the form mix --scene reads. Both CLIs write through a temporary file and replace the destination only on success, so a failed write (exit 12) leaves an existing file intact

The full suggestion goes to stdout as JSON, with the keys scene, tracks, mix, and explanation; --scene-out is what you feed back into mix. A sample that is not finite in either channel of an input is refused with exit 6.

suggest-mix --params accepts these camelCase keys, in the sorted order shown in an unknown-key error: enableBalance, enableDynamics, enableEq, enableGain, enableHighPass, enableImage, enableStructure, eqMaxCutDb, hopLength, mixBusHeadroomDbtp, nFft, suggestionStrength, targetTrackLufs, tempoBpm. For example, enable_eq=1 is unknown; use enableEq=1. Naming tempoBpm in --params together with --tempo-bpm is refused.

The channel strip ​

The single-input channel strip is a different command with a different job, and it is called mix-strip. Both front-ends carry it and take the same options:

bash
sonare-cli mix-strip song.wav -o strip.wav \
  --input-trim-db -2 --fader-db 1.5 --pan 0.2 --pan-mode balance --width 1.4
OptionDefaultDescription
--input-trim-db0.0Gain applied before the strip
--fader-db0.0Fader gain
--pan0.0Pan position, -1 to 1; a value outside that range is refused
--pan-modebalancebalance, stereo-pan, or dual-pan, matched case-insensitively
--width1.0Stereo width, 0 to 2; 0 collapses to mono, above 1 widens, and a value outside the range is refused

The strip reads and writes true stereo, so a stereo source keeps its image. --width has nothing to act on for a mono source, so any value other than 1.0 against a mono input is rejected (exit 3) instead of quietly doing nothing.

The strip command is mix-strip, not mix: mix renders a whole scene.

Related: Mixing Engine.

Project & MIDI Workflow ​

The sonare project command group runs headless project and Standard MIDI File (SMF) / MIDI 2.0 workflows from JSON project files. The project file is the positional argument of every subcommand that reads one. project bounce --synth routes the project's MIDI tracks through the built-in synth instead of clip audio, and the flag reads two ways:

  • Bare --synth follows the project's General MIDI program changes per channel, with channel 10 routed through the GM drum-kit map. This is the option to use when the project carries real GM programs.
  • --synth <preset> pins every destination to one fixed NativeSynth preset, given as the library preset id (sawLead, warmPad, and so on) in any letter case. Run sonare project synth-presets to list the names.

project bounce writes the channel count you ask for with --channels: 1, 2, 6, or 8. Omitted, the render takes the scene master's layout width. The width cannot exceed the master's: a "5.1" master allows up to six channels and a "7.1" master up to eight, while mono and stereo masters, and scenes without a master, allow up to two. A width other than 1, 2, 6, or 8, and 0 or a negative value, exit 2; a width above the master's exits 3. The master's layout is the layout field of the master bus in the scene (see Mixer Scene JSON).

bash
# Print the project ABI version
sonare project abi

# Create an empty project JSON at a given sample rate
sonare project new --sample-rate 48000 -o empty.json

# Build a project with one MIDI track from a Standard MIDI File
sonare transcribe vocal.wav -o song.mid
sonare project import-smf song.mid -o project.json

# Validate a project JSON (prints diagnostics; optionally writes canonicalized JSON with -o)
sonare project validate project.json
sonare project validate project.json -o canonical.json

# Treat any load diagnostic as a failure (exit 9) — for CI
sonare project validate project.json --strict

# Compile-check a project JSON (prints diagnostics; exits 9 on errors; does not write a file)
sonare project compile project.json

# List the NativeSynth presets --synth accepts
sonare project synth-presets

# Render a project at the project's sample rate and a given channel count
sonare project bounce project.json --sample-rate 48000 --channels 2 -o bounce.wav

# Render a project whose master bus has "layout": "5.1" to a six-channel WAV
sonare project bounce project-51.json --sample-rate 48000 --channels 6 -o bounce-51.wav

# Render the MIDI tracks through the built-in synth, following GM programs
sonare project bounce project.json --synth -o gm-bounce.wav

# …or pin every destination to one preset
sonare project bounce project.json --synth sawLead -o synth-bounce.wav
CommandDescriptionNotable options
sonare project abiPrint the project ABI version—
sonare project newCreate an empty project JSON--sample-rate (8000 to 384000; omitted, the project's own), -o (required)
sonare project validateValidate a project JSON; optionally write canonicalized JSON-o, --strict (any load diagnostic fails)
sonare project compileCompile-check a project JSON; prints diagnostics, exits 9 on errors (writes no file)--json
sonare project synth-presetsList the NativeSynth preset names --synth accepts--json
sonare project bounceRender a project to a WAV (a project whose sampleRate is not a whole number of hertz exits 5). --sample-rate must equal the project's own rate; the render is not resampled-o (required), --sample-rate, --frames (omitted, through the last event and its tail), --channels, --instrument-latency-samples (default 0), --synth, --audio, --resolve-audio
sonare project align-takesAlign every take against one reference audio source and write the alignment into the project as warp maps-o (required), --reference-source (required), --audio, --resolve-audio, --hop-length (default 512), --bins-per-octave (default 12)
sonare project export-smfExport the project to a Standard MIDI File-o (required)
sonare project import-smfBuild a project from a Standard MIDI File-o (required)
sonare project export-midi2Export the project to a MIDI 2.0 Clip File-o (required)
sonare project import-midi2Build a project from a MIDI 2.0 Clip File-o (required)

A project document carries only a URI reference for an audio clip's source — never decoded PCM — so a document with audio clips cannot be rendered until those sources are bound. project bounce and project align-takes have two ways to bind them: --audio SOURCE_ID=WAV binds one source per occurrence and repeats once per source; --resolve-audio instead opens the file:// URIs the document's own unresolved sources already carry, and refuses any other scheme by name. A source still unresolved once both are applied exits 9 and is named with its id, its URI, and the option that would have supplied it. Both front-ends take both options.

bash
# Bind two audio sources by id, then render
sonare project bounce takes.json \
  --audio 1=vocal-take.wav --audio 2=harmony-take.wav \
  -o bounce.wav

# Or resolve the document's own file:// URIs instead of naming each source
sonare project bounce takes.json --resolve-audio -o bounce.wav

# Align every take to source 1 and write the warp maps into a new project
sonare project align-takes takes.json --reference-source 1 --resolve-audio -o aligned.json
bash
# Round-trip a project through Standard MIDI File format
sonare project export-smf project.json -o project.mid
sonare project import-smf project.mid -o roundtrip.json

# Round-trip through MIDI 2.0 Clip File format
sonare project export-midi2 project.json -o project.midi2
sonare project import-midi2 project.midi2 -o roundtrip2.json

# Render a project's MIDI tracks through the built-in synth
sonare project bounce project.json --synth --sample-rate 48000 -o render.wav

Both CLIs also have midi-render, a shorthand for project bounce that always takes the synth path — omit --synth there and it follows GM programs. It takes the project file as its positional argument and the same --sample-rate, --frames, --channels, --instrument-latency-samples, and -o as project bounce, with the same --channels values and scene-master cap; it takes neither --audio nor --resolve-audio.

transcribe ​

transcribe is the reverse direction: audio in, a Standard MIDI File out (see Audio to MIDI). It is on both CLIs.

bash
sonare transcribe solo.wav -o solo.mid
sonare transcribe chords.wav -o chords.mid --polyphonic --tempo-bpm 120
OptionDescription
--tempo-bpmTempo of the project PPQ grid. Give a finite value in [1e-6, 100000] BPM, or omit it to detect tempo. An out-of-range value exits with code 2 before opening input.
--polyphonicUse the multi-F0 chain, which finds overlapping notes
--monophonic-modelMonophonic note model, segments or singing (default segments): segments cuts the pitch track where it moves, singing holds vibrato and drift within a note. Refused with --polyphonic
--reference-hzTuning reference the MIDI note numbers are measured against (default 440.0)
--f0-min-hz, --f0-max-hzF0 range in Hz for either chain; --f0-max-hz must exceed --f0-min-hz. Omitted endpoints use 65/2093 for monophonic and 55/1760 for polyphonic, while explicit endpoints override the selected chain's defaults
--max-polyphonyPolyphonic only: voices kept per frame, 1 to 64 (default 10)
--min-frame-peak-ratioPolyphonic only: the per-frame search stops below this share of the frame's first peak, 0 to 1 (default 0.2); 0 is a real zero
--min-ridge-peak-ratioPolyphonic only: a fade below this share of a ridge's own peak breaks the ridge, 0 to 1 (default 0.1); same domain
--reattack-ratioPolyphonic only: a pitch struck again while it still sounds becomes a new note when its salience climbs past this multiple of the level before (default 2.0 on the CLI, where the library functions leave the split off unless you pass a value); 0 turns the split off, otherwise it must be greater than 1
--min-note-division NShortest note as a note value, 1 to 128: 32 keeps notes from a thirty-second note up at the transcription tempo. Applies to both chains; refused together with --min-note-ms
--min-note-msShortest span kept as a note, in ms (default 30 for the monophonic segments model, 45 for singing, 60 polyphonic); refused together with --min-note-division
--segmentation-threshold-centsMonophonic: the segments model ends a note where the pitch moves this many cents; singing reads it as the scale of the movement kept within one note (default 50)
--velocity-floor-dbLevel mapped to velocity 1; does not drop notes (a note more than 36 dB under the take's loudest notes, or under -80 dBFS, is dropped regardless). Must be negative (default -48)
--fixed-velocity NGive every note velocity N (1-127); the level gate still drops tails and ghosts
--channelMIDI channel the events are emitted on, 0 to 15 (default 0)

The options marked "Polyphonic only" are refused without --polyphonic (exit 3).

The notes land on a project's tempo map, so an explicit --tempo-bpm is installed as that map rather than handed to the transcriber. -o is required.

With --json, transcribe includes tempo_confidence and time_signature (numerator, denominator, confidence) when it detects tempo. Both detected fields are omitted when --tempo-bpm is explicit.

SoundFont (SF2) and per-destination synth JSON are not wired through these CLI commands; use the Project API for SoundFont-backed bounces.

Related: Project Editing, Project Bounce, Native Synth, SoundFont Player.

Note Editing Workflow ​

Per-note editing ​

polyphonic-notes and polyphonic-render are a pair: the first prints the notes a polyphonic analysis found, numbered from 0, and the second re-renders the take with edits addressed by those numbers. Both run the analysis at its own defaults and neither takes a framing option, so the index you read from one is the index the other acts on.

bash
sonare polyphonic-notes chord.wav --json
sonare polyphonic-render chord.wav -o out.wav \
  --edit 0.pitch_shift_semitones=2 --edit 3.muted=1

One --edit is one NOTE.FIELD=VALUE assignment, and the option repeats. The fields are pitch_shift_semitones, gain_db, time_offset_samples, time_stretch_ratio, formant_shift_semitones, vibrato_depth_change, drift_change, and muted; an unknown field is rejected rather than ignored. polyphonic-render requires -o; polyphonic-notes prints to stdout and takes no output file. A malformed assignment, an unknown field, or a value of the wrong type exits 2 before the take is read.

Scale correction and vocal notes ​

pitch-correct-timevarying --mode scale picks its target for each analysis frame: the scale note nearest that frame's pitch. A frame within --vibrato-threshold-cents of its target is left as it is, and any other frame is pulled toward it with a time constant of --retune-speed-ms. A note sung near the midpoint between two scale notes, with vibrato, is therefore pulled toward both of them, and its vibrato widens instead of settling.

bash
sonare pitch-correct-timevarying vocal.wav -o corrected.wav \
  --mode scale --scale-root 0 --scale-mode-mask major \
  --retune-speed-ms 50 --vibrato-threshold-cents 20

--scale-mode-mask takes a mode name such as major or dorian, or a 12-bit scale mask (default 2741); --scale-root is the root pitch class, 0 to 11.

vocal-notes reads a take the way a vocal edit session does and writes nothing. Each note has its start and end (seconds and samples), its center as a MIDI value, its median frequency, an f0_stability score, and the nearest note name with the offset in cents. The options are the session's analysis settings; an option left out keeps the session default, which --help states for each. With --json, each note's entry also carries its per-frame amplitude array, so the output is large for a long take. Lower --segmentation-threshold-cents when two neighboring notes were sung less than 50 cents apart, or the boundary between them is found late. Editing and rendering a session stay in the bindings; see Offline Monophonic Vocal Editing and Pitch-Correct a Vocal Take.

bash
sonare vocal-notes vocal.wav
sonare vocal-notes vocal.wav --json --segmentation-threshold-cents 30 --min-note-ms 40

Splitting Takes at Silence ​

Every positional file is one take of the same part. With more than one take, the intervals become the union of each take's own, merged where they touch, so a cut falls only where every take is quiet:

bash
sonare split-silence take1.wav take2.wav take3.wav
Non-silent intervals: 3
  20992 - 51200
  84480 - 129024
  147456 - 181248

--write-takes PREFIX writes every take sliced at every interval as PREFIX{take:02d}_{interval:03d}.wav, both indices 1-based — three takes and three intervals write nine files:

bash
sonare split-silence take1.wav take2.wav take3.wav \
  --write-takes cut_
Non-silent intervals: 3
  20992 - 51200
  84480 - 129024
  147456 - 181248
Wrote 9 take files with prefix cut_

A take that ends earlier than the others is padded rather than shortened, so one interval's files come out the same length across every take and stay directly comparable. A take whose sample rate differs from the first is refused by name instead of resampled (exit 3):

bash
sonare split-silence take1.wav take2.wav t3_44.wav
Error: take sample rate differs: t3_44.wav is 44100 Hz, the first take is 48000 Hz

Synthesis ​

Both CLIs can generate simple test signals and render a MIDI project through the built-in synth:

CommandRequired or notable option
sonare tone -o tone.wav --frequency-hz 440--frequency-hz, -o; optional --sample-rate (22050), --duration-sec (1.0), --phase (0.0), --amplitude (1.0)
sonare chirp -o sweep.wav --fmax-hz 8000--fmax-hz, -o; optional --fmin-hz (0.0), --exponential, --sample-rate (22050), --duration-sec (1.0)
sonare clicks -o clicks.wav --times 0.5,1.0,1.5--times comma-separated seconds, -o; optional --sample-rate (22050), --length (samples; omitted, through the last click and its decay), --frequency-hz (1000.0), --click-duration-sec (0.1)
sonare midi-render project.json -o render.wavthe project file, -o; --synth PRESET (omitted, it follows the GM programs), --sample-rate, --frames, --channels (1, 2, 6, or 8; omitted, the scene master's width), --instrument-latency-samples. A project bounce with the synth always on, so it takes neither --audio nor --resolve-audio

--sample-rate for tone, chirp, and clicks is 8000 to 384000. --fmax-hz must be greater than 0, and --exponential needs a --fmin-hz above 0.

project bounce and its midi-render shorthand support output widths of 1, 2, 6, or 8. Omit --channels to take the scene master's layout width; 0 or a negative value is a usage error. The requested output width cannot exceed the scene master's layout, except that mono and stereo masters (and scenes without a master) allow up to two channels. A "5.1" master permits six channels and a "7.1" master permits eight.