Showing posts with label controlling. Show all posts
Showing posts with label controlling. Show all posts

Controlling music with your mind

Last year I bought an EEG headset (the Mindwave Mobile) to play with my Raspberry Pi and then ended up putting it down for a while. Luckily, this semester I started doing some more machine learning and decided to try it back out. I thought it might be possible to have it recognize when you dislike music and then switch the song on Pandora for you. This would be great for when you are working on something or moving around away from your computer.

So using the EEG headset, a Raspberry Pi, and a bluetooth module, I set to work on recording some data. I listened to a couple songs I liked and then a couple songs I didnt like with labeled data. The Mindwave gives you the delta, theta, high alpha, low alpha, high beta, low beta, high gamma, and mid gamma brainwaves. It also approximates your attention level and meditation level using the FFT (Fast Fourier Transform) and gives you a skin contact signal level (with 0 being the best and 200 being the worst).

Since I know very little about brainwaves, I cant make an educated decision on what changes to look at to detect this; thats where machine learning comes in. I can use Bayesian Estimation to construct two multivariate Gaussian models, one that represents good music and one that represents bad music.



----TECHNICAL DETAILS BELOW----
We construct the model using the parameters below (where ? is the mean of the data and ? is the standard deviation of the data):










Now that we have the model above for both good music and bad music, we can use a decision boundary to detect what kind of music you are listening to at each data point.





where:






The boundary will be some sort of quadratic (hyper ellipsoid, hyper parabola, etc) and it might look something like below (though ours is a 10 dimensional function):
 

----END TECHNICAL DETAILS----

The result is an algorithm that is accurate about 70% of the time, which isnt reliable enough. However, since we have temporal data, we can utilize that information, and we wait until we get 4 bad music estimations in a row, then we skip the song.

Ive created a short video (dont worry, I skip around so you dont have to watch me listen to music forever) as a proof of concept. Then end result is a way to control what song is playing with only your brainwaves.


This is an extremely experimental system and only works because there are only two classes to choose and it is not even close to good accuracy. I just thought it was cool. Im curious to see if training using my brainwaves will work for other people as well but I havent tested it yet. There is a lot still to refine but its cool to have a proof of concept. You cant buy one of these off the shelf and expect it to change your life. Its uncomfortable and not as accurate as an expensive EEG but it is fun to play with. Now I need to attach one to Google Glass.

NOTE: This was done as a toybox example as fun. You probably arent going to see EEG controlled headphones in the next couple years. Eventually maybe, but not due to work like this.

How to get it working


HERE IS THE SOURCE CODE

I use pianobar to stream Pandora and have a modified version of the control-pianobar.sh control scripts I have put in the github repository below.
I have put the code on Github here but first you need to make sure you have python >= 3.0, bluez, pybluez, and pianobar installed to use it. You will also need to change the home directory information, copy the control-pianobar.sh script to /usr/bin, change the MAC address (mindwaveMobileAddress) in  mindwavemobile/MindwaveMobileRawReader.py to the MAC address of your mindwave mobile device (which I got the python code from here), and run sudo python setup.py install.

I start pianobar with control-pianobar.sh p then I start the EEG program with python control_music.py, it will tell you what it thinks the song is in real time and then will skip it if it detects 4 bad signals in a row. It will also tell you whether the headset is on well enough with a low signal warning.

Thanks to Dr. Aaron Bobick (whose pictures and equations I used), robintibor (whose python code I used), and Daniel Castro (who showed me his code for Bayesian Estimation in python since my implementation was in Matlab).


Consider donating to further my tinkering.


Places you can find me
Read More..

Controlling Raspberry Pi via text message

This script enables you to control your computer via text message. Think of it almost as a version of SSH over text message.

It is designed to intelligently and quickly check unread Google voice messages. If certain parameters are passed, it runs the command you send and returns the result.
This is the third script in my AUI (Alternative User Interface) Series.
This requires curl and libboost1.50-regex. The setup script can install curl and boost regex. 

NOTE: This will work with any linux OS but I am using it on the Raspberry Pi so if you are using something else, you will have to compile it yourself (make sure to change the Makefile flags).

The stable version is on github here:
https://github.com/StevenHickson/PiAUISuite

And the working copy source can be found here:
http://stevenhickson-code.googlecode.com/svn/trunk/AUI/TextCommand/


Google Voice unfortunately doesnt have an API available so I started writing my own.
I found this page and this page which were good references. Unfortunately, neither of these actually worked, so I wrote my own based off them. The script will install this and you are free to use it however you want as long as you cite me and follow GPLv3.

It works by using cron to run a script once every minute. The script checks your unread inbox messages and uses curl to make sure certain safety parameters are met. It is very important to check the unread inbox as it only pulls a 1-3 KB file rather than a 150+ KB file. This really adds up once a minute over time. If certain parameters are met, ie it has a valid phone number and command, then it runs the command you give it. The results of the command are then texted back to you. 
This will not work with interactive scripts like more or man



Installation Instructions

(this requires git)

sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


There are other scripts in here that you can ignore. It will ask you the username details in the script.
This will be your Google voice username, password, key, and valid number.

Your Google voice username will be your e-mail. For example:
John.Doe@gmail.com
Your password is your Google voice password:
ThisIsntMyPassword
The key is the valid command-word that proceeds commands to the machine. For example, mine is Cmd. So I text:
Cmd ls
to have the pi text the results of the current directory back.
Your valid number is the phone number you want your google voice to receive commands from (Not your Google voice number!). You must put the country code but not the + sign. Ex:
15553332222

After that everything should work.
Note, I worked out a few major bugs with the install script and it is reposted now. So make sure to get the newest version.

Consider donating to further my tinkering


Places you can find me





Read More..

Voicecommand image file and controlling electronics with your voice

With the introduction of the Raspberry Pi B+, a lot of people are finding image files arent working unless updated first. Because of this, I went ahead and made a fresh image file for voicecommand on Raspbian that is A/B/B+ compatible.

You can download it at:
https://mega.co.nz/#!MM8W1JxR!4PlZ_1-dumasDUCYRI4LuiBwEJgtqhfoin0R8ls90NQ

Ive also taken the liberty of putting wiringPi and pilight on it. This means its easier than ever to control electronics with your voice (Ill post more on that later).
You can read more about it at the hackaday projects page here.

And here is a quick video demo:

Consider donating to further my tinkering since I do all this and help people out for free.



Places you can find me
Read More..