Inspiration
Everyone on our team has a connection to music. Some of us produce, and others sing or perform. One of our teammates used to produce music with a close friend. This friend was in a car accident that damaged both of their hands. They can no longer do anything that needs fine hand control, like using a mouse, typing, or playing a piano. Producing music had always been how they relaxed, and it was suddenly out of reach when they needed it the most.
Many people are in a similar situation. Music has two sides: listening and making. We know listening to music is universally considered healing, but we overlook the producing part. We wanted to give people who have lost the ability to make music a new interface to be able to do so. HandsFree Studio is built for anyone who can't produce music with their hands due to reasons like arthritis, ALS, or paralysis, or for people who are recovering from accidents and can't use their hands even temporarily.
What it does
HandsFree Studio enables you to produce music without using your hands. You use your face as the cursor and your expressions, such as opening your mouth or raising your eyebrows, to select and click. We have head and eye movement pointers for various situations to have a smooth cursor experience. Our simplified interface translates your input into MIDI and sends it to FL Studio in real time. FL Studio is industry-renowned, widely used music production software.
With HandsFree Studio, you can:
- Play individual notes and record note patterns.
- Record chord progressions.
- Program beats with drums and hi-hats, and loop them under the melody.
- Hum a melody and have it turned into notes in your key for any instrument that you select.
- Switch instruments, such as piano, violin, strings, and voice.
- Control basic functions like pause, play, resume, record, higher octave, lower octave, etc., with the on-device voice assistant Mozart.
- Describe what you want to our Gemini-powered voice assistant Travis. For example, make an A minor chord progression over 4 bars and play the notes on the current track. This will process and generate your request and put it on the track you desire.
How we built it
Face tracking
We used OpenCV to get the webcam feed of the laptop they use and MediaPipe in Python. MediaPipe Face Landmarker gives us 478 face points for the head pose and blend shapes, such as open mouth and raised eyebrows.
Navigate mode (head)
Your head angle sets where the pointer goes. It is smoothed with a One Euro filter. Making a gesture moves your face, which would normally shift the pointer. To prevent that, each click is locked where the pointer was before the gesture has begun.
Play mode (eyes), for faster music over 90 BPM
Switching to play mode enables an eye tracking model that uses both eye and head movement for faster control. This reduces functionality and restricts you to 8 notes instead of the usual 12 on the screen. We use eye and head movement because eye movement alone is too subtle for a webcam that is an arm's length away to read confidently.
You can calibrate eye tracking by following a moving dot for a few seconds. The model refines itself with every click, and you can recalibrate anytime your head position changes.
Voice assistants
We have two voice assistants, both triggered by a word:
- Mozart handles on-device commands like play, stop, record, undo, increase tempo, decrease tempo, increase and decrease the octaves, switching different modes, switching different tracks, and any other functionality you might do on the app itself.
- Travis is the creative assistant built on the Gemini API. You can describe whatever music or whatever progression you want, with however much or little detail, and Gemini returns it as a structured JSON. This JSON is interpreted by HandsFree Studio, validated to see if it's legitimate music, and then it converts to MIDI. This converted MIDI is, again through HandsFree Studio, sent to FL Studio, where it'll reside in one of the tracks.
Gemini setup
Travis uses a strict JSON schema. Each project has its own memory file, so you can refer to earlier requests and ask for changes. For speed, we query two Gemini models at the same time and use the response of whichever one answers first. We also have a small offline rule-based parser that handles more simple requests like "play these notes in order" or "play these two chords in order." Open-ended questions like "can you play an A minor progression" or "add a drum beat to my melody" go directly to Gemini.
MIDI
Python RT MIDI sends notes, and sends commands as Control Change messages, over a virtual MIDI port between HandsFree Studio and FL Studio. A custom FL Studio controller script, which is written in Python against FL Studio's MIDI scripting API, carries out the commands inside FL Studio.
UI
We have a local web interface with HTML, CSS, and JavaScript that runs a native window through PyWebView, so it feels like a desktop app.
Challenges we ran into
- Face to cursor: mapping head movement to a cursor that feels natural and is smooth.
- Talking to FL Studio: we had to work out how to send MIDI notes and commands from our hands-free interface to FL Studio.
- Misclicks: opening your mouth or raising your eyebrow also moves your nose, which is the main point the cursor refers to. The cursor jumps as you attempt to select and many times selects the wrong thing. We fixed it by locking each click to the pointer's position just before the gesture has begun.
- The Gemini output: we needed consistent, structured output. We needed to give it enough context without making requests so large they got slow. We learned to query several models at once and take the first valid response.
- Background chatter: commands like stop, play, resume, and record kept firing during normal conversation, so we added a wake word. The app only listens to a command and processes it as a command after hearing the two keywords Mozart and Travis.
- Snapping clicks: face control is very shaky since a head can't be perfectly still. If you click a little bit off a button, the app assumes you meant the nearest one as long as it's close enough. We had to iterate through many radii to determine the most intuitive distance for a close-enough click.
- Rounding hummed notes: we have a hum mode that rounds each pitch that you hum or sing to the nearest note in the current key you have selected and also maps the timing to the nearest sixteenth note. A sixteenth note is a quarter of a beat. We had the design decision of whether to round it live or after the take is done. We chose the live option because instant feedback enables the users to notice it right away when something's being misheard or misinterpreted, instead of finding it after a full recording.
- Speed limits of head control: when you go above 90 BPM, head movement was too unsteady to record and started to hurt after a couple of measures, so we added eye tracking as a mode. You can switch for faster songs. This limits functionality in terms of the number of notes you can play at once but enables you to play those fewer notes at a faster pace.
- Eye tracking from an arm's length: the eyes only take up a few pixels in the webcam frame, and processing high-res frames 30 times a second is too slow for a real-time cursor. We tried many calibration methods, and none were precise enough, so we redesigned the screen instead. When you are in eye tracking mode, there are fewer, bigger targets. Play mode shrinks to 8 large pads in a 4-by-2 grid, whereas before it was 12 large pads in a 4-by-3 grid. Moving left to right between them is easy for the eyes compared to up-and-down movement, just because of how much the eye moves to see up and down versus side to side. To compensate for the lack of eye movement when going up and down, we decided to combine it with a slight nod or lift of the face to move between the top and bottom row. The split felt intuitive and works for recordings up to and about 120 BPM. It's not a complete fix, but a way to mitigate it with the technology we currently have.
Accomplishments that we're proud of
- A fluid head cursor. Initially, our cursor was very choppy, had about 10 frames a second, and was very hard to maneuver. Now our cursor is fluid enough that after a few minutes of using it, it feels intuitive and almost as fast as a regular mouse or trackpad. The movements are small enough to use comfortably for 30-minute sessions without feeling much neck strain.
- Simple interface to capture a robust, complex existing software. FL Studio can take hundreds of hours to master. We created an interface you can learn in under an hour. It doesn't expose everything FL Studio can do, but it's enough to produce various instruments, vocals, and beats to produce basic songs, which is a great starting point.
- Understanding intention. We went through many app iterations on voice and gestures, stopping the app from treating conversations like commands, stopping it from reading every face movement as a gesture, and telling what a user means from what they happen to do. That was the core of the project. All the data we get is from the mic for the audio and the camera for the video. Trying to understand intentions and sometimes avoid or infer actions needed a lot of thought, and we have, through iteration, compensated for many edge cases.
What we learned
From a technical standpoint: Libraries like media pipe, vosk for transcription, sounddevice for voice inputs, mido for making midi messages, python-rtmidi for a virtual midi port, pywebview to give the feel of a desktop app while being web based, Json parsing to see if outputs were in the correct format, One Euro filter smoothing algorithm for smooth cursor feel, automaing MIDI protocols, implementing redundancies to increase accuracy.
More general:
- There are many libraries for almost everything you need if you look enough for it. We were already aware of OpenCV to access the webcam, but initially, we thought we might have to make a full face model. That's where most of our manpower would go. Upon research, we found that MediaPipe already has this capability. After understanding and implementing the MediaPipe API, we were able to expand the scope of our project to much more.
- Every action needs more than one way to do it, especially because of the fragility of these inputs. The head and the eyes are used for pointing the cursor in different situations. We have two ways of selecting: opening your mouth and raising your eyebrows. This is to account for the fact that one might not work sometimes, or your mouth might get tired, or your eyebrows might get tired, and you want to switch. Every command also accepts several phrasings, like "continue" and "resume," which both do the same thing. We asked people how they would naturally say each command, and to make this app as intuitive as possible, we supported the most common ways we found people to express these commands.
- This was out first time working with LLM APIs. We assumed Gemini's output would always follow our schema because we told it to in the prompt, but sometimes it returned something that was absolute rubbish. Now we have a validator that checks every response before converting it into MIDI and then feeding it to FL Studio.
- Every extra operation we want per frame slows the whole app, so for a fluid cursor, we accepted more false positives. We'd rather be about 80% fluid with occasional misreads than misread rarely but feel only about 50% to 60% as smooth.
What's next for HandsFree Studio
Since FL Studio is such feature-rich software, for a person to be able to take advantage of that using our simplified interface, we need much more functionality. The voice command feature needs to be much more robust and add support for picking an instrument, jumping to a specific place in a song, and also post-production actions like adding reverb, fading two tracks, cutting, splitting, and all these advanced features. These can all be done with voice command and eye movement, or face movement, but it needs much more thought and time to be implemented.
The biggest improvement we can have for HandsFree Studio out of the current features is the eye tracking. We think being able to build a more robust, fine-tuned model instead of the general-purpose MediaPipe face landmarks would be greatly beneficial because we have a rigid structure of where the eyes are most likely to be. We don't need to assume that an eye can be in any space on the screen. We just need to assume which of the 8 places it is most likely to be, given the current eye position. Building a custom model for eye tracking would be very beneficial.
Another improvement would be combining our two voice models, Mozart and Travis, into one. After getting an input, it would decide whether this is a task that needs to be sent to Gemini, or this is an on-device command, or it is meant to be an on-device command and can be executed that way.
Built With
- fl-studio
- gemini
- gemini-api
- javascript
- json
- mediapipe
- opencv
- python
- vosk