Earlier, we tried getting a sort of Karaoke system working on the Pi. The idea was to use the built-in alsa sound system that comes with Raspbian to capture the microphone and pass it through to the speakers while simultaneously running some sort of Karaoke program (our plan was to use something on XBMC). Sadly, the alsa sound system was a bit broken such that if you tried to play two sounds at the same time, when the first sound finished the entire sound system would crash and you would have to reboot the Pi. This spelled the end of our Karaoke plans.
HOWEVER! There has since been an update of the sound system. It's not perfect and it still crashes, but it doesn't crash THE WHOLE SYSTEM, It seems to just corrupt the process that you were running. Further investigation lead to the discovery of a lightweight youtube player (whitey, using OMXPLAYER) and a way to run alsaloop to capture the microphone AT THE SAME TIME! Effectively, a proper Karaoke system!
There are some problems. We run our Pi with a USB microphone and Wireless dongle, meaning there's nothing left for a keyboard or a mouse unless you use a powered hub, and then that's getting messy. Therefore we recommend that you SSH in to your pi from another computer (in the example video we use a Nexus 7).
Secondly, we need to run two seperate programs simultaneously, so ideally you'll need to SSH in twice.
Thirdly, each program needs to be reset (Ctrl-C then restart) after each "performance" otherwise the audio gets corrupted (this is the sound system crashing locally I suspect).
Finally, you must start the microphone recording AFTER the video starts playing.
If all this sounds a bit fiddly, it isn't in practice, plus we'll work on wrapping this all up into a nicer package (or someone else can).
Have a look at the video (apologies for the poor quality) and then we'll provide installation and running instructions.
To set up a similar system you will need:
- A Raspberry Pi running Raspbian
- A USB Microphone (We use a Guitar Hero one that came with the game)
- An internet connection
- Another computer with terminal (SSH) software
Ideally, you should also set up your pi with a fixed IP address.
We don't need too much really.
First, make sure your Pi is up-to-date.
sudo apt-get update
sudo apt-get upgrade
Also, we recommend setting your overclocking on medium or turbo and you will need to enable SSH. This is all done in:
We'll be using whitey as our youtube interface, which in turn uses omxplayer to play video.
sudo apt-get install youtube-dl
sudo youtube-dl --update
sudo youtube-dl -U
This installs the youtube side of things. Now for the interface
sudo apt-get install python-setuptools
sudo easy_install whitey (Note the underscore, not dash. Thanks Charlie!)
sudo apt-get install omxplayer
Now the Whitey side of things should be set up. Test it by running pi-yt.
Another thing we want to do is blank the screen and remove the flashing cursor before playing any videos, otherwise the video plays over any text you already have on screen (such as the login). Also, we'll be starting and stopping pi-yt after every song, so we'll set up a simple script file to do all this for us. Make sure you are in the /home/pi directory.
sudo pico k.sh
Now we need to add the following lines. You don't have to call the file k.sh btw, it's just what we used.
sudo dd if=/dev/zero of=/dev/fb0
sudo setterm -cursor off > /dev/tty1
Those first two lines clear the screen and remove the cursor. Now save the file (Ctrl-X) and lets make it runnable.
sudo chmod 755 k.sh
Test this by running the file:
Now we will set up another script that will execute the microphone capture command. It's quite a long-winded command hence the use of a script, as we also need to run this after every song. Create a file like you did before; we called our one r.sh. Add the following line to it:
alsaloop -C hw:1,0 -P hw:0,0 -c 1 -t 12000
Note we are assuming you haven't got any other hardware plugged in. Your microphone should be hw:1,0 and your sound output should be hw:0,0. This should be the case for most of us! Save this file and again, make it executable with sudo chmod 755 [filename]
That should be everything ready to go. To replicate our set up, use a wifi dongle, plug in your USB mic and plug it in to your TV. Initially you will see the standard Raspian boot up procedure until you get to the login: prompt. We won't be logging in this way however, and after the first song starts, the screen will remain cleared and black.
With your Raspberry Pi active, you should now be able to login to it using another computer. In the picture above we are using Putty for windows and in the video we used Terminal IDE for Android. There are a raft of terminal programs you can choose from. However you will need to know the I.P. address of your Raspberry Pi which was why we suggested setting up a static I.P. address for it. If you can't do this, there are ways to find the I.P. address. You could use Nmap or perhaps you could get the Pi to print it's I.P. address after booting. If you find you can't login, perhaps you have forgotten to enable SSH (use raspi-config)?
As you can see from above, we have opened TWO terminal windows. We do this because the Karaoke process involves two seperate programs that must be run and we'll need ready access to the command line so that there is no noticable delay between the video starting and the recording starting.
In the first terminal window you can launch Whitey. Use the script we created earlier to do this as it will clear the screen and remove the cursor on the screen attached to the Raspberry Pi.
This is where it's quite a nice experience for the audience, as they can't see all your faffing around on the terminal screens. All they see is a black screen and then their video. No text or prompts or the like.
Whitey is pretty straight-forward to use. Press 's' to enter a search query. As you can see here, adding "karaoke" on the end is quite effective. You can page up/down using the square brackets "[ and ]" and you launch the video of your choice by pressing the number associated with it. In this example, "I want to break free" would be number 4. We have found that for whatever reason, some videos just don't play (we haven't purchased the MPEG licences however, so it could be that), but the majority do.
Once you have started the video, you should then switch to your other terminal. Here we are going to start the microphone pass-through command using the script we also created earlier:
If you find that you need to adjust either the volume of the music or the volume of the microphone, you can launch alsamixer (although you'll need another terminal to do this. Don't worry though, you can have three easily enough!).
You can now sit back and "relax" as the "performance" takes place.
Once finished, we will then need to "reset" both of our programs. Press CTRL-C to terminate the microphone capture scripts, then switch to the other terminal and press CTRL-C to terminate Whitey. We need to do this because if you were to start another song, you would find that the sound is corrupted.
You can then restart Whitey, choose a song and restart the microphone capture once the video starts. Rather than retype in the commands you can just press UP ARROW to access the previously typed-in command.
I think you'll agree that it's not that fiddly to do, and the results are excellent!