Trading Fours

Play or hum a short phrase into your mic. When you stop, this page transcribes it into notes, builds a small Markov chain out of your own phrase's intervals and rhythms, and improvises a same-length response back at you — the way two players trade short solos back and forth.

Listen
Transcribe
Improvise
Respond

Tap the button and play a short phrase.
 
your phrase improvised response
How the response is generated (v1)

Pitch is tracked with browser-side autocorrelation on the mic signal, then quantized into discrete notes once a pitch holds steady for a few frames. From your note sequence, the page builds a bigram Markov chain over the semitone intervals between your notes, and samples note durations directly from the durations you actually played. It then walks the chain to generate a new interval/duration sequence — starting from your last pitch — until the total length matches your phrase, gently pulling the pitch back toward your range if it wanders.

This is a real-time, single-user stand-in for the clustering + outline method described in the Riff Jr. thesis, which trained on hundreds of measures of a specific artist's transcribed solos rather than one live phrase. Chord-aware generation, a real training corpus, and better polyphonic transcription are v2 territory.