
Cochlea
io.github.richer-richard由 GitHub 帳號 richer-richard 發布v0.7.0更新於 Oct 24, 2026
Render, analyze, and verify audio (WAV/FLAC/mp3/ogg) offline and deterministically via MCP tools.
概覽
離線音訊引擎,讓助理把樂譜寫成資料、渲染出確定性音訊,再分析成 JSON 特徵與頻譜圖並驗證斷言。
- 可以做什麼
- 創作與渲染:render_score 把 RON 樂譜渲染為確定性 PCM,score_reference 回傳撰寫語法、預設與斷言說明。
- 分析音訊:probe_audio 與 probe_digest 輸出響度、起音、音高、旋律、調性、速度、節奏、立體聲、結構、靜音與削波,支援 WAV、FLAC、mp3、ogg。
- 視覺檢視:spectrogram 以內嵌 PNG 回傳頻譜圖,可疊加節拍、起音與音高標註。
- 比較與分窗檢視:audio_diff 在特徵空間比較兩個檔案,loudness_timeline 與 beat_grid 提供分窗檢視。
- 轉換與檢查:import_midi、export_midi、transcribe_audio 與 lint_score。
- 適用情境
- 適合助理需要產生或修改音訊、並在無人耳試聽的情況下用數字核對結果的情境,例如驗證響度目標、音符時值、音準,或確認重新渲染後音色未變。也適合對既有音訊檔案做音樂特徵分析。
- 執行需求
- 以本機 stdio 程序執行,可用 cargo install cochlea-mcp 從 crates.io 安裝(需 Rust 工具鏈),或使用打包的 mcpb 套件。未宣告帳號、API 金鑰或環境變數。可選 --root DIR 將檔案讀寫限制在指定目錄內。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Cochlea,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
cochlea
A headless audio engine for agents. Write a score as data, render it offline to deterministic PCM, then listen through numbers — loudness, onsets, pitch, key, spectrograms — and assert what you heard. Compose → render → probe → verify, with no human ear (and no audio device) in the loop.
[Mel spectrogram of first_light.ron: six note onsets followed by a reverb tail decaying to silence]
What the agent sees: the mel spectrogram of examples/scores/first_light.ron
— the score used in the example below — after render and probe. No PCM in
sight.
Or entirely from the command line, score as RON:
cochlea probe works on any WAV, plus FLAC (decoded bit-exact), mp3,
and ogg — still without ffmpeg, and with no score required. That's the
front door: point it at audio you didn't render, and you get the same JSON
report and spectrogram an agent uses to review its own work.
How an agent listens
compose → render → probe (JSON) → spectrogram (one vision call) → verify
- compose a score as data (RON, or the Rust builder above).
- render it to deterministic PCM —
cochlea render score.ron --out mix.wav. - probe the mix into a compact JSON report (loudness, onsets, pitch,
key, silence, clipping) —
cochlea probe mix.wav --json report.json. No image, no audio: the agent reads numbers. - look, when numbers aren't enough —
cochlea spectro mix.wav --out spec.pngrenders one small PNG the agent reviews in a single vision call instead of reasoning about raw samples. - verify —
cochlea render score.ron --verifyruns the score's embedded assertions and exits nonzero on failure. An agent can retry on its own, without a human confirming "yes, that sounds right."
When something in the middle of a long file needs a closer listen, every
read tool takes --from/--to. Probe just bars 17–19, or draw a
spectrogram of just the drop. The cut is frame-exact, report times are
relative to it, and source.start_ms records where it came from. That
turns the whole stack into a zoom lens instead of a whole-file-only
report.
The economics are the point here, not an afterthought. The first_light
render above is 7 seconds of 48 kHz 32-bit-float PCM, which is 2.7 MB. A
3-minute piece at the same settings runs about 66 MB. You would not hand
that to an agent as text, and reading it sample by sample is worse.
Its probe report is a few KB of JSON instead. Here is schema v5, trimmed
to the interesting fields. Note pitch.melody: the piece's bass line and
melody read back as note events, which is the read-back half of the
compose loop.
And the spectrogram is one small image. Here's the title_cue demo — a
pad whose cutoff_hz automation sweeps 250 Hz → 5000 Hz across bars 1–3:
The dark band at the top of the frame narrows as the sweep runs, letting
more high-frequency energy through over time. An agent reads that
straight off the image. The demo's Monotone(track: "pad", param: "cutoff_hz", ...) assertion checks the same thing numerically.
To get a whole piece in one image no matter how long it is, --sheet
tiles the spectrogram into a contact sheet instead of one long strip.
Two bars per tile here, via --bars-per-tile 2:
[Contact-sheet spectrogram of first_light.ron tiled two bars per row]
Reading audio without a context window
probe --digest skips JSON and prints a deterministic text summary
instead: one line per feature dimension, then a windowed timeline capped
at about 40 rows. Here's real output for the drum_groove demo — 20.8
seconds and four tracks, with the rhythm, stereo, and structure
dimensions all in one screenful:
Tempo and rhythm are reported as separate axes, because they change independently. A drum solo can hold a rock-steady pulse while its pattern turns unrecognizable, and that difference is exactly what an agent needs to see.
Here the tempo reads 110.3 BPM, matching the authored 110, and
stability 1.00 says the speed never moves across the piece. The alts
list surfaces the genuine half-tempo reading at 54.9 BPM — which is
actually the stronger raw peak, with the octave prior breaking the tie
toward the beat. Metrical ambiguity like that is data an agent can weigh,
rather than a coin flip hidden inside the detector.
The rhythm line then says how the hits relate to that pulse: 98% of
onsets sit on the beat-subdivision grid and 56% land on off-beat
subdivisions, so clear=true. That's an eighth-note hat groove, with its
syncopation reported as a number.
Under the pre-0.2.0 metric this same groove read clear_rhythm=false at
confidence 0.01. Layering hats, kick, snare, and pad across three
metrical levels diluted every lag's share of a mass-fraction score. The
grid-based rule asks the right question instead.
The (straight) tag is the grid hypothesis test: alignment is measured
against both straight sixteenths and eighth-note triplets, and the report
carries whichever more hits land on. A shuffle or swing take reads
grid_align=1.00 (triplet) — recognized as an aligned triplet rhythm —
instead of being force-fit to sixteenths and scored sloppy.
cochlea diff compares two files in feature space instead of byte-for-byte
— "did my change do what I meant," not "is the file bitwise equal." Real
output diffing first_light.wav against title_cue.wav:
The timbre row is an MFCC spectral-shape distance, with c0 excluded
since that's just loudness. The same instrument re-rendered measures
around 0, while swapping a sine for a saw at matched loudness measures
well above it. It's the "did the re-render keep the instrument's
character" axis, which loudness and pitch can't see.
Add --spectro delta.png and the diff also renders a signed difference
heat map: red where B is louder, blue where it's quieter, black where
nothing changed. A moved onset shows up as a blue/red vertical pair, and
a brightened sweep as a red wedge. What changed becomes visible
structure, not just a number.
Diff a render against itself, or a re-render of the same score, and the
verdict reads byte-identical instead — the determinism contract above,
checked from the outside. --tier2 turns that verdict into a gate: exit
0 for byte-identical or Tier-2-equivalent, exit 1 otherwise, so a CI job
or an agent can catch a regression without ever reading a raw sample.
Agents as MCP clients
cochlea-mcp is a stdio MCP server built on the same libraries the CLI
uses. It exposes twelve tools — render_score, probe_audio,
spectrogram, lint_score, probe_digest, loudness_timeline,
beat_grid, audio_diff, import_midi, export_midi,
transcribe_audio, and score_reference — each a thin wrapper over the
matching library call. Any MCP client gets the same compose → render →
probe → spectrogram → verify loop as tool calls, rather than as
shelled-out subprocesses.
What makes it agent-native rather than a CLI in a trenchcoat:
- It teaches itself.
score_referencereturns the complete authoring reference — the RON grammar, the live preset catalog with every automatable parameter (generated from the same registry that validates scores, so it can't go stale), allverify:assertions, and a worked example the test suite itself renders. An agent connected cold can compose without ever seeing this repo. - It shows, not points.
spectrogramreturns the image inline as MCP image content (base64 PNG, size-capped), so a client with no filesystem access still gets the one-vision-call review;out_pathis optional.annotate: truedraws the detected beats, onsets, and pitch onto the image, andaudio_diffcan return the signed difference heat map the same way. - It zooms.
probe_audioandspectrogramtakefrom_s/to_s— lean into 42.0–44.5 s of a long file the way a human replays a bar, instead of paying for whole-file analysis every call. - It can be confined.
cochlea-mcp --root DIRrefuses any read or write that resolves (canonically — symlinks and..included) outsideDIR, before touching the filesystem.
Full tool schemas, arguments, and the JSON-RPC framing are in
docs/mcp.md.
Install
All nine crates are on crates.io:
Or from source: git clone https://github.com/richer-richard/cochlea && cd cochlea && cargo install --path crates/cli.
Concepts
Score IR (cochlea-score). A score is plain data: tracks, notes,
per-parameter automation, a tempo map of step changes, and an optional
master section. It serializes to RON (version: 1) and round-trips both
ways under test.
Positions read the way you'd say them — bar(3).beat(2) — and durations
are exact fractions: Dur::quarter(), "3/16", with dotted and triplet
sugar. A position that doesn't land on the tick grid is an error, not
something quietly rounded. cochlea import reads Standard MIDI Files with
timing intact: SMF ticks land on the grid verbatim, and GM programs become
labeled preset guesses.
Integer time is ground truth. Everything is ticks at 960 PPQ. BPM is
converted once, up front, to integer nanoseconds per quarter note. Turning
ticks into samples is exact rational u64/u128 arithmetic (fenestra-anim's
mul_div), applied once when events are scheduled. Nothing accumulates
floating-point seconds, nothing reads a wall clock, and a property test
holds it drift-free across 10⁹ ticks.
Synth (cochlea-synth). Eleven presets built on fundsp. Eight are
subtractive: sine, saw_lead, square_bass, chord_pad (genuinely
stereo — its detuned saws pan apart), noise_hat, pluck, kick, and
snare. Three are not: fm_bell (harmonic FM with an automatable
brightness), marimba (a modal struck bar), and organ (an additive
drawbar). There's also a reverb insert.
Each instrument declares its automatable params with a name, unit, range,
and default. Scores are validated against that registry, and the same
registry generates the authoring reference, so the docs can't drift from
the code. All noise comes from a counter-based RNG keyed on
(seed, sample_index) — random access, with no stateful generator
anywhere.
Renderer (cochlea-render). Audio is rendered in 64-sample blocks,
split at event boundaries, so note timing is sample-accurate while
automation runs at control rate (~1.3 ms at 48 kHz). Tracks render
independently, which is both the parallelism unit and where stems come
from for free. Voice allocation and oldest-note stealing are pure
functions of the schedule.
The master bus sums stems at f64 in fixed track order, then applies the
score's optional master stage: an output gain, and a brick-wall lookahead
limiter whose sample-peak ceiling holds exactly (offline, lookahead is
just a forward window maximum — no delay line). That's the tool for
hitting a LUFS target while leaving TruePeakBelow headroom. With no
master section, the mix is byte-equal to the sum of the stems, both by
definition and by test.
Features (cochlea-features). One schema-versioned JSON report,
covering:
- loudness — integrated LUFS, momentary max, true peak, and LRA, via ebur128;
- onsets from spectral flux, and YIN pitch with cents deviation;
- a quantized melody: note events an agent can diff against what it wrote;
- an MFCC timbre digest, and chroma plus Krumhansl-Schmuckler key;
- tempo and rhythm as separate axes — tempo gives pulse clarity, octave
alternatives, and windowed stability, while rhythm gives grid alignment
(with a straight-vs-triplet hypothesis test), offbeat ratio, and a
calibrated
clear_rhythm; - stereo width, correlation, and balance;
- structure boundaries via Foote novelty, plus silence, tail, and clipping.
On top of that: a windowed segment timeline, an LLM-sized text digest, a
feature-space diff between two files, and frame-exact windowing
(Audio::window) behind every --from/--to.
Spectro (cochlea-spectro). Mel spectrogram PNGs, with an HTK
filterbank, viridis colors, a time ruler, and bar markers. It can draw
analysis overlays on the image (beat grid, onsets, pitch), render a signed
A→B difference heat map, and tile a whole piece into a contact sheet so an
agent can review it in a single vision call.
Verify (cochlea-verify). The assertion DSL shown above. The same
assertions embed in score RON under verify:, and cochlea render score.ron --verify runs them, exiting nonzero with a machine-readable
JSON failure report.
Determinism, precisely scoped
Audio is a fold, not a map: filters and delays carry state, so per-sample purity is not the contract. The contract is three tiers:
Tier 1 is bought with a specific set of choices:
libmfor every transcendental in a DSP path. The std float methods are banned by clippy config, not by convention.- No fast-math and no implicit FMA.
mul_addis banned too. - Denormals are honored everywhere. Flushing them is a realtime performance hack, and x86 and aarch64 can't even do it uniformly. We render offline and eat the rare slow tail.
- Fixed summation order, and an f64 master bus.
- Voices tick sample by sample. fundsp's SIMD block path provably diverges from its scalar path, so it's banned.
- Analysis FFTs use
FftPlannerScalar, which does no runtime CPU dispatch.
The full audit trail — per fundsp node family, ebur128's internals,
rustfft's dispatch — lives in
docs/determinism.md.
Feature accuracy (synthesized ground truth, 48 kHz)
ffmpeg-free by design
cochlea reads WAV, FLAC, mp3, and ogg/vorbis using hound and
symphonia, both pure Rust. It writes plain WAV, and renders PNGs on the
CPU with rustfft, a hand-rolled mel filterbank, a viridis LUT, and
image.
There are no subprocess calls, no system codecs, no GPU, and no audio
device. The whole pipeline is a pure Rust dependency graph, and CI blocks
GUI, GPU, and device crates from ever entering Cargo.lock (deny.toml).
Decoding comes with two different promises, and it's worth being clear about which is which. WAV and FLAC decode bit-exact — FLAC is lossless by spec, and it's checked against WAV twins in-tree. mp3 and ogg are analysis input only: reproducible for a given build, but a lossy codec already threw the original samples away, so there's no exactness claim left to make.
Assertion cookbook
The same assertions embed in score RON:
cochlea render score.ron --verify runs them; failures come back as JSON
({"passed": false, "checks": [...]}) and a nonzero exit.
To actually hit a loudness target rather than just assert it, give the score a master bus — gain to push, a limiter to hold the ceiling:
Four worked demos live in demos/:
metronome— sample-exact scheduling and onset tolerances.chord_pad— harmony reads back as written.title_cue— a four-bar cinematic sting that asserts a LUFS target, a monotone filter sweep, click-freedom, and silence after the fade.drum_groove— a 110 BPM eight-bar groove on the realkickandsnarepatches, hats panned right and snare left. It asserts detected tempo,HasClearRhythm(true)with grid alignment ≥ 0.9, stereo width, loudness range, and section count.
drum_groove is also the fixture that motivated splitting tempo from
rhythm: the old single confidence metric read it as rhythm-less at 0.01,
despite getting the BPM spot on.
Workspace
features and spectro depend on neither score nor synth — enforced
in CI — which is why probe works on arbitrary audio files with no score
in sight.
License
MIT OR Apache-2.0, at your option.
來源:README.md,提交 f8457c1
工具
0版本歷史
1- v0.7.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分