Raspberry Pi para acender um LED usando controle de voz – (Parte 2/12)

Raspberry Pi to light an LED using voice control – (Part 2/12)

Now, voice control is not just limited to high-end devices like smartphones or iPhones. The Raspberry Pi, which is open-source and fully customizable hardware, offers the same. Plus, it's cheap! You can customize it to play music, open Gmail, or maybe tell some jokes.

Here is a simple but interesting example of how to customize your Raspberry Pi to light up an LED using voice control. In this tutorial we will learn how to install Voice Control, and configure it to turn an LED on and off.

Prerequisites and equipment:

You will need the following:

  1. A Raspberry Pi Model B or higher.

  2. A USB WiFi adapter (Edimax – 802.11b/g/n wireless nano USB adapter is used here).

  3. A USB webcam with USB microphone/microphone (Logitech USB Webcam is used here).

  4. An SD card updated with the Raspbian operating system (here's a guide if you need it)

  5. Access to Raspberry via keyboard and monitor or remotely.

Here you cannot use microphones, as the Raspberry Pi does not include a sound card. Therefore, use a USB microphone or a USB webcam with a built-in microphone.

Working principle:

The software used in this tutorial uses Google Voice and Speech APIs. The spelled user's voice signals are captured by the USB webcam's microphone. These sound signals are then converted to text using the Google Voice API. The text is then compared with the other commands previously defined in the command configuration file. If there is a match, the corresponding commands are executed.

Startups:

First, we have to check if your microphone or webcam is detected by the Raspberry Pi and if the microphone volume is turned up. The first step is to check if your webcam or microphone is listed using the “ lsusb ” command.

Verificando webcam ou microfone detectado pelo Raspberry Pi

Figure 1: Checking webcam or microphone detected by Raspberry Pi

The next step is to set the microphone recording volume to high. To do this, type the command “ alsamixer ” in the terminal. A beautiful GUI screen appears, press the up or down arrow keys to set the volume. Press F6 (all) and select the webcam or microphone from the list. Again, use the up arrow key to set the recording volume to high.

Ajustando o volume do microfone para alto

Fig. 2: Adjusting the microphone volume to high

Connect a black female to male jumper to physical pin 6, a ground pin, and connect a red jumper to physical pin 16 of your Pi.

Conexões de jumper feminino e masculino com Pi

Fig. 3: Female and male jumper connections with Pi

The Wiring Pi project is used here to switch the GPIO pins between high and low. Run the following commands to download and install Wiring Pi.

sudo apt-get install git-core

git clone git://git.drogon.net/wiringPi

CDPi wiring

./ramp up

Baixando Fiação Pi para Raspberry Pi

Figure 4: Downloading Wiring from Pi to Raspberry Pi

Instalando a fiação Pi no Raspberry Pi

Fig. 5: Installing Pi Wiring on Raspberry Pi

Create the following script as a file called 'led':

#!/bin/bash

if ($# > 1)

then

/usr/local/bin/gpio mode 4 output

if ((“$1” = “on”))

then

/usr/local/bin/gpio writes 4 in

fi

if ((“$1” = “off”))

then

/usr/local/bin/gpio cancel 4

fi

fi

Set the script to be executable with the following command:

chmod u+x led

Now this command should light up the LED connected to the pin. (Pin number description can be found on the Wiring Pi page.

./led on

To turn off this command can be used

./led

Installing speech recognition software for Raspberry Pi:

Voice Command is installed as part of the package collection. We only need the dependencies and voice command components for this tutorial. When the setup script runs, it will ask you to install several packages, you can only say yes to the dependencies and the voice command.

Run the commands below:

git clone git://github.com/StevenHickson/PiAUISuite.git

cd PiAUISuite/Install/

./InstallAUISuite.sh

Instalando software de reconhecimento de voz para Raspberry Pi

Fig. 6: Installing speech recognition software for Raspberry Pi

After installing Voice Command, it will ask you to configure it. Choose yes to allow the installation script to be configured automatically. When configuration is complete, you will be prompted to edit the configuration file. Press Enter to edit the file and see the next configuration section. Add the following line to the configuration file, save and exit.

light==/home/pi/scripts/led…

The line above means that when you say light on or off, Voice Command will run the /home/pi/led script with the on or off argument. This is similar to the result when you ran the script manually.

Use the command below to launch Voice Command. The -c means run continuously, -k pi sets the name prompt you will say to get the Raspberry Pi's attention. The -v causes the program to check the prompt before entering speech recognition mode. The -i causes voice command to only process explicit commands listed in the configuration file. Finally, the -b0 argument forces the voice command not to use filler text before its response.

voice command -c -k pi -v -b0 -i

Run the above command

Clearly say PI and wait for the response “Yes sir”

Say clearly lit. The LED should light up

Say it clearly: delete it. The LED should turn off

Congratulations! You have successfully voice controlled your lamp with your Raspberry Pi.

Circuit diagrams

Circuit Diagram-Voice Control

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.