1
00:00:00,200 --> 00:00:01,010
Hi everyone.

2
00:00:01,020 --> 00:00:02,590
So now in this tutorial.

3
00:00:02,640 --> 00:00:07,260
Let's actually go ahead and let's go inside this activity underline minute example here.

4
00:00:07,500 --> 00:00:09,460
So here you can see this takes you right.

5
00:00:09,480 --> 00:00:13,410
Just click on it and you can see that the idea is to the right you.

6
00:00:13,470 --> 00:00:16,240
So now let's go to our main activity class here.

7
00:00:16,440 --> 00:00:22,350
And inside this class let's declare an object or a variable of type the text you here sort of set in

8
00:00:22,350 --> 00:00:24,630
here takes the view text view.

9
00:00:24,630 --> 00:00:27,210
Now let's give a name to our valuable here.

10
00:00:27,270 --> 00:00:30,850
So as I step in here fix the underlying value.

11
00:00:30,900 --> 00:00:31,340
Right.

12
00:00:31,350 --> 00:00:33,480
So this is the name of my variable semicolon.

13
00:00:33,510 --> 00:00:35,630
So here I just declared my variable.

14
00:00:35,820 --> 00:00:39,170
Now let's go inside is uncreate Smurfette here.

15
00:00:39,480 --> 00:00:44,850
And after this line of code here that we actually call this set content view method I'm going to initialize

16
00:00:45,000 --> 00:00:49,100
this variable so I can say Pique's the underlying value assignment operator.

17
00:00:49,110 --> 00:00:57,870
So now we need to cast this object to a fixed view object find view by id r that ID that takes the value

18
00:00:58,160 --> 00:00:58,880
semicolon.

19
00:00:58,910 --> 00:00:59,630
That's it.

20
00:00:59,640 --> 00:01:00,040
Right.

21
00:01:00,060 --> 00:01:07,620
So here let's create a method inside the main activity class in order to allow the user to actually

22
00:01:07,620 --> 00:01:10,280
use the speech recognition framework.

23
00:01:10,530 --> 00:01:11,760
So let's scroll down here.

24
00:01:11,790 --> 00:01:15,000
And after the end curly brace of this uncreate method.

25
00:01:15,030 --> 00:01:20,620
And before the end in curly brace of this main activity class I can say private's OK.

26
00:01:20,620 --> 00:01:24,060
Void and the name of the Smurfette here is going to be.

27
00:01:24,090 --> 00:01:28,750
Listen listen to the users voice through the user's voice.

28
00:01:28,830 --> 00:01:33,360
And here just put a bit of practice this year and then open and close this method by using the curly

29
00:01:33,360 --> 00:01:34,620
braces.

30
00:01:34,620 --> 00:01:36,910
So now I can say so inside the Smurfette.

31
00:01:36,930 --> 00:01:42,870
Let's Create of idea of pipe intent so we can say intent and the name of this rally is going to be voice

32
00:01:42,930 --> 00:01:45,080
intent or its intent.

33
00:01:45,120 --> 00:01:47,200
Assignment operator new.

34
00:01:47,670 --> 00:01:50,220
So I'm going to create a new object of intent right.

35
00:01:50,270 --> 00:01:54,260
So new intent and instead the practice is just typing here.

36
00:01:54,300 --> 00:01:59,240
Recognize their intent that action recognize speech.

37
00:01:59,240 --> 00:01:59,950
So semicolon.

38
00:01:59,970 --> 00:02:06,570
So you're going to create a new intent in order to allow the user to actually talk to his or her phone

39
00:02:06,840 --> 00:02:10,110
or keep using this action recognized speech intent.

40
00:02:10,110 --> 00:02:17,250
So after this line of code we are going to send some data to this to this action recognize speech intent.

41
00:02:17,250 --> 00:02:21,170
So for example I can say voice intent voice intent.

42
00:02:21,180 --> 00:02:22,910
That puts extra.

43
00:02:22,980 --> 00:02:25,450
So this put extra needs to argument.

44
00:02:25,470 --> 00:02:31,460
The first argument is going to be the key and the second argument is going to be the actual date up

45
00:02:31,710 --> 00:02:34,030
that we want to see into this intent.

46
00:02:34,140 --> 00:02:37,460
So the first one is key so it is going to be recognizer intent.

47
00:02:37,530 --> 00:02:44,220
That extra that extra prompt underline prompt or case is the key comma.

48
00:02:44,400 --> 00:02:48,130
So we're going to prompt the user to actually talk to the phone.

49
00:02:48,330 --> 00:02:54,180
So that's why the key is called Extra prompt and the second argument is going to be a string value.

50
00:02:54,240 --> 00:02:57,840
And here I can't say touch to me.

