Hi everyone.
So now in this tutorial.
Let's actually go ahead and let's go inside this activity underline minute example here.
So here you can see this takes you right.
Just click on it and you can see that the idea is to the right you.
So now let's go to our main activity class here.
And inside this class let's declare an object or a variable of type the text you here sort of set in
here takes the view text view.
Now let's give a name to our valuable here.
So as I step in here fix the underlying value.
Right.
So this is the name of my variable semicolon.
So here I just declared my variable.
Now let's go inside is uncreate Smurfette here.
And after this line of code here that we actually call this set content view method I'm going to initialize
this variable so I can say Pique's the underlying value assignment operator.
So now we need to cast this object to a fixed view object find view by id r that ID that takes the value
semicolon.
That's it.
Right.
So here let's create a method inside the main activity class in order to allow the user to actually
use the speech recognition framework.
So let's scroll down here.
And after the end curly brace of this uncreate method.
And before the end in curly brace of this main activity class I can say private's OK.
Void and the name of the Smurfette here is going to be.
Listen listen to the users voice through the user's voice.
And here just put a bit of practice this year and then open and close this method by using the curly
braces.
So now I can say so inside the Smurfette.
Let's Create of idea of pipe intent so we can say intent and the name of this rally is going to be voice
intent or its intent.
Assignment operator new.
So I'm going to create a new object of intent right.
So new intent and instead the practice is just typing here.
Recognize their intent that action recognize speech.
So semicolon.
So you're going to create a new intent in order to allow the user to actually talk to his or her phone
or keep using this action recognized speech intent.
So after this line of code we are going to send some data to this to this action recognize speech intent.
So for example I can say voice intent voice intent.
That puts extra.
So this put extra needs to argument.
The first argument is going to be the key and the second argument is going to be the actual date up
that we want to see into this intent.
So the first one is key so it is going to be recognizer intent.
That extra that extra prompt underline prompt or case is the key comma.
So we're going to prompt the user to actually talk to the phone.
So that's why the key is called Extra prompt and the second argument is going to be a string value.
And here I can't say touch to me.
Talk to me.
Exclamation mark semicolon.
So again just typing here voice intent.
That puts extra and for the first argument we need to specify the key.
You can see that the first argument must be of type string.
Right because all these versions of this method.
Here the first argument which is the key is always of types 3.
So recognizer intent that language just type typing here language and here extra language model is this
one.
This is the key.
So here we want to specify that the user can actually talk in any language that he or she wants.
So that's why the key is called extra language model and the value is going to be recognizer intent.
That language model that language model free for that's it.
Semi-colon.
So let's create a new line here.
So here I am saying that the user can't speak in any language that he or she wants.
Language model free for this is the key extra language model.
So again after this line of code I can say and here finally we need to specify the maximum results that
we want to get from the user's speech.
So I can't say we seem to end that puts extra is recognize or intent that extra underline Max results
comma and the value is going to be.
For example I want to get 10 actually 10 results.
Semicolon.
That's it right.
And finally we need to call this if it's thought activity for result.
We are not going to start activity here.
We are going to start activity for results because if you want to actually get the data from the voiced
intent so just call this the start activity for result and then when it passed the intent if she's going
to be voice Internet karma and the request quote is is going to be the request code that you actually
created inside the main activity class this one speech request so let's pass this value here.
Speech request.
That's it.
So now this is our listen to the user's voice method right.
So where do we actually call this method from.
We are going to call this method from our uncreate method and after the inside if statement that we
are 100 percent sure that the user user's device actually supports speech recognition right.
So inside this statement We are saying that TOSed that may test your device does not support speech
recognition.
So here I can call this Meffert listen to the users voice.
Right now I can scroll down here.
So this is my faith.
And here inside is main activity class.
I am going to call this method of activity results suggest typing here an activity result so he had
this is the method that we need to override here in order to actually get the data from the voice.
Intent here inside the Smurfette.
First we need to create an if statement so if request code so I'm going to refer to the first argument
that we get from the Smurfit If request code is equal to the request code that we actually sent to this
intent.
OK this Meffert voice intent so if you sent this request code here for this instance right.
So I am actually saying if request code is equal to that speech request here and excuse me and result
code so if you have another argument here result quote is equal to result.
Ok then I can open and close this if statement.
And inside this statement I can be 100 percent sure that we get this data here that we get the data
from the actually voice intent here.
This statement is really important.
That's why we create our request called a speaking request here so that later when we want to get the
data from the voice intent we can actually to use this request not hear this speech request code in
order to be sure that the data is coming from the specific intent that we want to get the data from.
OK so in this if statement I can't say so.
Now let's create an array list of string values so I can't say I least and instead the angle brackets.
I can say strange and the name of my aerialist is going to be voice words voice for its assignment operator.
So here I can refer to this argument which is of that intent data that gets strange aerialist extra
get string Aurelia's extra.
And here as an argument I can't pass this value recognizer intent that extra resolves extra underline
results right semicolon.
So let me create a new line here so that they can see what's going on here.
So you are going to get the warts that the user has actually said and we are going to assign those words
into this at least here which is of type string and are a list of string values.
So after this line of code we can also get a decimal value from this ancient.
So what is that this decimal value is the symbol value is going to be the preciseness of divorce that
we are going to get from the user's voice.
Right.
Which is called comfort levels.
So let's create an array of floats values float and put a pair of brackets here and here the name of
this array is going to be confit levels assignment operator.
And here again if you are going to refer to the state is of the intent that get float and a extra dot
get float get float.
Add a extra that argument past this value recognizer intent that extra confidence scores semi-colon.
So here let me create on your line here so that you can see what's going on here.
And now it's time to output the results to the screen.
So now let's first like let's actually create a variable of that integer index assignment operator zero
semicolon.
Let's create a for in loop here instead of Frances just typing here.
Streambed.
And here I can't say a voice word or use that word use the word colon.
And here we are going to iterate over each value each string value that we have inside this latest voice
words voice words.
So this for English here is going to be executed for each string value that we have inside is released.
So insert this for loop here.
Let's create an if statement.
So if and here I'm going to refer to this at a comfort level.
If comfort levels is not equal to null an index is less than I'm going to now I'm going to the entity
is actually at a coffee levels that lenth.
So only in that case we are going to actually execute the codes inside the if statement.
First we are going to specify that if this array is not equal to all and if the index that we have here
is actually less than the length the number of elements that we have inside this country it was only
in this case only if these two conditions are true we can be actually 100 percent sure that we've got
some words some words from the user that we can actually output them to the screen.
So inside this if statement I can say TXI the underlying value it said text.
So here just refer to this.
Use the word plus two two coats and here just put a dash sheer space plus.
And we are going to also out with the value of the comfort level so the comfort level is going to be.
So let's refer to discomfit levels Aure and put a pair of brackets your index.
So that's it.
In this way you are going to get to use a word.
And we also going we are going to actually get a comfort level of that specific word here from this
arii.
OK so now let's run the application and let's see what happens.
So choose one of these devices and then click on OK.
So now you can see that our emulator is running.
And here it says talk to me.
Right.
But as you can see here it is actually an emulator out here.
And we cannot use this feature here inside our emulator unit to test this app on your actual Android
device.
So I'm going to test it now I'm going to test this app on my Android device and I'm going to see whether
this app is going to work or not.
So I actually tested the app on my Android device and it didn't work because there is a bug here inside
our unactivated results Meffert.
So inside the Smurfette look at this piece of code here.
This condition here is that Apprentice's of this statement.
Here we are saying if we Quest's code is equal to speak request.
So here it is true.
And request again here.
We must refer to this result code and I mistakenly referred to this request code instead.
So here I should actually delete this value and I should actually type it here.
Result code.
Ok this is very important.
You may actually later for example do this mistake.
So make sure to avoid these kinds of mistakes and make sure to always check your statements for any
kinds of mistakes like this one.
So if the score is equal to speak request and result code here is equal to result.
OK so this condition is for actually checking that if anything if actually for example getting the data
up from the voice intent was actually executed this process was actually executed normally.
So this piece of what he had this condition is necessary in order to access the data of that voice intent.
Right.
So now let me test the app on my Android device again here.
So I just want to select this device here and I just need to click on OK.
So here I actually recorded my android screen in order to show you how this app works.
So let me play this video so here I actually said hello and now you can see that the halo is outputted
here.
Inside our takes you.
So that's it.
If you have any questions please post the discussion in the course and then I'll do my best to answer
all of your questions.