System Structure
Vocal2Piano is a robotic piano accompanist built to play alongside a live singer—not just to replay a fixed sequence of notes. It turns a melody or an existing song into a piano arrangement, works out how two mechanical hands can perform it on a real keyboard, and adjusts the accompaniment as the singer pauses, resumes, changes volume, or sings in another key.
The project is a complete hardware+software system, designed and built end to end. Its physical players are two independently moving carriages, one for bass and one for treble. Each carries 13 solenoid-actuated fingers—seven for white keys and six for black keys—and travels along the keyboard on a belt driven by a stepper motor. Together, the 26 fingers can cover a much larger playing range than either carriage could reach while stationary. And the web app is where music is prepared, edited, rehearsed, and translated into a physically playable plan. It sends timestamped commands over USB Web Serial to a Teensy 4.1, which drives the motors and solenoids at the right instants and independently enforces hardware safety rules. When Listen Mode is enabled, microphone input feeds back into the performance, allowing the accompaniment to respond to the singer rather than forcing the singer to follow a rigid backing track.
System architecture
Mechanical Design (CAD)
The main mechanical challenge was to build a robot that could play across a full keyboard without installing a separate actuator on every key. I designed the entire assembly in Fusion 360, using two independently moving carriages to act as the robot's bass and treble hands.
Each carriage carries 13 JF-1039(B) solenoids — seven for white keys and six for black keys — giving the robot 26 independently controlled fingers.
A NEMA17 stepper motor drives each carriage through a GT2 timing belt, allowing the two hands to travel independently along the keyboard. Each hand can only cover approximately one octave at a time, so moving between positions is essential for reaching notes outside its immediate range.
The entire mechanism is mounted inside a custom keyboard-mounted enclosure that supports the moving assemblies and keeps the solenoid fingers aligned with the keys. The complete robot measures 1676 × 215 × 123 mm (L × W × H).

CAD animation — both robotic hands moving along the keyboard and pressing individual keys
Solenoid Finger & Carriage
The main mechanical challenge was converting the solenoids' short linear strokes into reliable piano key presses while keeping the entire mechanism compact. I designed lever-based finger mechanisms to transfer the solenoids' motion to the piano keys, with separate geometries for white and black keys to accommodate their different heights, lengths, and spacing. Each moving carriage integrates 13 independently actuated fingers (7 white-key and 6 black-key), driven along the keyboard by a NEMA17 stepper motor and GT2 belt. This design allows two robotic hands to cover a wide playing range with only two motors, while the software handles carriage positioning, note reachability, and collision avoidance.



Custom Electronics (PCB)
Driving 26 solenoids and two stepper motors requires significantly more power than a microcontroller can provide directly. I designed two custom 4-layer PCB types in KiCad: a central C0nTrollER board for power distribution and motion control, and two identical PLAyeRs boards for driving the solenoids.

Fabricated and assembled PCBs — one C0nTrollER and two PLAyeRs boards
C0nTrollER — Power & Motion Control
The C0nTrollER is the central control board, integrating the microcontroller, stepper drivers, and power-management circuitry. Key components were selected for their roles in precise motion control and reliable power delivery:
- Teensy 4.1: A high-performance microcontroller responsible for real-time command execution, motor control, and solenoid timing.
- TMC2209: Stepper motor drivers for independently controlling the bass and treble carriages.
- MP1584 buck converter: Steps the 12 V supply down to 5 V for the control electronics.

C0nTrollER — PCB layout

C0nTrollER — circuit schematic
PLAyeRs — Solenoid Driver Boards
Each PLAyeRs board drives the 13 solenoids on one robotic hand. Rather than controlling every actuator directly from the Teensy, I used a dedicated PWM controller and MOSFET switching circuits.
- PCA9685: A 16-channel PWM controller, allowing multiple solenoids to be controlled over a shared I²C connection.
- IRLZ34N MOSFETs: Low-side switches that control the 12 V solenoids without routing their current through the microcontroller.
- SS14 flyback diodes: Protect the switching circuits from voltage spikes produced when the inductive coils turn off.

