How To: Add Voice Feedback to Your Home Automation With Link It ONE!

by Ayush Sharma in Circuits > Assistive Tech

1326 Views, 19 Favorites, 0 Comments

How To: Add Voice Feedback to Your Home Automation With Link It ONE!

linkit dev board.jpg
IMG_4580.JPG

Hello Everybody,

Today i will show you , how to add Voice feedback to your Home Automation.

This will always be a good additive to your Home Automation Project with Link it ONE because your Linkit ONE would leave a feedback like a " I have Turned on Lights for You" and "Lights are Already ON" or

" Hello, How can i assist you today?".

You might be tinking that , it would require too much code but the real thing is that you will need only 4 lines of code to make a linkit ONE speak a audio file.

This Project has a Backbone on TTS , Text-To-Speech . I used Natural Readers Software to Convert my written text to an mp3 Audio File. I just write my Lines like " Hello Master" and convert this to an mp3 file which would be copied to linkit ONE Internal Memory.

In this Instructable i will show you , how to merge Audio Library with Wifi Library of Linkit ONE and use it with your own setup.

Thanks to Mediatek, that they added audio ic and codec for or ease!

About the Code - Starting

1.PNG

The Code uses two Mediatek Libraries which would be merged to form a good Voice Feedback System.

The Two Libraries will be LAudio and LGSM / LWiFi / LBT ( you add all these 3 also)

for Now , we will be merging 2 Libraries - LAudio and LGSM

Remember to use .wav or .mp3 only.

So let's go in the code -

Add this in the starting of the Code, (for GSM SMS Control Only!)

#include <LTask.h>
#include <LGSM.h>
#include <LAudio.h>

If anybody is making the project with Lwifi or Lbt Library then Add this Only + your wifi or bt library

#include <LAudio.h>

About the Code - Setup

2.PNG

Now Add this in setup, if you want the link it one to play any audio file only once when powered.

otherwise ignore this Code.

LAudio.begin();
{ LAudio.playFile( storageFlash,(char*)"yourfilenamehere.wav"); LAudio.setVolume(5); Serial.println("playing - yourfilename.mp3"); }

About the Code - on OFF Voices Addon

3.PNG

when you want to make linkit one say , when the lamp is turned on or when you receive a Message then use this code. Remember always to use "if " in the code, otherwise it will continuously play the audio files.

Improvements Appreciated.

