1
00:00:06,880 --> 00:00:12,070
So basically we want to set this up so that if there's an error that it will stop the app and print

2
00:00:12,070 --> 00:00:13,400
the error.

3
00:00:13,790 --> 00:00:17,240
Otherwise we want it to do what we need it to.

4
00:00:17,260 --> 00:00:21,640
So let's type if let error equals error.

5
00:00:22,060 --> 00:00:31,030
So if we were going to create a constant called error and if this error is made equal to the error that

6
00:00:31,030 --> 00:00:32,470
the recognizer throws

7
00:00:36,550 --> 00:00:39,240
then we're going to print.

8
00:00:39,880 --> 00:00:44,590
There was an error Colin.

9
00:00:45,520 --> 00:00:52,610
And we're going to give it the error that it created using this little encapsulation type thingamabob

10
00:00:52,640 --> 00:00:54,360
string interpellation that's what it's called.

11
00:00:54,670 --> 00:01:00,340
So if there's an error it'll be thrown in right there and it will print nicely for us but now we want

12
00:01:00,340 --> 00:01:07,430
to say else otherwise we want to basically print the transcription.

13
00:01:07,750 --> 00:01:11,180
So let's let's go and just stop and run through this.

14
00:01:11,260 --> 00:01:16,710
Here's our path to our audio file and we're going to start playing the music.

15
00:01:16,780 --> 00:01:24,280
Then immediately after that we set up a recognizer we create a request that pulls the file and it silently

16
00:01:24,280 --> 00:01:29,090
parses through this file entry and turns it into text which is so cool.

17
00:01:29,410 --> 00:01:31,720
So then we create a recognition task.

18
00:01:31,720 --> 00:01:33,220
And this is actually sorry.

19
00:01:33,220 --> 00:01:37,020
This is actually where it recognizes the text and then prints a result.

20
00:01:37,030 --> 00:01:42,050
And so while it's doing that we're going to actually print the end result.

21
00:01:42,050 --> 00:01:47,630
So it's called result dot best transcription.

22
00:01:47,950 --> 00:01:52,990
And this is the most accurate one that is created and we want to set it up as a formatted string so

23
00:01:52,990 --> 00:01:58,590
that it starts with a capital and is formatted nicely.

24
00:01:58,670 --> 00:02:04,290
So this is a lot of stuff and we have not yet checked to see if it works.

25
00:02:04,320 --> 00:02:14,770
So let's go ahead and create an Iby action to trigger loading our audio and transcribing.

26
00:02:14,820 --> 00:02:22,790
So open your mind up storyboard open your assistant editor and pull open your view controller an automatic

27
00:02:22,790 --> 00:02:24,230
of course.

28
00:02:24,240 --> 00:02:24,860
OK.

29
00:02:25,230 --> 00:02:28,150
So underneath this is the button.

30
00:02:28,170 --> 00:02:30,360
So you may have to access it from here.

31
00:02:30,360 --> 00:02:34,260
I like to create my actions at the bottom of my view controllers

32
00:02:36,950 --> 00:02:43,500
so down here you up right click from button down below here.

33
00:02:43,820 --> 00:02:45,510
Now well let me.

34
00:02:45,560 --> 00:02:47,590
Why is this strange.

35
00:02:47,630 --> 00:02:48,350
Let's try it again.

36
00:02:48,370 --> 00:02:49,190
Oh there we go.

37
00:02:54,770 --> 00:02:55,710
I wonder.

38
00:02:56,080 --> 00:02:57,180
Oh you know what.

39
00:02:57,250 --> 00:02:57,970
Let me cancel this.

40
00:02:57,970 --> 00:03:01,460
I must have accidentally deleted an important bracket.

41
00:03:01,690 --> 00:03:01,960
Yeah.

42
00:03:01,990 --> 00:03:03,130
Looks like that's what I did.

43
00:03:04,710 --> 00:03:09,180
Let's go ahead and scoot those over scoot that over cleaned it up there.

44
00:03:09,180 --> 00:03:09,680
OK.

45
00:03:16,220 --> 00:03:16,830
All right.

46
00:03:17,060 --> 00:03:21,200
So now what is that huh.

47
00:03:21,550 --> 00:03:22,390
So I delete two