PLAyeRs — PCB layout

PLAyeRs — circuit schematic
Music Processing & Motion Planning
Before the robot can play, the system needs to solve two problems: turning a melody into a musical accompaniment and making that accompaniment physically playable.
From Humming to Harmony
A hummed melody contains vibrato, pitch variations, and timing errors, so the app first converts the recording into clean musical notes before finding a suitable accompaniment.
- Pitch Detection: YIN tracks the voice every 10 ms, while note segmentation and adaptive tuning convert the recording into quantized notes.
- Key Detection: Krumhansl–Schmuckler key finding compares the melody against 24 major and minor key profiles.
- Harmonization: A hidden Markov model uses statistics from POP909 and McGill Billboard to score melody–chord compatibility and chord transitions. Viterbi decoding selects the best progression across the song.
- Arrangement: The chords are converted into five piano styles: block, broken, Alberti, stride, and bossa nova.
The result is an editable piano accompaniment created from just a hummed melody.
Music processing pipeline
Physically Constrained Motion Planning
A musically valid arrangement isn't necessarily playable by the robot. Each carriage reaches only one octave at a time, and repositioning takes time.
The planner uses Viterbi-based dynamic programming to find the best sequence of carriage positions and finger assignments, minimizing missed notes and unnecessary movement. A trapezoidal velocity model rejects moves that exceed the motor limits of 100 mm/s and 1000 mm/s². It also maintains at least five free white keys between the two hands and respects a 4 A solenoid-current budget. Unreachable notes can be shifted by an octave or omitted, with every adjustment shown in a playability report.
Real-Time Firmware
The web app decides what to play, while the Teensy 4.1 firmware, written in C++ with PlatformIO, handles when and how to play it.
Browser scheduling and USB communication introduce unpredictable delays, making them unsuitable for precisely timing individual key presses. Instead, the app streams commands 0.1–0.3 seconds ahead, each with a device timestamp. The Teensy stores them in a time-sorted command queue and executes each command at its scheduled time. A 50 kHz timer interrupt generates step pulses for the two TMC2209 drivers, while the firmware coordinates solenoid actuation. This keeps the robot synchronized with audio playback without relying on the exact arrival time of USB messages.
Real-time control architecture
Interactive Web App — Compose, Rehearse, Perform
I wanted the robot to feel like a usable musical instrument, not just a hardware demo. So I built a browser-based app in React, TypeScript, and Vite, styled like a retro desktop with movable windows and a Start menu.
The workflow starts in Songs, where a user can import MIDI or MusicXML, hum a melody, or start from a built-in chord loop. From there, the accompaniment can be edited by changing the key, tempo, piano style, chords, or individual bars and notes, with every change previewed directly in the browser using Web Audio.
In Rehearsal, the app shows how the two virtual hands move across the keyboard alongside the musical timeline. It also reports playability, making it easy to see which notes the robot can reach and which ones have been shifted or omitted.
When connected over Web Serial, the app can home the robot and stream timed commands for performance. It also includes a built-in manual, vocal-range tools, and performance feedback.

Web app — composing, rehearsing, and controlling the robot
Listen Mode
The most important feature is Listen Mode. While the song is playing, the app analyzes the microphone in real time so the accompaniment can respond to a live singer. Instead of acting like a fixed backing track, the robot can wait for a vocal entrance, pause when the singer stops, resume when they come back in, match their loudness, and even adapt to the key they are singing in. That interaction — a robot accompanist that follows the performer — is the core idea behind Vocal2Piano.
Demo — From Humming to Piano Accompaniment
One of my favorite features is being able to create a piano accompaniment from just a hummed melody. The demo below shows the entire process, from humming a simple tune to hearing the finished accompaniment.
Humming-to-accompaniment demo — from a recorded melody to an automatically harmonized piano arrangement