if((dtaget[0] == 'O' && dtaget[1] == 'N') || (dtaget[0] == 'o' && dtaget[1] == 'n'))
{ digitalWrite(pinLed, HIGH); LAudio.playFile( storageFlash,(char*)"turnedon.mp3"); //Playing LAudio.setVolume(5); Serial.println("playing - turnedon.mp3"); }

else if((dtaget[0] == 'O' && dtaget[1] == 'F' && dtaget[2] == 'F') || (dtaget[0] == 'o' && dtaget[1] == 'f' && dtaget[2] == 'f')) { digitalWrite(pinLed, LOW); // lamp off LAudio.playFile( storageFlash,(char*)"turnedoff.mp3"); //Playing LAudio.setVolume(5); Serial.println("playing - turnedoff.mp3"); }

Download Your Audio Files

4.PNG

Download your audio files from any Free or Paid TTS Service.

I use www.NaturalReaders.com

Anyother Free Service Will work too.

Most of the Voices would be of 50kb(max) and mediatek linkit ONE has a 10MB Internal Memory.

Therefore many voices could be stored in Linkit ONE without any SD Card.

Uploading Audio Files to Your Linkit ONE

5.PNG

Upload all the audio files to your linkit one.

Turn the switch to MS to enable Internal Memory.

Upload the Code

6.PNG

Now Upload the Code to Link it ONE for Turning Lamp On and OFF + Voice Feedback.

if you want to control volume then edit this line "LAudio.setVolume(5);" Volume ranges from 1-6 so edit that 5.

Now, Upload the Code to Turn the Lamp on and off with sms + voice Feedback.
Code: /* * SMS Control Light + Voice Feedback. * * You should insert a SIM card and the GPRS antenna * Send a "on" or "ON" to lighten the led * Send a "off" or "OFF" to make the led off * This Code also has Audio Feedback. * LED connect to D3

Edited by Ayush Sharma

On: 10/29/15 */ #include #include /* * SMS Control Light * * You should insert a SIM car and the GPRS antenna * Send a "on" or "ON" to lighten the led * Send a "off" or "OFF" to make the led off * This Code also Has Voice Feedback. * LED connect to D3 */ #include #include #include char buff[120]; const int pinLed = 3; // led connect to D3 void setup() { Serial.begin(9600); LAudio.begin(); { LAudio.playFile( storageFlash,(char*)"firstassist.mp3"); LAudio.setVolume(5); Serial.println("playing - firstassist.mp3"); } while(!LSMS.ready()) { delay(1000); } Serial.println("GSM OK!!"); } void loop() { char p_num[20]; int len = 0; char dtaget[500]; if(LSMS.available()) // Check if there is new SMS { LSMS.remoteNumber(p_num, 20); // display Number part Serial.println("There is new message."); Serial.print("Number:"); Serial.println(p_num); Serial.print("Content:"); // display Content part while(true) { int v = LSMS.read(); if(v < 0) break; dtaget[len++] = (char)v; Serial.print((char)v); } Serial.println(); LSMS.flush(); // delete message if((dtaget[0] == 'O' && dtaget[1] == 'N') || (dtaget[0] == 'o' && dtaget[1] == 'n')) { digitalWrite(pinLed, HIGH); LAudio.playFile( storageFlash,(char*)"turnedon.mp3"); //Playing LAudio.setVolume(5); Serial.println("playing - turnedon.mp3"); } else if((dtaget[0] == 'O' && dtaget[1] == 'F' && dtaget[2] == 'F') || (dtaget[0] == 'o' && dtaget[1] == 'f' && dtaget[2] == 'f')) { digitalWrite(pinLed, LOW); // lamp off LAudio.playFile( storageFlash,(char*)"turnedoff.mp3"); //Playing LAudio.setVolume(5); Serial.println("playing - turnedoff.mp3"); } } }

#include char buff[120]; const int pinLed = 3; // led connect to D3 void setup() { Serial.begin(9600); LAudio.begin(); { LAudio.playFile( storageFlash,(char*)"LS8Mo.wav"); LAudio.setVolume(5); Serial.println("playing - firstassist.mp3"); } while(!LSMS.ready()) { delay(1000); } Serial.println("GSM OK!!"); } void loop() { char p_num[20]; int len = 0; char dtaget[500]; if(LSMS.available()) // Check if there is new SMS { LSMS.remoteNumber(p_num, 20); // display Number part Serial.println("There is new message."); Serial.print("Number:"); Serial.println(p_num); Serial.print("Content:"); // display Content part while(true) { int v = LSMS.read(); if(v < 0) break; dtaget[len++] = (char)v; Serial.print((char)v); } Serial.println(); LSMS.flush(); // delete message if((dtaget[0] == 'O' && dtaget[1] == 'N') || (dtaget[0] == 'o' && dtaget[1] == 'n')) { digitalWrite(pinLed, HIGH); LAudio.playFile( storageFlash,(char*)"turnedon.mp3"); //Playing LAudio.setVolume(5); Serial.println("playing - turnedon.mp3"); } else if((dtaget[0] == 'O' && dtaget[1] == 'F' && dtaget[2] == 'F') || (dtaget[0] == 'o' && dtaget[1] == 'f' && dtaget[2] == 'f')) { digitalWrite(pinLed, LOW); // lamp off LAudio.playFile( storageFlash,(char*)"turnedoff.mp3"); //Playing LAudio.setVolume(5); Serial.println("playing - turnedoff.mp3"); } } }

Finishing

IMG_4579.JPG

1. Connect your Computer Speakers of diy speakers with the audio jack of Link it ONE.

2. Connect Relay / Led on pin 3.

3. Insert Sim Card

4. Attach GPRS Antenna.

Now just SMS "ON" to your number which is put in the linkit ONE to Turn ON the Lamp

and "OFF" to turn it OFF.

For now , I wanted to share this method but next time i will add this to my home automation projects.