1
00:00:06,280 --> 00:00:06,690
All right.

2
00:00:06,690 --> 00:00:09,020
So let's go ahead and let's get coding.

3
00:00:09,040 --> 00:00:14,920
We're going to be doing everything inside of our controller here and by everything I mean that there

4
00:00:14,920 --> 00:00:15,990
is very little code.

5
00:00:16,030 --> 00:00:18,870
Normally you would create classes and create a bunch of other stuff.

6
00:00:18,880 --> 00:00:23,240
But our app is so simple that we really don't actually need all of that.

7
00:00:23,260 --> 00:00:27,240
So let's go ahead and get rid of the boilerplate code that we do not need.

8
00:00:27,430 --> 00:00:29,400
And this is well we don't need it.

9
00:00:29,770 --> 00:00:34,820
And so let's think what do we actually need in order for this to work.

10
00:00:35,920 --> 00:00:42,160
We're going to go ahead and we're going to import our frameworks so import speech.

11
00:00:42,220 --> 00:00:44,260
That's the name of the new framework we'll be using.

12
00:00:44,500 --> 00:00:48,150
And we're also going to import avi foundation.

13
00:00:48,520 --> 00:00:48,960
OK.

14
00:00:49,030 --> 00:00:52,280
And if it's telling you that it can't find it it's just being whiney.

15
00:00:52,360 --> 00:00:54,540
Give it a give it a command B to build.

16
00:00:54,760 --> 00:01:01,560
And those errors will go away because they're just being silly and the Escobedo sometimes does that.

17
00:01:01,930 --> 00:01:12,070
So let's go ahead and we're going to basically create a couple of things we're going to create Iby actions

18
00:01:12,070 --> 00:01:15,380
and be outlets for our activity spinner.

19
00:01:15,580 --> 00:01:22,450
And for our textfield because they're going to need to be modified per our apps requirements so go back

20
00:01:22,450 --> 00:01:23,620
to storyboarded.

21
00:01:23,650 --> 00:01:24,660
Sorry about that.

22
00:01:24,670 --> 00:01:31,810
We're going to drop those in now and let's close out of pre-view and go to new controller.

23
00:01:32,390 --> 00:01:33,210
OK.

24
00:01:33,730 --> 00:01:38,740
So selecting our button with a right click and dragging to our view controller.

25
00:01:38,980 --> 00:01:41,820
Let's name this.

26
00:01:41,880 --> 00:01:42,630
That was our button.

27
00:01:42,650 --> 00:01:44,210
Yeah let's name it.

28
00:01:44,530 --> 00:01:45,640
Oh I'm so sorry.

29
00:01:45,640 --> 00:01:48,730
We need to actually create an I.V. outlet for our spinner.

30
00:01:48,730 --> 00:01:49,670
I said that already.

31
00:01:49,870 --> 00:01:54,410
So let's drag it over here and this will be activity spinner.

32
00:01:55,480 --> 00:01:56,120
OK.

33
00:01:56,470 --> 00:02:00,270
And then underneath that we want to do one for our UI.

34
00:02:00,280 --> 00:02:00,940
Text view.

35
00:02:00,970 --> 00:02:04,690
So go ahead and drag that here and name this one.

36
00:02:04,800 --> 00:02:10,580
Maybe transcription text field.

37
00:02:10,660 --> 00:02:12,560
Hey there we go.

38
00:02:12,830 --> 00:02:18,350
We have Ivy outlets that will modify this which will start at animating and we'll hide it when we need

39
00:02:18,350 --> 00:02:18,980
to.

40
00:02:19,280 --> 00:02:25,280
And we also have an idea here that will allow us to send in the text from our transcription when we

41
00:02:25,280 --> 00:02:26,130
get it done.

42
00:02:26,450 --> 00:02:27,100
OK.

43
00:02:27,410 --> 00:02:27,640
OK.

44
00:02:27,650 --> 00:02:34,050
So next let's just go ahead and hide our activities spinner when we launch our app.

45
00:02:34,070 --> 00:02:39,160
So activity's spinner dot and switch three.

46
00:02:39,200 --> 00:02:46,220
It's now called is hidden equals true so that when we launch our app the button is available and the

47
00:02:46,220 --> 00:02:47,860
spinner is not.

48
00:02:47,890 --> 00:02:53,770
That's exactly what we want let's go ahead and make this a little easier to see.

49
00:02:54,250 --> 00:02:55,040
There we go.

50
00:02:55,390 --> 00:02:56,030
All right.