51
00:02:58,000 --> 00:02:59,150
Talk to me.

52
00:02:59,260 --> 00:03:01,140
Exclamation mark semicolon.

53
00:03:01,150 --> 00:03:03,930
So again just typing here voice intent.

54
00:03:04,210 --> 00:03:10,130
That puts extra and for the first argument we need to specify the key.

55
00:03:10,180 --> 00:03:12,740
You can see that the first argument must be of type string.

56
00:03:12,750 --> 00:03:15,220
Right because all these versions of this method.

57
00:03:15,210 --> 00:03:18,580
Here the first argument which is the key is always of types 3.

58
00:03:18,670 --> 00:03:27,670
So recognizer intent that language just type typing here language and here extra language model is this

59
00:03:27,670 --> 00:03:27,870
one.

60
00:03:27,880 --> 00:03:28,560
This is the key.

61
00:03:28,690 --> 00:03:34,680
So here we want to specify that the user can actually talk in any language that he or she wants.

62
00:03:34,690 --> 00:03:42,010
So that's why the key is called extra language model and the value is going to be recognizer intent.

63
00:03:42,190 --> 00:03:48,780
That language model that language model free for that's it.

64
00:03:48,820 --> 00:03:49,640
Semi-colon.

65
00:03:49,780 --> 00:03:51,740
So let's create a new line here.

66
00:03:51,760 --> 00:03:56,810
So here I am saying that the user can't speak in any language that he or she wants.

67
00:03:56,830 --> 00:04:00,170
Language model free for this is the key extra language model.

68
00:04:00,190 --> 00:04:06,370
So again after this line of code I can say and here finally we need to specify the maximum results that

69
00:04:06,370 --> 00:04:08,530
we want to get from the user's speech.

70
00:04:08,530 --> 00:04:18,220
So I can't say we seem to end that puts extra is recognize or intent that extra underline Max results

71
00:04:19,130 --> 00:04:22,650
comma and the value is going to be.

72
00:04:22,660 --> 00:04:25,620
For example I want to get 10 actually 10 results.

73
00:04:25,630 --> 00:04:26,360
Semicolon.

74
00:04:26,410 --> 00:04:27,870
That's it right.

75
00:04:27,880 --> 00:04:31,950
And finally we need to call this if it's thought activity for result.

76
00:04:31,990 --> 00:04:34,160
We are not going to start activity here.

77
00:04:34,180 --> 00:04:39,580
We are going to start activity for results because if you want to actually get the data from the voiced

78
00:04:39,760 --> 00:04:45,490
intent so just call this the start activity for result and then when it passed the intent if she's going

79
00:04:45,490 --> 00:04:50,440
to be voice Internet karma and the request quote is is going to be the request code that you actually

80
00:04:50,440 --> 00:04:56,410
created inside the main activity class this one speech request so let's pass this value here.

81
00:04:56,500 --> 00:04:57,700
Speech request.

82
00:04:57,730 --> 00:04:58,350
That's it.

83
00:04:58,570 --> 00:05:01,840
So now this is our listen to the user's voice method right.

84
00:05:01,900 --> 00:05:04,660
So where do we actually call this method from.

85
00:05:04,790 --> 00:05:11,830
We are going to call this method from our uncreate method and after the inside if statement that we

86
00:05:11,830 --> 00:05:18,730
are 100 percent sure that the user user's device actually supports speech recognition right.

87
00:05:18,850 --> 00:05:24,460
So inside this statement We are saying that TOSed that may test your device does not support speech

88
00:05:24,460 --> 00:05:25,240
recognition.

89
00:05:25,240 --> 00:05:28,630
So here I can call this Meffert listen to the users voice.

90
00:05:28,630 --> 00:05:31,010
Right now I can scroll down here.

91
00:05:31,270 --> 00:05:32,520
So this is my faith.

92
00:05:32,590 --> 00:05:35,600
And here inside is main activity class.

93
00:05:35,740 --> 00:05:42,790
I am going to call this method of activity results suggest typing here an activity result so he had

94
00:05:42,790 --> 00:05:47,360
this is the method that we need to override here in order to actually get the data from the voice.

95
00:05:47,380 --> 00:05:49,510
Intent here inside the Smurfette.

96
00:05:49,660 --> 00:05:55,360
First we need to create an if statement so if request code so I'm going to refer to the first argument

97
00:05:55,690 --> 00:06:03,430
that we get from the Smurfit If request code is equal to the request code that we actually sent to this

98
00:06:03,430 --> 00:06:03,970
intent.

99
00:06:04,020 --> 00:06:08,740
OK this Meffert voice intent so if you sent this request code here for this instance right.

