All right.
So let's go ahead and let's get coding.
We're going to be doing everything inside of our controller here and by everything I mean that there
is very little code.
Normally you would create classes and create a bunch of other stuff.
But our app is so simple that we really don't actually need all of that.
So let's go ahead and get rid of the boilerplate code that we do not need.
And this is well we don't need it.
And so let's think what do we actually need in order for this to work.
We're going to go ahead and we're going to import our frameworks so import speech.
That's the name of the new framework we'll be using.
And we're also going to import avi foundation.
OK.
And if it's telling you that it can't find it it's just being whiney.
Give it a give it a command B to build.
And those errors will go away because they're just being silly and the Escobedo sometimes does that.
So let's go ahead and we're going to basically create a couple of things we're going to create Iby actions
and be outlets for our activity spinner.
And for our textfield because they're going to need to be modified per our apps requirements so go back
to storyboarded.
Sorry about that.
We're going to drop those in now and let's close out of pre-view and go to new controller.
OK.
So selecting our button with a right click and dragging to our view controller.
Let's name this.
That was our button.
Yeah let's name it.
Oh I'm so sorry.
We need to actually create an I.V. outlet for our spinner.
I said that already.
So let's drag it over here and this will be activity spinner.
OK.
And then underneath that we want to do one for our UI.
Text view.
So go ahead and drag that here and name this one.
Maybe transcription text field.
Hey there we go.
We have Ivy outlets that will modify this which will start at animating and we'll hide it when we need
to.
And we also have an idea here that will allow us to send in the text from our transcription when we
get it done.
OK.
So next let's just go ahead and hide our activities spinner when we launch our app.
So activity's spinner dot and switch three.
It's now called is hidden equals true so that when we launch our app the button is available and the
spinner is not.
That's exactly what we want let's go ahead and make this a little easier to see.
There we go.
All right.
So we have our activity spinner hidden.
Very good.
Now we need to go ahead and we need to create the function that will request speech authentication.
Remember I said you have to authenticate just like you would with not get.
So we're going to make a function to do that phunk request speech off and inside of that let's create
something called an s f speech recognizer.
Just like that.
And we need to request authorization similarly to how you would on maps.
OK.
And for the handler just press enter and basically we're going to delete this because we don't need
it.
But you do need this bracket and the in here because we are working inside of a little closure.
OK.
So sorry I forgot we need to give us an off status here.
K now in order to actually do something with the status we need to type.
If our status is double equal to s f speech recognizer authorization status dot authorized
We now want to basically set it up to handle our media file.
But we have not yet added that so I will be providing this in the source code but I've just created
a little audio file called test and fauré and I'm going to drop that in right up here and make sure
that you have copy items if needed create folder references and make sure you add it to the target scribe
click finished.
And for stuff like this I like to create a group and name it resources and I'll just drag that file
inside of resources.
OK.
Let's not forget it's there.
OK so now we're going to set up the path to this file so that our audio player can access it.
And so that our speech recognizer can analyze it.
So we're going to kind of kill two birds with one stone.
So go ahead and type if let path whoops éclat path equals bundled up Main your L for resource
and then basically we're going to just tell it yeah right here the name as a string.
So our file is called test with extension extension of course is for.
No need for the dot.
It takes care of that for you.
So in order for this to actually oh yeah go ahead and give it some brackets and tab down there.
Now in order for this to actually pull the file we need to create an audio player.
So below your ID outlets go ahead and type bar audio player of type avi audio low D player and we're
not going to instantiate it yet.
So go ahead and do that.
So now we need to basically tell the app how we want it to play the audio and so to do this we need
to be safe and go ahead and type do.
And inside of this bracket we're going to type let sound equals try avi audio player
sometimes you have to wait for the autocorrect.
There it is Avi audio player and we want to pull the contents of the path that we just created straight
to our file.
Now underneath that we need to set up the audio player the one that we created up here.
We want to set that up with our sound.
So this actually sorry needs to be.
Oh no I'm sorry.
That's correct.
So we want our audio player to have a sound.
Now it needs to be cell because we're going inside of a closure here.
And I'll explain more about that in a second.
So self-taught audio player equals sound that we just created here.
Then below that we want to type self audio player.
Sorry I'm getting ahead of myself here.
We want to type sound dot play.
And in order for this to actually work the right way we need to provide a catch block that will catch
errors in case there are any.
This is just something that's mandatory for playing audio and in our catch block we're just going to
print just a generic error.
It's not going to actually be anything useful but it basically satisfies the needs of our stuff here
that we're doing.
All right.
So we have now requested speech authorization.
We have come through once it is authorized and basically giving it a path to find the file.
Now this right here this do block.
This is going to play the audio file but it is not yet analyzing it.
I just thought it would make sense to play the file.
While we're also simultaneously analyzing it.
So let's get on to the analysis now and then in a second.
We're going to basically check to see if the player works and check to see if the analysis works too.
So go ahead and if you remember on that documentation I showed you we need a recognizer a request a
recognition task and then it prints out a result.
And that is the text that we want to fill our UI text for you.
So let's create a recognizer of type f s f speech recognizer.
So many long words go ahead and give us some parentheses there to instantiate a blank one there.
Let's create a request request equals s f speech you RL recognition request and that will basically
understand our u r l that we have laid out for our file here.
Test him for a.
And I'm forgetting something we need to include u r l and of course that is path because we created
it here here.
So down below let's create the next required thing.
It's a part of recognizer.
So let's go recognizer recognition task.
Now it says with s f speech recognition requests and we already have that it's called request and r
s f speech recognition task delegate that is basically going to well let's just go ahead and get rid
of it X because we don't need it.
Sorry we're going to type with code and request and then we're going to create a closure and inside
of that we're going to basically print a result and an error if we need to.
So go ahead and add that.
And then since it's a closure we need to type in to give it a clue that we're starting the closure and
it's giving us an error because it's saying that we were not yet using that result but we'll do that
right now.