51
00:02:56,410 --> 00:02:59,170
So we have our activity spinner hidden.

52
00:02:59,230 --> 00:02:59,770
Very good.

53
00:03:00,840 --> 00:03:09,790
Now we need to go ahead and we need to create the function that will request speech authentication.

54
00:03:09,840 --> 00:03:12,970
Remember I said you have to authenticate just like you would with not get.

55
00:03:12,990 --> 00:03:21,800
So we're going to make a function to do that phunk request speech off and inside of that let's create

56
00:03:21,800 --> 00:03:25,260
something called an s f speech recognizer.

57
00:03:27,070 --> 00:03:28,130
Just like that.

58
00:03:28,300 --> 00:03:34,210
And we need to request authorization similarly to how you would on maps.

59
00:03:34,330 --> 00:03:34,540
OK.

60
00:03:34,540 --> 00:03:40,330
And for the handler just press enter and basically we're going to delete this because we don't need

61
00:03:40,330 --> 00:03:41,180
it.

62
00:03:41,440 --> 00:03:46,120
But you do need this bracket and the in here because we are working inside of a little closure.

63
00:03:46,510 --> 00:03:47,130
OK.

64
00:03:47,380 --> 00:03:52,840
So sorry I forgot we need to give us an off status here.

65
00:03:54,790 --> 00:04:00,550
K now in order to actually do something with the status we need to type.

66
00:04:00,610 --> 00:04:12,360
If our status is double equal to s f speech recognizer authorization status dot authorized

67
00:04:14,840 --> 00:04:19,100
We now want to basically set it up to handle our media file.

68
00:04:19,130 --> 00:04:24,680
But we have not yet added that so I will be providing this in the source code but I've just created

69
00:04:24,680 --> 00:04:31,820
a little audio file called test and fauré and I'm going to drop that in right up here and make sure

70
00:04:31,820 --> 00:04:37,880
that you have copy items if needed create folder references and make sure you add it to the target scribe

71
00:04:38,810 --> 00:04:39,860
click finished.

72
00:04:40,560 --> 00:04:47,850
And for stuff like this I like to create a group and name it resources and I'll just drag that file

73
00:04:47,850 --> 00:04:49,530
inside of resources.

74
00:04:50,190 --> 00:04:50,930
OK.

75
00:04:51,180 --> 00:04:52,380
Let's not forget it's there.

76
00:04:52,680 --> 00:04:58,470
OK so now we're going to set up the path to this file so that our audio player can access it.

77
00:04:58,690 --> 00:05:02,770
And so that our speech recognizer can analyze it.

78
00:05:02,820 --> 00:05:04,950
So we're going to kind of kill two birds with one stone.

79
00:05:05,250 --> 00:05:16,050
So go ahead and type if let path whoops éclat path equals bundled up Main your L for resource

80
00:05:19,330 --> 00:05:23,560
and then basically we're going to just tell it yeah right here the name as a string.

81
00:05:23,560 --> 00:05:30,460
So our file is called test with extension extension of course is for.

82
00:05:30,490 --> 00:05:31,830
No need for the dot.

83
00:05:31,840 --> 00:05:33,590
It takes care of that for you.

84
00:05:34,030 --> 00:05:40,200
So in order for this to actually oh yeah go ahead and give it some brackets and tab down there.

85
00:05:40,240 --> 00:05:44,010
Now in order for this to actually pull the file we need to create an audio player.

86
00:05:44,260 --> 00:05:56,430
So below your ID outlets go ahead and type bar audio player of type avi audio low D player and we're

87
00:05:56,430 --> 00:05:58,250
not going to instantiate it yet.

88
00:05:58,410 --> 00:06:00,020
So go ahead and do that.

89
00:06:00,300 --> 00:06:07,740
So now we need to basically tell the app how we want it to play the audio and so to do this we need

90
00:06:07,740 --> 00:06:11,110
to be safe and go ahead and type do.

91
00:06:11,550 --> 00:06:19,420
And inside of this bracket we're going to type let sound equals try avi audio player

92
00:06:22,130 --> 00:06:23,480
sometimes you have to wait for the autocorrect.

93
00:06:23,480 --> 00:06:31,340
There it is Avi audio player and we want to pull the contents of the path that we just created straight

94
00:06:31,340 --> 00:06:32,750
to our file.

95
00:06:32,830 --> 00:06:41,030
Now underneath that we need to set up the audio player the one that we created up here.

96
00:06:41,030 --> 00:06:44,660
We want to set that up with our sound.

