@miadi/songbird
v0.1.1
Published
Sing a phrase, keep it as a MIDI take: Songbird's capture chain (save the voice, transcribe it, align it if asked, write the .mid, attach both to a composition), its key and intonation reading, and the piano-roll layout of a take. Browser-first and framew
Readme
@miadi/songbird
Sing a phrase, keep it as a MIDI take. This is Songbird without a framework: the
chain that turns a recording into a take, the key and intonation of a take, and
the geometry of its piano roll. @miadi/songbird-ui draws the card.
Songbird belongs to the musical composition domain. It authors MIDI from a sung phrase; the capture domain only records what already exists.
The chain
import { runTakeChain, attachTake, httpSongbirdTransport } from "@miadi/songbird"
const take = await runTakeChain(chunks, recorder.mimeType, {
ext: ".m4a",
bpm: 92,
align: true, // snap to sixteenths at 92 BPM; the sung positions stay in rawNotes
deferAttach: true, // judge first, keep after
}, (message, kind) => show(message, kind))
// when the singer says keep (null: nothing was recorded)
if (take) await attachTake(take, "chanson-d-ete", "Chanson d'été", "verse two, softer")- The voice is saved, first and always.
- It is transcribed from the saved file.
- The notes are aligned to the tempo, only when that was asked before the take began.
- The notes are written as a
.midnamed after the voice (ava8-core's writer), at the take's tempo when it was aligned, otherwise at 120 BPM. - Both are attached to a composition, at once or when the singer keeps the take.
Each step that fails leaves what was already saved and says what is missing.
Neither function rejects. attachTake answers how far it got
(midiAttached, voiceAttached), so a failed attach stays visible and can be
retried. acceptReplacement removes a previous take only after its
replacement is attached, and only through the remover the host passes.
The I/O is a SongbirdTransport the host passes as { transport }:
importFile, analyze, attachMidi, attachVoice. The default,
httpSongbirdTransport(), speaks gmtermux's routes over fetch (/import,
/api/nyro/analyze, /api/compositions/<slug>/midi and /clips); a host with
other routes or a token names them.
The take, read
| Export | What it answers |
|---|---|
| keyFromNotes(notes) | The key of a transcription, { key, tonic, mode, confidence }, or null under five hops of evidence. Each note weighs its duration in live-detector hops (HOP_SECONDS), so a take and a live phrase are read with one threshold. |
| histogramOfNotes(notes) | The 12-bin pitch-class histogram behind it. |
| centsOffPitch(note), centsOff(note) | Cents from the note's equal-tempered center, from its hzMean; 0 when it carries none. |
| layoutTake(notes, { width, rawNotes, bpm, aligned }) | The piano roll as geometry: a row per pitch sung (highest on top), a block per note with inTune (within 15 cents), ghosts where alignment moved a note, beat lines when a grid applied. |
| noteNameOf(midi) | 69 → A4. |
The browser's half
pickRecorderFormat() asks MediaRecorder for mp4 first (iOS records nothing
else), then webm, and answers null where there is no recorder.
openMicrophone() asks for the raw microphone, echo cancellation, noise
suppression and gain control off, and falls back to plain audio.
micErrorMessage(error) says why the microphone failed in words a singer can
act on.
The package imports no Node built-in. Browser globals are read only when a function is called.
The live lane
While a phrase is sung, listenToPitch(stream, onNote) reads the microphone every
80 ms and calls onNote each time a new note has held for three reads: the numbers
of gmtermux's live lane (#54), with the same YIN tracker the saved take is read with.
It answers null where there is no Web Audio, and stop() closes its audio
context; the stream's tracks stay the caller's. createNoteSteadier and
readLiveNote are the same rule without audio, for a test or another source.
@miadi/songbird-ui useLivePitch and LiveNoteLane draw it.