100
00:06:08,740 --> 00:06:16,750
So I am actually saying if request code is equal to that speech request here and excuse me and result

101
00:06:16,750 --> 00:06:21,130
code so if you have another argument here result quote is equal to result.

102
00:06:21,140 --> 00:06:24,200
Ok then I can open and close this if statement.

103
00:06:24,280 --> 00:06:32,110
And inside this statement I can be 100 percent sure that we get this data here that we get the data

104
00:06:32,140 --> 00:06:34,940
from the actually voice intent here.

105
00:06:35,080 --> 00:06:36,720
This statement is really important.

106
00:06:36,730 --> 00:06:41,890
That's why we create our request called a speaking request here so that later when we want to get the

107
00:06:41,890 --> 00:06:48,400
data from the voice intent we can actually to use this request not hear this speech request code in

108
00:06:48,400 --> 00:06:55,590
order to be sure that the data is coming from the specific intent that we want to get the data from.

109
00:06:55,700 --> 00:06:58,910
OK so in this if statement I can't say so.

110
00:06:58,990 --> 00:07:05,820
Now let's create an array list of string values so I can't say I least and instead the angle brackets.

111
00:07:05,830 --> 00:07:14,460
I can say strange and the name of my aerialist is going to be voice words voice for its assignment operator.

112
00:07:14,470 --> 00:07:22,270
So here I can refer to this argument which is of that intent data that gets strange aerialist extra

113
00:07:22,930 --> 00:07:24,850
get string Aurelia's extra.

114
00:07:25,060 --> 00:07:32,850
And here as an argument I can't pass this value recognizer intent that extra resolves extra underline

115
00:07:32,860 --> 00:07:35,200
results right semicolon.

116
00:07:35,230 --> 00:07:38,790
So let me create a new line here so that they can see what's going on here.

117
00:07:38,800 --> 00:07:46,030
So you are going to get the warts that the user has actually said and we are going to assign those words

118
00:07:46,120 --> 00:07:51,280
into this at least here which is of type string and are a list of string values.

119
00:07:51,310 --> 00:07:57,740
So after this line of code we can also get a decimal value from this ancient.

120
00:07:57,740 --> 00:08:04,190
So what is that this decimal value is the symbol value is going to be the preciseness of divorce that

121
00:08:04,190 --> 00:08:06,550
we are going to get from the user's voice.

122
00:08:06,610 --> 00:08:07,000
Right.

123
00:08:07,010 --> 00:08:09,150
Which is called comfort levels.

124
00:08:09,380 --> 00:08:16,220
So let's create an array of floats values float and put a pair of brackets here and here the name of

125
00:08:16,220 --> 00:08:21,050
this array is going to be confit levels assignment operator.

126
00:08:21,140 --> 00:08:27,920
And here again if you are going to refer to the state is of the intent that get float and a extra dot

127
00:08:27,950 --> 00:08:31,100
get float get float.

128
00:08:31,310 --> 00:08:39,440
Add a extra that argument past this value recognizer intent that extra confidence scores semi-colon.

129
00:08:39,440 --> 00:08:43,430
So here let me create on your line here so that you can see what's going on here.

130
00:08:43,580 --> 00:08:47,800
And now it's time to output the results to the screen.

131
00:08:47,840 --> 00:08:53,630
So now let's first like let's actually create a variable of that integer index assignment operator zero

132
00:08:53,690 --> 00:08:54,510
semicolon.

133
00:08:54,530 --> 00:08:58,040
Let's create a for in loop here instead of Frances just typing here.

134
00:08:58,040 --> 00:08:58,820
Streambed.

135
00:08:59,310 --> 00:09:04,720
And here I can't say a voice word or use that word use the word colon.

136
00:09:05,100 --> 00:09:12,530
And here we are going to iterate over each value each string value that we have inside this latest voice

137
00:09:12,530 --> 00:09:14,680
words voice words.

138
00:09:14,690 --> 00:09:21,300
So this for English here is going to be executed for each string value that we have inside is released.

139
00:09:21,320 --> 00:09:23,810
So insert this for loop here.

140
00:09:24,110 --> 00:09:25,930
Let's create an if statement.

141
00:09:25,970 --> 00:09:29,800
So if and here I'm going to refer to this at a comfort level.

142
00:09:29,990 --> 00:09:40,050
If comfort levels is not equal to null an index is less than I'm going to now I'm going to the entity

143
00:09:40,070 --> 00:09:42,860
is actually at a coffee levels that lenth.

144
00:09:42,910 --> 00:09:47,590
So only in that case we are going to actually execute the codes inside the if statement.

145
00:09:47,650 --> 00:09:53,380
First we are going to specify that if this array is not equal to all and if the index that we have here

