Voice Activated Assistant - MAX

Published

Introduction: Voice Activated Assistant - MAX

About: A character who is following behind the Technology.

Hey in this Instructable I am going to talk about a how to make a chat-bot MAX(named myself !!! )

With some implementation you can make this chatbot voice controlled or with the usage of various software you can make it as a voice assistant. I here is not going to talk about it since every one can genuinely make this implementation easily.

So everyone please support me.......

My first Instructable !!!!!!!

Feeling Nervous on what is going to Happen ................

Step 1: Knowing About the Contest

Hi Engineers and Designers........

Me myself a Computer Science student loves to play game and always inspired on computers.Talking briefly I love to know how all these stuff out present works.So as a reason I kept looking ,googling(infact I used to use Yahoo too !!!!!!) for searching and learning the things.

So one day I came before the screen of Instructables. It really amused me through various projects with a variety of ideas on various aspects.Then from that day I keep on track with it.The contest page really amused me both concerned with the prizes and the projects that have been submitted by various people around the world.

VOICE ACTIVATED CHALLENGE is my first platform in regards on writing an Instructable.

Prizes amused me a lot(Yeah !!! Too Much........).

Also I wish to share my knowledge in the field of Computers and it's technology to others about how various things actually works.

In this Instructable I show you how to Build your own voice activated assistant .

Since it is my first Instructable there may be so many mistakes (even though I think all of these have been fixed) , so forgive for that.

SO.....

Let us start the journey...................

Step 2: Where Did I Know About the Things ?

This will be a major question I think most of your minds may gone through.........

I have a much passion for Artificial Intelligence[AI] from my schooling, from that I have searched a lot looking onto resources to study up and to develop a model on my own.

Initially it was very difficult(true condition) as I understood it was a very vast subject that is not at all easy to handle.

The books that looked up includes :

  1. Artificial Intelligence A Modern Approach
  2. Artificial.Intelligence.in.the.21st.Century.2nd.Edition
  3. Deep Learning

These are very good books(yes surely) but it is not at all easy to understand the things that has been written on that.Then I kept it at a side and go on to search for the resources that gives up a brief idea about what it really represent and ways to get on to it.

Then I found an interest in that.Through out the vacation after schooling I started to learn about it more deeply.

At that time I also learned various programming languages (C++,C,Python,Java ....),which too very interesting.

On reading more on the topic I understood one Important Thing....................

The programming languages IS THE BASIC FOR EVERY MACHINE LEARNING PROCESS.

Machine Learning is the process of application of AI.

With a great understanding on programming languages and various things that can be done depending by the programmer to make a computer to do anything for us.

So I decided to create a good base on the languages that made me understand the concepts provided on the book that I have already mentioned.

You too can do that........

There are so many websites present in the web to teach programming languages freely .

So you can surf the internet to understand more about it if you wish.........

Step 3: Let Us Start

Me before starting about writing the Instructable I thought of to write something that kind be understood by :

  1. People who have an experience with coding
  2. People without any coding background

So I think I have done the thing without any mistakes(hopefully).

So I have decided to build a chat bot that can talk to the user and can respond according to our talk.

The program(set of instructions) cannot think on its own. It has a database(a place where data has been stored) of facts and rules, which are searched at the time of talking to give the best possible response that makes in connection with the user.

It works by matching process depending on things entered up, only in rare cases an entire sentence is matched over to a complete sentence.

Step 4: How Does It Actually Work ?

Step 1 :

MAX finds out if the user has given any null input. If user when provided input in such a way , it takes the fact from the static database to respond.

Oh Sorry ........

I forgot to Say ,

Static Database : The place where in-built responses is stored up. Responses like :

1. When MAX does not understand about what the user is talking about.

2. When the user repeats himself.

3. For greeting statements.

4. When the user does not type anything and just keeps on pressing Enter.

Keyword : words having special meaning.

Step 2 :

