Hello everyone,
Continued post of Raspberry Pi and Karaoke Machine (Implementation of Karaoke Part 1 of 2)
Earlier I installed the hosting server on the raspberry pi, which generally serves as a database server of karaoke. This stores record of the .kar files.
Now the next step is to add the scripts which php pages which response to the request being made by the main scripts.
Now extract the karaoke_php.zip into the /var/www/karaoke/ folder the karaoke_php.zip file is attached in the post.
Create a database using phpmyadmin.
I have made a database named karaokedb
Next step is to edit the dbinf.php file.
In this file you need to enter your mysql user, password and database details.
<?php $dbhost="localhost"; $dbuser="root"; $dbpass="your_database_password"; $dbname="karaokedb"; ?>
Edit your host, username, password and database name according to your choice.
The next step is to execute createdb.php.
This can be done by opening the created.php in your browser you just need to point URL to the file.
Like I can done this by using http://my_rasp_pi_IP/karaoke/createdb.php
Now you are done with creating a database server.
Now you can add .kar files to the webserver.
You just need open the http://rasp_pi_IP/karaoke/addkar.php
Browse .kar file. And enter the song name which can be pronounced.
This is all what I do with the database server.
Now for next step you need to install few applications. Like player and other application which will be needed to use voice command based karaoke.
For that enter the following in terminal.
sudo apt-get install pykaraoke flac
This will install a python based midi and karaoke file player.
After all these steps you need to create a karaoke.sh in /home/pi/
For that
sudo nano ~/karaoke.sh
Enter the following in the file
echo "Say the song name" arecord -f cd -d 3 -q -t wav -r 16000 | flac - -f --best --sample-rate 16000 -s -o sound.flac; echo "Converting Speech to Text..." wget -q -U "Mozilla/5.0" --post-file sound.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium" | cut -d\" -f12 > googleresponse.txt echo "You Said:" value=`cat googleresponse.txt` echo "$value" wget -q -O - "http://127.0.0.1/karaoke/songselect.php?songname=$value" > dbresponse.txt kar=`cat dbresponse.txt` echo "kar file name: $kar" pykar /var/www/karaoke/uploads/$kar
Make sure that karaoke.zip folder is extracted into /var/www/ mains folder otherwise you need to edit last line to point that where the directory is located. Edit to use with the other hosting server.
Moreover you can upload to php scripts to other hosting server. So those load on the raspberry pi decreases. But for that you need to replace
wget -q -O - "http://127.0.0.1/karaoke/songselect.php?songname=$value" > dbresponse.txt kar=`cat dbresponse.txt` echo "kar file name: $kar" pykar /var/www/karaoke/uploads/$kar
with
wget -q -O - "http://your_domain/path_to_the_php_scripts_where_it_is_uploaded/karaoke/songselect.php?songname=$value" > dbresponse.txt kar=`cat dbresponse.txt` echo "kar file name: $kar" wget -q -O - “http://your_domain/directory_/where_karaoke/_are_located/uploads/$kar” pykar $kar
Now make the file executable, for that
sudo chmod +x karaoke.sh
This is all about the installation.
For those who have wolfson pi.
They all need to edit .asoundrc file. Otherwise I was facing issues with that while recording sound at 8000Hz and 16000Hz sample rate.
Save the following scripts as /home/pi/.asoundrc (Backup your old .asoundrc file before this)
####################################################################### # # Use libsamplerate instead of internal resampler. # You might have to: sudo apt-get install libasound2-plugins # Or just comment out the next line if the internal one is good enough for your needs. defaults.pcm.rate_converter "samplerate" ###################################################################### # # Wolfson Audio Card for Raspberry Pi # pcm.wolfson_pi_soundcard { type hw card sndrpiwsp device 0 } # Create a Master volume control pcm.softvol { type softvol slave { pcm "pduplex" } control { name "Master" card 0 } } pcm.!default { type asym playback.pcm "plug:softvol" capture.pcm "pduplex" } ##################################################################### # # Mixing and resampling goodness :-) # # Several clients can record and play back simultaneously. # The dmix and dsnoop plugins operate at 48kHz by default, i.e. the sound card will be kept at 48kHz at all times. # All playback streams are converted to 2 channels/48kHz/16bit. # All recording streams are converted from the card's 2 channels/48kHz/16bit # to the requested number of channels, sample rate and bit depth. # We define one pcm device called "playmixer" for playback. pcm.playmixer { ipc_key 140324 # Any number will do, as long as it's unique in the system. ipc_key_add_uid true type dmix slave.pcm "wolfson_pi_soundcard" } # Define another one called "recmixer" for capture. # The sound card will run at 48kHz and input is resampled to the requested rate. pcm.recmixer { ipc_key 140325 ipc_key_add_uid true type dsnoop slave.pcm "wolfson_pi_soundcard" } # Define a duplex device, with both in- and outputs. pcm.duplex { type asym playback.pcm "playmixer" capture.pcm "recmixer" } # Add a "plug" plugin for the above "duplex" device. # This is where all the converting takes place. # Sample rate, number of channels, bit depth. # By the way, who thought that "plug" was a good name for a plugin? # # Use this device for all your playback and recording resampling needs. pcm.pduplex { type plug slave.pcm "duplex" } # A ctl device to keep xmms happy ctl.pduplex { type hw card 0 } # A DSP to keep the alsa-oss layer happy: pcm.dsp0 { type plug slave.pcm "duplex" } ctl.mixer0 { type hw card 0 }
You can change the input hardware in the karaoke scripts to select input device. I am using default wolfson_pi for input and output.
Now execute the script
./karaoke.sh
Follow the onscreen instruction and you are done with creating a voice command based karaoke selector and player.
The steps in the karaoke.sh scripts involve the 2 second voice recording.
Then it use Google_API to convert voice command into text.
Then it compares the text to the available song name in the database.
Get the name of the karaoke file.
Play the file using karaoke player.
In other terminal window you can use alsaloop to loop your voice to the speakers so that it can be fully used as karaoke player.
At last take a quick look to the demo here.
First video uses wolfsonpi.
In second video I used Pi-Face CAD and USB sound card. In alsaloop there are too much overflow and underflow. You may overclock to reduce this. or decrease the CPU usage. Otherwise it works well.
And sorry for my bad video quality
Regards,
Top Comments