RPI offline Voice recognition for Home Automation and IOT

This post was originally published on this site
Advertisement

Voice Recognition For Home Automation and IoT Having On Board RPi using AIY and it can recognize the voice in offline  Now no need to connect your phone to any third-party app for controlling your home. Simply use RPi as a Smart Home device.

We use various IoT and home automation devices that fulfil tasks such as switching the lights on or off by acting on our voice commands. However, most devices that are available either as DIY or as a finished product require phone connectivity and several apps in order to perform control using  voice commands. it become a complex process First connecting the phone with WiFi or any other network, and then installing and configuring an app for enabling voice command features increases the complexity of automation. But what if RPi removes all those steps and works as a smart assistant itself? Wouldn’t it be more convenient?

So let’s make a smart home automation system that does not require any phone connectivity. Instead, an RPi board does everything itself.

Along with home automation, our device can also record messages and audio, and save them using voice commands. So it also works as a voice recorder.

Bill of Material

Prerequisite

First of all, we have to set up the voice bonnet for our project. The AIY voice bonnet comes with the RPi Zero, jumper wires, switches and a preloaded AIY Raspbian OS image. But if you do not get the the AIY Raspbian OS SD card then you can take any blank SD card, download the latest Raspbian OS image of the AIY and then setup the RPi with that after doing the basic WiFi setup and other initial settings.

Go to the desktop of Raspbian OS, run the test voice script and then test the bonnet speaker and voice. Now it’s time to install the libraries in the Raspberry Pi. To do so, first open the Linux terminal and then run the following command to install the voice recognition library: 

sudo pip3 install speechrecognition

After setting up the library, we are ready to code. Open the Python IDE and then import the required library in the code. Use the speech recogniser to listen to the audio from the mic and convert it into text. After this, use the if condition to compare the commands. If the command matches with turning on the lights, then they will turn on.

Connection

Connect the relay 5V with the power pin on Voice bonnet and and GND with GND pin on Voice bonnet and then 27 pin to BCM 27 Pin of raspberry pi.

Testing 

Run the code created. Then press a button to say a command like turn on light. The recogniser will recognise the sound and will perform the task. Similarly, if you want to record your voice, then say “record me” and the recogniser will start recording. Press the button on the bonnet to stop and play the recorded audio.

Code

Advertisement