There are some in built responses that MAX can recognize readily and easily. It finds the presence of any such sentence after identifying the users input and remembers the associated keyword.

Step 3 :

If no in-built sentence is found even after fragmentation of the given sentence, then MAX searches for the specific keyword to define the context. If no context is being found then it's next aim to make the user to talk about the topic more deliberately in a specific manner.

Step 4 :

From the Static Database that we have already talked about , it will pick-up the response that depends on what the user have talked about.

Step 5 :

I there is any need of changing the words it will do it itself (such as Conversion of MY to YOUR etc....)

Step 5: Let Us Code .............

I am using Turbo C IDE 3.0 as this is the IDE [Integrated Developmental Environment]

Before the coding , let us see the structure of a sample Data File.

MAX recognizes certain keywords.

If these keywords are found in the input provide by the user , then a corresponding response is chosen from the data file and is chosen up and displayed on the screen.

A keyword is separated in the data file from the responses by @KWD@ token.

Token is a smallest part of every programming aspects.

This token denotes the next line is a keyword and not a response.

------------------------------------------------------------------------------------------------------------------------------------------------------

@KWD@
HELLO

HI, HOW ARE YOU

HELLO DEAR !

I AM FINE

HOW WAS YOUR JOB?

HOW OLD ARE YOU?

@KWD@

I WILL

YOU WILL DO SO. I BELIEVE IT TOO...

WILL YOU BE ABLE TO DO SO ?

WILL YOU TRUST ME ?

@KWD@

YES

ARE YOU SURE ?

HOW CAN YOU BE SO SURE ?

@KWD@

NO

YOU SEEM TO BE VERY PESSIMISTIC.

NEVER SAY NO...

NEVER SAY NEVER

NEVER BE RUDE

NEVER BE ARROGANT !!!!

NEVER SAY I CANNOT DO THIS

NEVER BE OPTIMISTIC

@KWD@

COMPUTER

I KNOW HOW TO WORK ON COMPUTER.

YOU ARE CURRENTLY USING A COMPUTER. RIGHT ?

<< Add whatever you want in above format >>

------------------------------------------------------------------------------------------------------------------------------------------------------

For example ,
'Hello', from the above dictionary, MAX will give one of the following responses:

HI, HOW ARE YOU
HELLO DEAR !

I AM FINE

HOW WAS YOUR JOB?

HOW OLD ARE YOU?

Step 6: Classes

Once this thing is clear, let us now define the Data Structures that we will be using.

We create two classes :

progstr - This is used to store the user's input related information.

resp - This is used to store the information about the various responses

class progstr
{

public:

char userip[MAX_USER_INPUT];

char keyword[30];

int keyfound;

int keyno;

int nullip;

// constructor

progstr() { keyno=-1; nullip=0; keyfound=0;

}

}ip;

class resp

{

int tot_resp;

int last_resp;

char replys[MAX_RESP_NO][MAX_RESP_LEN];

char word[MAX_KWD_LEN];

public:

// constructor

resp()

{

tot_resp=0;

last_resp=-1;

}

int getcount()

{

return last_resp;

}

void addword(char str[MAX_KWD_LEN])

{

strcpy(word,str);

}

char * getword()

{

return word;

}

void addresp(char str[MAX_RESP_LEN])

{

strcpy(replys[++last_resp],str);

}

// defined later

void display_resp(int num);

void quit_display_resp(int num);

};

Looking onto first class ,

The character array userip is used to store the sentence provided by the user.

Another array keyword is used to store the keyword, if any, found in that input. If a keyword is found, we make int keyfound to 1 else, it remains 0, as it is initialized to 0 in the Constructor.

keyno stores the correspondingkey number of the corresponding keyword.

nullip indicates whether the user has given any Null input ie, he is just pressing enter without doing anything else.

Now let us come to the second class, resp.

The first data member, tot_resp indicates the number of total responses for a given keyword.

The replies are actually stored in replys[MAX_RESP_NO][MAX_RESP_LEN] and the corresponding keyword is stored in the array word.