48
00:03:26,440 --> 00:03:28,810
maybe I do it into 1.

49
00:03:28,840 --> 00:03:29,910
It's strange.

50
00:03:30,110 --> 00:03:33,280
What is this expected declaration.

51
00:03:33,280 --> 00:03:35,170
My class is here.

52
00:03:35,730 --> 00:03:36,920
Let's lower that.

53
00:03:36,960 --> 00:03:38,130
So if I go

54
00:03:43,310 --> 00:03:44,020
one more OK.

55
00:03:44,030 --> 00:03:45,920
Now our classes finally closed.

56
00:03:45,920 --> 00:03:46,780
There we go.

57
00:03:48,860 --> 00:03:52,720
Let's cancel the simulator.

58
00:03:52,720 --> 00:03:54,140
We don't really need that right now.

59
00:03:54,350 --> 00:03:56,620
That's just taking up a lot of extra memory.

60
00:03:57,000 --> 00:03:57,330
OK.

61
00:03:57,330 --> 00:04:03,560
So we're going to go out and create space for an IB action right click drag and drop it down here.

62
00:04:04,690 --> 00:04:10,320
Change it to action of course and we're going to call this play button.

63
00:04:11,170 --> 00:04:14,490
Pressed ok cool.

64
00:04:14,530 --> 00:04:20,080
So let's go out and close the assistant editor go back to our new controller just to save on some memory

65
00:04:20,130 --> 00:04:21,460
and space and time here.

66
00:04:21,490 --> 00:04:23,170
Ok cool.

67
00:04:23,170 --> 00:04:27,630
So let's go down to that IAB action.

68
00:04:28,030 --> 00:04:38,490
Now what we should do is basically when that button is pressed we want to hide our activity I'm sorry.

69
00:04:38,530 --> 00:04:45,550
We want to show our hidden activity spinner so activity spinner that is hidden is no longer true.

70
00:04:45,550 --> 00:04:47,230
It is now false.

71
00:04:47,230 --> 00:04:53,890
We also want our activity spinner to start spinning of course because otherwise it just looks like a

72
00:04:53,890 --> 00:04:56,990
static photo which is nowhere near as cool.

73
00:04:57,640 --> 00:05:00,430
So activity spinner does start animating

74
00:05:03,530 --> 00:05:06,850
equals true very very cool.

75
00:05:07,010 --> 00:05:10,590
And you know what we don't actually need to just start animating because it's a function that is called

76
00:05:10,590 --> 00:05:11,580
Right on it.

77
00:05:12,120 --> 00:05:17,940
Now it's indexing the files here which is why everything looks purple and white and not properly colored

78
00:05:17,970 --> 00:05:21,100
but in a moment it will change back I promise.

79
00:05:21,190 --> 00:05:21,400
OK.

80
00:05:21,420 --> 00:05:27,620
So beneath this go ahead and type the name of our function request speech.

81
00:05:29,460 --> 00:05:32,530
And we are not building nearly as much as we should.

82
00:05:32,550 --> 00:05:36,310
So we're finally at a point where we can build this app.

83
00:05:36,390 --> 00:05:37,860
So let's go ahead and give it a shot.

84
00:05:37,920 --> 00:05:42,700
Let's try building it on our simulator and see what happens.

85
00:05:47,020 --> 00:05:47,380
OK.

86
00:05:47,400 --> 00:05:47,940
Here we go.

87
00:05:47,940 --> 00:05:49,520
Let's take a look.

88
00:05:49,650 --> 00:05:51,820
Let's see what happens.

89
00:05:56,150 --> 00:05:56,700
Ok cool.

90
00:05:56,710 --> 00:06:01,240
So nothing looks different here but let's try to see if it works if I click it should start playing

91
00:06:01,240 --> 00:06:02,620
my audio file.

92
00:06:02,620 --> 00:06:09,310
It should recognize the audio and transcribe it and print it here in the console so let's give it a

93
00:06:09,310 --> 00:06:09,800
shot.

94
00:06:20,430 --> 00:06:28,930
So it doesn't seem Oh we crashed Interesting OK let's look at our error code here.

95
00:06:29,190 --> 00:06:38,320
The app's info up list must contain an n s speech recognition usage description key Oh right we forgot

96
00:06:38,320 --> 00:06:41,040
something very very important.

