lmaudio
lmaudio is a native lmcode host for offline audio: synthesis, physical models, filters, effects and analysis in one static executable scripted from LMScript. It renders deterministic WAV, CSV and numeric results and needs no sound card.
Install and run
npm install -g @lmctl-ai/lmctl
lmscript hello.lms
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmaudio/main/examples/drum_machine_pattern.lms
A block that declares cli="lmaudio" and install="github:lmctl-ai/lmaudio@latest" compiles against the schema embedded in the lmaudio binary. lmscript uses lmaudio from PATH, or downloads the release binary into its tool cache on first use. The latest release is v0.2.2.
Host protocol and flags
| Command or variable | Effect |
|---|---|
| lmaudio --version | Prints the release identity, for example lmaudio 0.2.2. |
| lmaudio --notices | Prints the third-party software notices with the upstream license texts. |
| lmaudio --lmcode-schema | Prints the embedded schema as readable JSON. |
| lmaudio --lmcode-schema --json | Prints the exact schema bytes the compiler binds a program to (schema version 2, name lmaudio). |
| lmaudio --lmcode-signatures | Prints every canonical signature the host registry provides, one per line, standard catalog included. |
| lmaudio --lmcode FILE [FILE ...] | Runs compiled lmcode program files. This is what run_lmcode calls; the compiler owns the program files. |
| lmaudio --dry-run --lmcode FILE | Runs a program without writing any file. The flag comes before --lmcode. The result envelope carries dry true. |
| LMAUDIO_MAX_MEMORY_MB | Environment variable: total memory budget in MiB, default 4096. A value that is not a positive whole number is a usage error on every command. |
| Exit code | Envelope | Meaning |
|---|---|---|
| 0 | ok true | The program ran and every audio.assert_close held. |
| 2 | phase cli, code CLI_USAGE | Unknown or misplaced arguments, or an invalid LMAUDIO_MAX_MEMORY_MB. |
| 3 | phase load, for example code LOAD_BAD_BYTECODE or LOAD_UNBOUND | The program file cannot be read, or it imports a function the host does not provide. |
| 3 | phase run, code RUN_HOST | A host error with a source line and column: a failed audio.assert_close, a missing WAV file, an invalid argument, or the memory budget being exceeded. |
Every --lmcode run ends with one JSON envelope on stdout between the lines LMCODE_RETURN_BEGIN and LMCODE_RETURN_END. run_lmcode decodes it and returns a map with ok and result on success, or ok false with phase, code, message, line and column on failure.
Schema quick reference
| Item | Value |
|---|---|
| Schema | dsl.schema 2, name lmaudio |
| Context object | audio, of type Audio |
| Host types | Audio (28 methods), Buffer (58 methods), Spectrum (16 methods), Spectrogram (9 methods), Biquad (10 methods) |
| Host signatures | 171 |
| Standard signatures | 206 of lmcode_std_v3 (the current catalog has 226) |
| Total from lmaudio --lmcode-signatures | 377 |
| Units | seconds, Hz, linear amplitude unless a name says db |
| Sample rate | 100 to 384000 Hz, 44100 when omitted |
| Buffers | mono or stereo, 32-bit float, at most 200 million frames |
Main objects and functions
| Object | What it does | Main members |
|---|---|---|
| audio (Audio) | Makes sound and holds helpers | silence, sine, cosine, saw, square, triangle, chirp, impulse, noise, expr, additive, fm, karplus, pluck, modal, bar, drum, sequence, load_wav, stereo, biquad_design, note_freq, midi_freq, cents, db, print, save_text, assert_close |
| Buffer: levels and envelopes | Returns a new buffer | gain, gain_db, normalize, normalize_rms, normalize_lufs, fade, adsr, multiply, pan |
| Buffer: editing | Returns a new buffer | slice, pad, concat, mix, reverse, resample, channel, to_mono, pattern, granular |
| Buffer: filters and effects | Returns a new buffer | biquad, svf, ladder, lpf_sweep, convolve, reverb, zitarev, delay, chorus, flanger, phaser, compress, overdrive, wavefold, bitcrush, paulstretch |
| Buffer: measurement | Returns numbers | rms, peak, dc_offset, energy, zcr, duration, frames, sr, channels, get, pitch, lufs, rt60, peak_freq, centroid, thd, snr_db |
| Buffer: analysis objects | Returns Spectrum, Spectrogram or Buffer | spectrum, spectrogram, schroeder_db |
| Buffer: output | Writes files and returns the buffer | save_wav, save_csv, pitch_track_csv |
| Spectrum | Reads one FFT | mag_at_freq, peak_freq_in, peak_freq, peak_mag, db_at, phase_at, ifft, parseval_energy, save_csv |
| Spectrogram | Reads an STFT grid | frames, bins, time_at, freq_at, mag_at, db_at, ridge_freq, save_csv |
| Biquad | Exact filter response | gain_at, db_at, phase_deg_at, apply, save_response_csv, b0, b1, b2, a1, a2 |
| Standard functions | Values back to LMScript and general helpers | lmcode_return_put, lmcode_return_set, str_split, float_list, json_parse, file_write |
Minimal runnable example
Save as hello.lms in an empty directory and run lmscript hello.lms. It renders an arpeggio, normalizes it to -16 LUFS, checks the loudness, saves a WAV file and returns two numbers to LMScript.
# hello.lms: an A major arpeggio on a plucked string, checked and saved
mkdir("audio");
a = _lmcode_ cli="lmaudio" install="github:lmctl-ai/lmaudio@latest";
let arp = audio.sequence("A3:0.5 C#4:0.5 E4:0.5 A4:1.5", 120.0, "karplus", 22050);
let out = arp.reverb(0.8, 6500.0, 0.25).normalize_lufs(-16.0);
audio.assert_close(out.lufs(), -16.0, 0.01);
audio.print("pitch of the first note: " + str(arp.slice(0.0, 0.25).pitch()) + " Hz");
out.save_wav("audio/hello.wav", 16);
lmcode_return_put("lufs", out.lufs());
lmcode_return_put("seconds", out.duration());
end _lmcode_
r = run_lmcode(a);
println(json_stringify(r));
assert(r.ok);
lmscript hello.lms
pitch of the first note: 219.959988525778 Hz
lmaudio: warning: 1 sample(s) outside [-1, 1] were clipped while writing audio/hello.wav (16-bit PCM); normalize() first or save with bits=32
{"ok":true,"result":{"lufs":-16.00000004683295,"seconds":1.5000907029478459}}
More detail
- Skill: install, commands, safety rules, worked examples, errors and verification.
- Guide: concepts, architecture, the domain model and limits.
- Reference: every type, method, flag and exit code, plus the standard library.
- GitHub repository: README gallery, 22 runnable examples and releases.