97
00:06:44,660 --> 00:06:47,990
So this actually sorry needs to be.

98
00:06:48,290 --> 00:06:48,830
Oh no I'm sorry.

99
00:06:48,830 --> 00:06:49,550
That's correct.

100
00:06:49,550 --> 00:06:53,580
So we want our audio player to have a sound.

101
00:06:53,660 --> 00:06:58,050
Now it needs to be cell because we're going inside of a closure here.

102
00:06:58,350 --> 00:07:00,600
And I'll explain more about that in a second.

103
00:07:00,680 --> 00:07:06,640
So self-taught audio player equals sound that we just created here.

104
00:07:07,480 --> 00:07:13,950
Then below that we want to type self audio player.

105
00:07:14,450 --> 00:07:16,200
Sorry I'm getting ahead of myself here.

106
00:07:16,220 --> 00:07:18,440
We want to type sound dot play.

107
00:07:20,180 --> 00:07:29,360
And in order for this to actually work the right way we need to provide a catch block that will catch

108
00:07:29,420 --> 00:07:31,070
errors in case there are any.

109
00:07:31,160 --> 00:07:35,720
This is just something that's mandatory for playing audio and in our catch block we're just going to

110
00:07:35,720 --> 00:07:38,290
print just a generic error.

111
00:07:38,300 --> 00:07:45,290
It's not going to actually be anything useful but it basically satisfies the needs of our stuff here

112
00:07:45,290 --> 00:07:46,320
that we're doing.

113
00:07:46,670 --> 00:07:47,030
All right.

114
00:07:47,030 --> 00:07:51,740
So we have now requested speech authorization.

115
00:07:51,740 --> 00:07:58,040
We have come through once it is authorized and basically giving it a path to find the file.

116
00:07:58,040 --> 00:08:00,650
Now this right here this do block.

117
00:08:00,680 --> 00:08:04,420
This is going to play the audio file but it is not yet analyzing it.

118
00:08:04,420 --> 00:08:06,960
I just thought it would make sense to play the file.

119
00:08:06,980 --> 00:08:11,180
While we're also simultaneously analyzing it.

120
00:08:11,270 --> 00:08:16,580
So let's get on to the analysis now and then in a second.

121
00:08:16,580 --> 00:08:20,870
We're going to basically check to see if the player works and check to see if the analysis works too.

122
00:08:21,170 --> 00:08:28,620
So go ahead and if you remember on that documentation I showed you we need a recognizer a request a

123
00:08:28,640 --> 00:08:31,370
recognition task and then it prints out a result.

124
00:08:31,370 --> 00:08:35,200
And that is the text that we want to fill our UI text for you.

125
00:08:35,330 --> 00:08:43,630
So let's create a recognizer of type f s f speech recognizer.

126
00:08:43,680 --> 00:08:49,830
So many long words go ahead and give us some parentheses there to instantiate a blank one there.

127
00:08:50,340 --> 00:09:00,870
Let's create a request request equals s f speech you RL recognition request and that will basically

128
00:09:01,410 --> 00:09:07,390
understand our u r l that we have laid out for our file here.

129
00:09:07,390 --> 00:09:08,710
Test him for a.

130
00:09:08,970 --> 00:09:16,580
And I'm forgetting something we need to include u r l and of course that is path because we created

131
00:09:16,580 --> 00:09:18,220
it here here.

132
00:09:18,610 --> 00:09:22,550
So down below let's create the next required thing.

133
00:09:22,550 --> 00:09:24,260
It's a part of recognizer.

134
00:09:24,290 --> 00:09:29,210
So let's go recognizer recognition task.

135
00:09:29,450 --> 00:09:36,960
Now it says with s f speech recognition requests and we already have that it's called request and r

136
00:09:36,960 --> 00:09:47,810
s f speech recognition task delegate that is basically going to well let's just go ahead and get rid

137
00:09:47,810 --> 00:09:49,310
of it X because we don't need it.

138
00:09:49,340 --> 00:09:55,460
Sorry we're going to type with code and request and then we're going to create a closure and inside

139
00:09:55,460 --> 00:10:01,010
of that we're going to basically print a result and an error if we need to.

140
00:10:01,020 --> 00:10:02,430
So go ahead and add that.

141
00:10:02,630 --> 00:10:09,710
And then since it's a closure we need to type in to give it a clue that we're starting the closure and

142
00:10:09,740 --> 00:10:15,140
it's giving us an error because it's saying that we were not yet using that result but we'll do that

143
00:10:15,350 --> 00:10:16,370
right now.
