Controlling your computer’s volume with your brain

Neha Adapala
7 min readJan 28, 2024

--

Have you ever wished that you would be able to change what your computer does with just your brain?

Maybe it sounds like a superhero story to you but I’ll tell you how you can be as cool as a superhero too — just keep reading.

You can write words, switch tabs/ windows or skip through videos. Today I’ll be showing you how you can increase the volume on your computer.

WHAT YOU NEED:

  • Muse headband (I use the Muse 2 headband)
  • A computer

Yeah that’s about it…

  1. Download Python

For this project, I decided to use Python. Go to https://www.python.org/downloads/ and download the latest version that works for whatever your device is. You can click on the yellow links to change the version that you’d like to download

2. Download Visual Studio Code

I chose Visual Studio Code because it’s free and easy to use, especially because so many other people use it as well, so they’ll come across similar problems to you and provide solutions online when they find them. Go to https://code.visualstudio.com/Download and download the latest version that works for your device.

If you’d like to find out more information about your Mac to check if the download will work. You can check it by clicking the small apple in the top left > About this Mac > More Info.

3. Learn how to use the Muse headband

To learn how to properly connect the Muse headband for the best connection, I would recommend downloading the Muse app and following all of those steps first. Once it’s connected properly there, disconnect it, because Muse can only connect to 1 device at any certain time.

4. Download an outlet

An outlet is necessary for your muse headband to display the signals on your computer. Therefore, I chose my outlet to be Petal Metrics. Simply download it and follow the instructions to make it an application on your device.

5. Navigating Petal Metrics

Now, just open Petal Metrics and under Type, click LSL and click the STREAM button. If you scroll down, it should show that it is connecting, or that it is streaming + the name of your Muse headband.

If it doesn’t show that it’s connecting, make sure that it is disconnected from ALL other devices.

6. Downloading Github code

Great! Now we want to actually see what the signals look like. Luckily, alexandrebarachant on Github has created a Python package to stream, visualise, and record EEG data from our Muse headband. We just need to have this in our own code.

First, go this link and click on the dropdown of the green button that says Code. Then, press the copy button that I’ve circled.

7. Working with VS code

Now go back to Visual Studio Code (VS Code) and click on the below items in the order of the numbers. (For step 3 you have to copy the link into the bar).

After this, click the terminal button at the top of your screen (circled below) and click New Terminal — the first option.

8. Installations

Now in the terminal, you have to install some python dependencies using Python. You should see a screen like the one in the picture.

Now in the terminal type the following commands each on one line and press the return button after each line:

pip install muselsl
pip install pygatt
pip install numpy
pip install matplotlib
pip install pylsl
pip install os-sys
pip install scikit-learn
pip install scipy

If pip doesn’t work, try replacing pip with pip3.

9. Viewing the signals

Perfect! Now just type in muselsl view into the terminal to view the signals. You should see something like the image below.

These are YOUR brain waves. They might look all over the place- this might be because your signals aren’t the most accurate (a problem that many Muse headband users may face) or it’s just how your brain waves are. To help with this, consider meditation, which can be done using the actual Muse app — the headband was intended to help with meditation.

10. Finding out when you blink

Now, exit the terminal and go back to the code. Go to muse-lsl/examples/neurofeedback.py. All the fun stuff we’re gonna work on will be happening in section 3.3 COMPUTE NEUROFEEDBACK METRICS.

Blinking.

We’ve all blinked before- the average person blinks ~21,600 times per day! What if I told you that by purposefully blinking you could change the way your computer is currently functioning!! Essentially, if the value of your brain’s delta waves are all greater than 1, it probably means that you’re blinking. You can test this by looking at the values of your delta waves when you blink. Just write the code:

print("Delta: ", band_powers[Band.Delta])

If you try to continue following the tutorial you’ll probably notice that for every one blink that you take, you increase the volume 10 times. To solve this, go to the experimental parameters section and look at the overlap length. The shift length is how often a new eeg measurement will be taken. Right now it’s 0.2 seconds. When you blink, you take a fairly long amount of time.

To account for this, you want to make the shift length just 1 second. The epoch length basically means the period of time that the code takes to give to the FFT (fast fourier transform), which is used for signal processing. To make this as smooth as possible, for something like detecting what state your brain is in (e.g. focussed), it is super useful to have a high overlap length so the signals are accurate.

However, when you want to record blinking, it’s not as useful, since you only want to know when you are blinking or not. That’s why you should change the overlap length to 0.

Perfect! You can now recognise when you’re blinking.

11. Doing something when you blink.

Great, you know how to find out you’re blinking… but now what?

Pyautogui is a super useful library where you can create scripts that can simulate mouse movements, click on objects, send text, or use hotkeys. To get started it’s important to do installations! You know the drill. Go to the terminal in VSCode and type this in:

pip install PyAutoGUI

Once it’s installed, you want to add:

import pyautogui

To the very top of your code in neurofeedback.py. This means that your code knows what you’re referring to when you use pyautogui.

Now just type in (in the section 3.3):

Woohoo! You did it!! But if this doesn’t work for all of you do not fret and keep reading.

12. Solving problems

A problem that I faced was that press doesn’t work for all the keys in macOS. If you face this problem too, all you have to do is run

press()

That will probably give you an error. BUT it’s important to get the error because it leads you to the solution. Check the file path of where the problem is coming from. Then, using the terminal, find the file “_pyautogui_osx.py”. You can do this by using pwd, cd and ls. This will vary from computer to computer, so check out this article to learn more about basic terminal commands.

When you get to the file, change

To:

Amazing!! Now you can make all of this come true by typing this in:

WOW!! Well done! You did it!!!

12. Other possibilities

This doesn’t just stop here though. With pyautogui you can do so much!

Yes! You can do all of this with just pyautogui. Also it doesn’t just have to be blinking. You can also change your computer by detecting how focussed you are (check my previous tutorial on that out). For example, you can increase the volume when you are less focussed and vice versa!

Let me know if you tried this out by contacting me on email at neha.adapala@gmail.com, I would love to see what you come up with!

--

--

Neha Adapala

Hi! Feel free to contact me about anything from natural sciences to arts. My interests mainly lie in technologies though!