146
00:09:53,680 --> 00:09:59,050
is actually less than the length the number of elements that we have inside this country it was only

147
00:09:59,050 --> 00:10:05,650
in this case only if these two conditions are true we can be actually 100 percent sure that we've got

148
00:10:05,650 --> 00:10:11,340
some words some words from the user that we can actually output them to the screen.

149
00:10:11,470 --> 00:10:17,640
So inside this if statement I can say TXI the underlying value it said text.

150
00:10:17,650 --> 00:10:19,240
So here just refer to this.

151
00:10:19,240 --> 00:10:26,400
Use the word plus two two coats and here just put a dash sheer space plus.

152
00:10:26,410 --> 00:10:31,680
And we are going to also out with the value of the comfort level so the comfort level is going to be.

153
00:10:31,780 --> 00:10:36,120
So let's refer to discomfit levels Aure and put a pair of brackets your index.

154
00:10:36,130 --> 00:10:36,580
So that's it.

155
00:10:36,580 --> 00:10:39,090
In this way you are going to get to use a word.

156
00:10:39,280 --> 00:10:45,280
And we also going we are going to actually get a comfort level of that specific word here from this

157
00:10:45,290 --> 00:10:45,920
arii.

158
00:10:46,210 --> 00:10:51,670
OK so now let's run the application and let's see what happens.

159
00:10:51,670 --> 00:10:53,840
So choose one of these devices and then click on OK.

160
00:10:53,860 --> 00:10:56,820
So now you can see that our emulator is running.

161
00:10:56,860 --> 00:10:59,050
And here it says talk to me.

162
00:10:59,050 --> 00:10:59,930
Right.

163
00:11:00,010 --> 00:11:04,700
But as you can see here it is actually an emulator out here.

164
00:11:04,970 --> 00:11:11,860
And we cannot use this feature here inside our emulator unit to test this app on your actual Android

165
00:11:11,860 --> 00:11:12,300
device.

166
00:11:12,310 --> 00:11:16,390
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

167
00:11:16,420 --> 00:11:18,030
this app is going to work or not.

168
00:11:18,070 --> 00:11:24,310
So I actually tested the app on my Android device and it didn't work because there is a bug here inside

169
00:11:24,370 --> 00:11:26,270
our unactivated results Meffert.

170
00:11:26,330 --> 00:11:29,070
So inside the Smurfette look at this piece of code here.

171
00:11:29,080 --> 00:11:31,920
This condition here is that Apprentice's of this statement.

172
00:11:31,930 --> 00:11:36,220
Here we are saying if we Quest's code is equal to speak request.

173
00:11:36,220 --> 00:11:37,500
So here it is true.

174
00:11:37,640 --> 00:11:40,380
And request again here.

175
00:11:40,450 --> 00:11:46,470
We must refer to this result code and I mistakenly referred to this request code instead.

176
00:11:46,480 --> 00:11:49,670
So here I should actually delete this value and I should actually type it here.

177
00:11:49,700 --> 00:11:50,920
Result code.

178
00:11:51,040 --> 00:11:52,570
Ok this is very important.

179
00:11:52,570 --> 00:11:55,920
You may actually later for example do this mistake.

180
00:11:56,140 --> 00:12:01,690
So make sure to avoid these kinds of mistakes and make sure to always check your statements for any

181
00:12:01,690 --> 00:12:03,780
kinds of mistakes like this one.

182
00:12:04,030 --> 00:12:11,470
So if the score is equal to speak request and result code here is equal to result.

183
00:12:11,470 --> 00:12:17,720
OK so this condition is for actually checking that if anything if actually for example getting the data

184
00:12:17,720 --> 00:12:24,770
up from the voice intent was actually executed this process was actually executed normally.

185
00:12:24,820 --> 00:12:30,680
So this piece of what he had this condition is necessary in order to access the data of that voice intent.

186
00:12:30,730 --> 00:12:31,280
Right.

187
00:12:31,600 --> 00:12:35,920
So now let me test the app on my Android device again here.

188
00:12:35,920 --> 00:12:39,090
So I just want to select this device here and I just need to click on OK.

189
00:12:39,160 --> 00:12:44,550
So here I actually recorded my android screen in order to show you how this app works.

190
00:12:44,550 --> 00:12:52,230
So let me play this video so here I actually said hello and now you can see that the halo is outputted

191
00:12:52,240 --> 00:12:52,690
here.

192
00:12:52,840 --> 00:12:54,440
Inside our takes you.

193
00:12:54,730 --> 00:12:55,360
So that's it.

194
00:12:55,390 --> 00:12:59,500
If you have any questions please post the discussion in the course and then I'll do my best to answer

195
00:12:59,530 --> 00:13:00,670
all of your questions.