Constructor:
This is used to initialize the total number of responses to 0. Why last_resp is initialized to -1 will be clear when you look at the function add_resp.

int getcount():

This function is used to get a count of how many responses are there for a given keyword.

void addword(char str[MAX_KWD_LEN]):

This is used to add a keyword.

char * getword():

Used to return the keyword for a particular object of class resp.

void addresp(...):

This is used to add a response corresponding to a given keyword.

void display_resp(int):

This is used to display the response to the user corresponding to a given index number for the responses. (actually it does more than that !).

void quit_display_resp(int):

Difference between this function and above function is that it is used in the end when the user is quitting. So, it does not return the prompt to the user.

Step 7: Functions

void initialize_global()

{

strcpy(wordin[0],"ARE");

strcpy(wordout[0],"AM");

strcpy(wordin[1],"AM");

strcpy(wordout[1],"ARE");

strcpy(wordin[2],"WERE");

strcpy(wordout[2],"WAS");

strcpy(wordin[3],"WAS");

strcpy(wordout[3],"WERE");

strcpy(wordin[4],"YOU");

strcpy(wordout[4],"ME");

strcpy(wordin[5]," I ");

strcpy(wordout[5],"YOU");

strcpy(wordin[6],"YOUR");

strcpy(wordout[6],"MY");

strcpy(wordin[7],"MY");

strcpy(wordout[7],"YOUR");

strcpy(wordin[8],"I'VE");

strcpy(wordout[8],"YOU'VE");

strcpy(wordin[9],"YOU'VE");

strcpy(wordout[9],"I'VE");

strcpy(wordin[10],"I'M");

strcpy(wordout[10],"YOU'RE");

strcpy(wordin[11],"YOU'RE");

strcpy(wordout[11],"I'M");

strcpy(wordin[12],"ME");

strcpy(wordout[12],"YOU");

strcpy(wordin[13],"YOU");

strcpy(wordout[13],"ME");

}

Let us now write a function for displaying the
responses to the user. The first if statement in the for loop is used to make a deliberate typing error to make it appear more human like ;-). One character is randomly chosen for typing error. Special cases like New Line and Backspace are separately considered. (Think why ?). Now I introduce something new. A special character - *. Char * represents all of the text found AFTER the identified keyword, and before one of the following punctuation marks.

For example, consider the user input

AMIT > CAN I GO TO INDORE TOMORROW ?

MAX > WHAT IF YOU DO NOT GO TO INDORE TOMORROW ?

The underlined portion is not stored in the dictionary, rather it is taken from the user input. In the file MAX.Dat, we store this information as

CAN I

WHAT IF YOU DO NOT *

Star (*) asks the program to simply copy whatever is typed after the keyword (here CAN I ) in the user input, as it is. I hope that now the function of * as a special keyword is clear. So, let us consider a more complicated case.

AMIT > CAN I GO TO SHOPPING ?

MAX > WHAT IF YOU DO NOT GO TO SHOPPING ?

We must perform some transformation also. When we think of transformation, the sentence gets divided in the following 3 sections:

  • Text Before Transposition Word. (here, GO TO SHOPPING WITH )
  • The Transposed keyword. (here, YOUR, in place of MY)
  • Text After Transposition Keyword. (here, I ? )

Step 8: The Cases Can Be Tackled By.........

Step 9: Searching a Keyword in the User's Input

MAX_KEY indicates the number of keywords in the DAT file.

We here simply searches whether the keyword is present in User's Input.

Step 10: Conclusion

That's all ..........

You have done it !!!!!!!!!

I think everyone understood the things clearly......


If anyone have doubt regarding anything you can feel free to ask.

Finally I will bring new,new things up like this on the coming months.........

Bye ......


See you soon ............

Share

    Recommendations

    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Oil Contest

      Oil Contest

    2 Discussions

    That's a neat idea! Welcome to Instructables :)

    1 reply