97
00:06:41,230 --> 00:06:44,710
We need to add this and speech recognition usage description.

98
00:06:44,710 --> 00:06:45,110
Wow.

99
00:06:45,130 --> 00:06:46,240
That is a mouthful.

100
00:06:46,540 --> 00:06:51,760
Go ahead and terminate the app and we're going to add that to our info duppy list.

101
00:06:51,760 --> 00:07:00,100
So basically click on your project over here and find your info up the list file and then basically

102
00:07:00,160 --> 00:07:01,760
we're going to add a new key here.

103
00:07:01,780 --> 00:07:05,740
By clicking the plus make sure this is closed not open.

104
00:07:05,740 --> 00:07:11,900
Make sure this is closed click plus and then you're going to type what we just saw here.

105
00:07:11,950 --> 00:07:20,150
So go ahead and type an s speech recognition usage description.

106
00:07:20,470 --> 00:07:26,710
And when I press Enter you'll see it actually changes into what it actually should look like but it's

107
00:07:26,710 --> 00:07:29,300
not yet auto completing because we're still in Beta.

108
00:07:29,320 --> 00:07:33,890
But by the time that the official XTO day comes out we'll be good to go.

109
00:07:34,290 --> 00:07:34,660
OK.

110
00:07:34,780 --> 00:07:41,470
So basically this is the nice little message that will pop up when you request speech off.

111
00:07:41,590 --> 00:07:53,480
So when it pops up you want to say something like We need to analyze and transcribe your audio.

112
00:07:53,670 --> 00:07:55,990
We hope that's cool.

113
00:07:56,830 --> 00:07:59,270
Let's add a nice little emoji here.

114
00:08:00,080 --> 00:08:02,480
Let's go ahead and give it a nice little thumbs up.

115
00:08:02,480 --> 00:08:04,660
I actually have one of these.

116
00:08:04,750 --> 00:08:05,700
We go.

117
00:08:05,980 --> 00:08:06,670
All right.

118
00:08:06,980 --> 00:08:12,790
So this is I think the reason our app crash let's build it one more time.

119
00:08:12,790 --> 00:08:15,820
Let's give it a shot and see if it works the way we want it to.

120
00:08:15,830 --> 00:08:21,440
Now right we go.

121
00:08:21,760 --> 00:08:27,670
So when we click this button it should request authorization.

122
00:08:27,780 --> 00:08:29,080
Hey look at that.

123
00:08:29,360 --> 00:08:34,840
OK so now we have a permission thingy we need to analyze and transcribe your audio we hope that's cool.

124
00:08:35,030 --> 00:08:36,430
So click allow.

125
00:08:36,590 --> 00:08:37,680
OK.

126
00:08:38,120 --> 00:08:42,530
And it appears to be not working.

127
00:08:42,530 --> 00:08:46,550
There was an error when it was suspended.

128
00:08:46,760 --> 00:08:47,470
OK.

129
00:08:47,790 --> 00:08:54,200
So it appears to be working but we know that right here in the in the console that it is not.

130
00:08:54,200 --> 00:09:01,250
And you know what I actually know why that is using the speech API on the simulator for whatever reason

131
00:09:01,580 --> 00:09:04,040
does not work on a simulator device.

132
00:09:04,040 --> 00:09:11,070
So I'm going to switch over to my iPhone here and I'm going to basically create a new movie recording

133
00:09:12,080 --> 00:09:16,650
and I'm going to set it up here to use my iPhone.

134
00:09:16,680 --> 00:09:17,700
So just like that.

135
00:09:17,700 --> 00:09:18,960
Here we go.

136
00:09:19,290 --> 00:09:23,160
And so I'm going to build it to my iPhone and then we're going to be able to see if this actually works

137
00:09:23,160 --> 00:09:24,710
the way it's supposed to.

138
00:09:24,810 --> 00:09:33,990
So I'll select my humourously named iPhone and build it to that one and we'll see if it's going to be

139
00:09:34,080 --> 00:09:35,780
nice to us.

140
00:09:35,790 --> 00:09:43,090
I apologize for my messy homescreen but least my wallpapers call.

141
00:09:43,240 --> 00:09:46,130
We go scribe is now installed.

142
00:09:46,150 --> 00:09:49,930
It's going to pop open here and on my iPhone.

