element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Rocking Raspberry Pi
  • Challenges & Projects
  • Design Challenges
  • Rocking Raspberry Pi
  • More
  • Cancel
Rocking Raspberry Pi
Blog Raspberry Pi and Karaoke Machine (Implementation of Karaoke Part 2 of 2)
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: babusingh9211
  • Date Created: 1 May 2014 4:40 PM Date Created
  • Views 1525 views
  • Likes 2 likes
  • Comments 4 comments
  • RoadTest
  • rpiintermediate
  • rockingraspberrypi
  • karaoke
  • voice-command
  • raspberrypi
  • challenge
  • rocking_pi
Related
Recommended

Raspberry Pi and Karaoke Machine (Implementation of Karaoke Part 2 of 2)

babusingh9211
babusingh9211
1 May 2014

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.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

First video uses wolfsonpi.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

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 image

 

 

Regards,

Sumit Rai

Attachments:
karaoke.zip
  • Sign in to reply

Top Comments

  • mmohit00007
    mmohit00007 over 11 years ago +1
    babusingh9211 nice project,it made my all concepts clear about karaoke u are relay dedicated person u completed this project and also made my mind to participate in the next e14 road test enrollment. and…
  • babusingh9211
    babusingh9211 over 11 years ago in reply to mmohit00007 +1
    Next time we both will be selected. BTW thank!!
Parents
  • babusingh9211
    babusingh9211 over 11 years ago

    There is update in the google-speech API,

    So to use the new API you have change the

     

    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

     

    to

     

    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/v2/recognize?lang=en--us&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" | cut -d\" -f8 > googleresponse.txt

     

    Otherwise you may not be able to use the Google Speech API which is used for transcribing the voice.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • babusingh9211
    babusingh9211 over 11 years ago

    There is update in the google-speech API,

    So to use the new API you have change the

     

    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

     

    to

     

    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/v2/recognize?lang=en--us&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" | cut -d\" -f8 > googleresponse.txt

     

    Otherwise you may not be able to use the Google Speech API which is used for transcribing the voice.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube