Intro: Raspberry Pi Voice Controlled Home Automation
The objective of this instructable is to provide a step-by-step tutorial on how to setup a raspberry pi that can automate lights / leds with your voice commands.
Step 1: Step 1: Things / Equipment You Need
1.Raspberry Pi 3 with Noobs / Raspbian Os.
2.A USB webcam with microphone / USB microphone
3. windows / linux pc to access Raspberry pi
Step 2: Setting Up Mic to Detect Voice
First, we have to check whether your microphone or webcam is detected by the Raspberry Pi and the microphone volumes are high. First step is to check your webcam or microphone is listed using the command “lsusb“.
Fig. 1: Checking Webcam Or Microphone Detected By Raspberry Pi
Next step is to set the microphone recording volume high. To do this, enter the command “alsamixer” in the terminal. A neat graphical interface screen shows up, press the up or down arrow keys to set the volume. Press F6 (all), then select the webcam or microphone from the list. Once again use the up arrow key to set the recording volume to high.
Fig. 2: Setting Microphone Volume High
Step 3: Setting Up Gpio Pins
To access GPIO Pins you must need to install Wiring Pi on your Raspberry Pi
sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
for further instructions you can take a look at the screenshots
Step 4: Writing Script
Create the following script as a file named ‘led’:
if [ $# > 1 ]
/usr/local/bin/gpio mode 4 out
if [[ "$1" = "on" ]]
/usr/local/bin/gpio write 4 on
if [[ "$1" = "off" ]]
/usr/local/bin/gpio write 4 off
Set the script to be executable with the following command:
chmod u+x led
Now this command should ON the LED connected to the pin. ( Pin number description can be found in Wiring Pi page).
For turning OFF this command can be used
Step 5: Installing the Voice Recognition Software for Raspberry Pi:
Voice Command installs as a part of collection of packages. We, only need the dependencies and voice command components for this tutorial. When the setup script runs, it will ask your wish to install several packages you can only say yes to dependencies and voice command.
Execute the commands below:
git clone git://github.com/StevenHickson/PiAUISuite.git
After Voice Command installs, it will prompt you to setup. Choose yes to allow the install script to auto setup. When the setup is complete it will prompt you to edit the config file. Press Enter to edit the file and see the next section for configuration. Add the following line to the config file, save, and exit.
The above line means that, when you say light on or light off Voice Command will execute the script /home/pi/led with passing the argument on or off. This is similar to the result as when you ran the script manually.
Use the below command to launch Voice Command. The -c means to run continuously, -k pi sets the name prompt you will say to get the Raspberry Pi's attention. The -v causes the program to verify the prompt before going into a voice recognition mode. The -i causes voice command to only process explicit commands listed in the config file. Finally, the -b0 argument forces voice command to not use filler text before its response.
voicecommand -c -k pi -v -b0 -i
Execute the above command
Say clearly PI and wait for the response "Yes Sir"
Say clearly light on. The LED should turn on
Say clearly light off. The LED should turn off