143
00:09:49,930 --> 00:09:51,370
Let's go ahead and give it a shot.

144
00:09:52,160 --> 00:09:52,640
OK.

145
00:09:52,790 --> 00:09:57,630
So I tap the button it requests my permission and I click OK.

146
00:09:58,880 --> 00:10:02,040
So oh hey awesome.

147
00:10:02,050 --> 00:10:03,130
So look at that.

148
00:10:03,220 --> 00:10:05,300
That is exactly what we need it.

149
00:10:05,410 --> 00:10:08,490
Scribe just might be the coolest app I've ever made.

150
00:10:09,240 --> 00:10:09,690
Great.

151
00:10:09,690 --> 00:10:13,830
So let's go back to my iPhone here which is recording.

152
00:10:13,830 --> 00:10:17,510
Do you notice that the spinner is still spinning.

153
00:10:17,880 --> 00:10:21,100
Yeah that's because we have not yet told when to stop.

154
00:10:21,090 --> 00:10:23,740
So let's go ahead and stop that from running.

155
00:10:24,090 --> 00:10:27,760
And in our view controller we need to add a couple of things.

156
00:10:27,960 --> 00:10:37,880
So we need to create Well basically all we need to do is tell it what we want it to do.

157
00:10:37,920 --> 00:10:43,400
As far as stopping goes and in order to do that we need to implement the avy audio player delegate.

158
00:10:43,470 --> 00:10:52,140
So up at the top of your class type avi audio player flips out the player audio player delegate.

159
00:10:52,650 --> 00:10:59,400
Just like that and there is a function inside this delegate that will help us monitor and analyze what

160
00:10:59,400 --> 00:11:01,500
an audio player has finished.

161
00:11:01,560 --> 00:11:03,090
And this is really really cool.

162
00:11:03,150 --> 00:11:08,850
So let's go ahead add that and it is called Audio Player did finished playing just like that.

163
00:11:09,660 --> 00:11:18,330
So all we need to do inside of this is basically just say player dot stop because what this does is

164
00:11:18,330 --> 00:11:21,280
it basically searches for an instance of AB audio player.

165
00:11:21,480 --> 00:11:24,890
And then we can pass this command stop straight to it.

166
00:11:24,930 --> 00:11:35,310
Beneath that we want to say activity spinner whip's activity spinner datt stop animating and activity

167
00:11:35,310 --> 00:11:42,780
spinner dot is hidden equals truth because when the audio is done we want the button to be enabled again

168
00:11:42,780 --> 00:11:45,050
so we can analyze the audio if we want to.

169
00:11:45,390 --> 00:11:51,490
So this now will analyze when the player is finished.

170
00:11:51,750 --> 00:11:53,030
It will stop the player.

171
00:11:53,040 --> 00:11:56,690
It will hide the spinner and it will stop it from animating.

172
00:11:56,700 --> 00:12:00,700
Now there's one last thing we need to do and it won't work without it.

173
00:12:00,750 --> 00:12:08,310
But we basically need to tell the audio player that it has a delegate like that sounds silly but all

174
00:12:08,310 --> 00:12:13,500
we need to do is type cell audio player which is the one that we created here.

175
00:12:13,560 --> 00:12:19,090
Self-taught audio player delegate equals self.

176
00:12:19,140 --> 00:12:24,050
So this basically just sets this view controller up to be its delegate and it's giving me an issue here

177
00:12:24,060 --> 00:12:28,130
what is the deal expression resolves to an unused.

178
00:12:28,170 --> 00:12:32,070
I value that is really interesting.

179
00:12:32,100 --> 00:12:34,790
Why would that be up.

180
00:12:34,800 --> 00:12:36,300
Looks like it just needed to build.

181
00:12:36,300 --> 00:12:42,390
Never mind sometimes if you add in some sub subclassing and things like that here are some inheritance

182
00:12:42,390 --> 00:12:43,410
here.

183
00:12:43,530 --> 00:12:47,650
It takes a while for it to analyze and really understand what it is that you are doing.

184
00:12:47,730 --> 00:12:52,010
So now that it is good to go it has a delegate.

185
00:12:52,170 --> 00:12:55,630
It has the function to detect that it has finished playing.

186
00:12:56,130 --> 00:12:59,540
Let's go ahead and run it and let's see if it works how we hope.

187
00:13:04,150 --> 00:13:06,810
OK let's check to see if it does what it's supposed to.

188
00:13:07,090 --> 00:13:12,220
So as soon as it's done playing the audio file it should go ahead and stop the spinner and make the

189
00:13:12,220 --> 00:13:18,250
button look just like it is right now so let's tap the button scribe just might be the coolest app I've

190
00:13:18,250 --> 00:13:19,150
ever made.

191
00:13:20,900 --> 00:13:23,390
Hey and it's finished and the button stopped.

192
00:13:23,390 --> 00:13:25,870
That is exactly what we wanted to do.

193
00:13:25,870 --> 00:13:27,420
Super duper cool.

194
00:13:27,740 --> 00:13:29,870
So let's let's think.

195
00:13:29,870 --> 00:13:31,860
Is there anything else that we are forgetting.

196
00:13:32,150 --> 00:13:33,610
Let's go inside of scribe.

197
00:13:35,100 --> 00:13:35,560
Oops.

198
00:13:36,880 --> 00:13:37,650
Am I forgetting.

199
00:13:37,690 --> 00:13:43,180
Oh of course we're not even putting in the audio into our app or mean the transcription we know it's

200
00:13:43,180 --> 00:13:48,940
printing here but we have yet to actually put it in where it's supposed to go.

201
00:13:49,300 --> 00:13:51,340
Now if you remember the result.

202
00:13:51,430 --> 00:13:55,000
Best descript best transcription formatted string.

203
00:13:55,030 --> 00:13:56,400
This is where it's supposed to be.

204
00:13:56,800 --> 00:14:04,180
But we actually can just set the text value of our text to you here to fill with this text.

205
00:14:04,180 --> 00:14:12,020
So delete this delete print and we're basically going to say self dot.

206
00:14:12,070 --> 00:14:17,010
And remember we already created an outlet for our transcription textfield.

207
00:14:17,290 --> 00:14:24,180
So where was that self transcription textfield text equals result.

208
00:14:24,220 --> 00:14:26,180
Best transcription formatted string.

209
00:14:26,470 --> 00:14:34,110
So in theory when I run this app it should transcribe and it should drop this text right in to our app.

210
00:14:34,300 --> 00:14:35,220
Let's give it a shot.

211
00:14:43,720 --> 00:14:48,340
Let's let it run and let it build and run again.

212
00:14:49,210 --> 00:14:50,100
And here we go.

213
00:14:55,690 --> 00:14:58,220
OK let's take a look what's on my phone.

214
00:14:59,280 --> 00:15:02,930
Scribe just might be the call it is ever made.

215
00:15:02,970 --> 00:15:03,970
OK.

216
00:15:04,440 --> 00:15:09,060
It finishes playing the player turns off just like we did with the delegate function there.

217
00:15:09,060 --> 00:15:09,870
Let's do it again.

218
00:15:09,990 --> 00:15:13,830
Scribe just might be the coolest app I've ever made.

219
00:15:15,140 --> 00:15:16,020
Awesome.

220
00:15:16,280 --> 00:15:23,230
OK guys well you know what we just created a beautiful app that uses the new speech recognition API

221
00:15:23,270 --> 00:15:24,450
from Apple in Iowa.

222
00:15:25,610 --> 00:15:31,060
We requested a speech authorization using that function in the info up list.

223
00:15:31,190 --> 00:15:39,080
We created a recognizer that basically analyzes our audio turns it into text and we also simultaneously

224
00:15:39,080 --> 00:15:42,210
created a player that played it at the same time.

225
00:15:42,800 --> 00:15:47,860
So this is only scratching the surface of what is possible with this speech API.

226
00:15:47,860 --> 00:15:54,200
And in a future video I'm going to be talking about how you can analyze live audio and then eventually

227
00:15:54,350 --> 00:16:00,100
how you can analyze live audio and set a new function based on a certain key word or phrases set.

228
00:16:00,410 --> 00:16:01,400
So stay tuned for those.

229
00:16:01,550 --> 00:16:02,180
Thanks for watching.

230
00:16:02,180 --> 00:16:02,730
This is cool.

231
00:16:02,730 --> 00:16:03,900
So some folks like.
