All right, so let's implement text to speech to our application, and I hope you tried to implement
that yourself.
So therefore we are going to need a tax object.
So I text to speech, object, text to speech like, so I'm gonna set it to it now, and we need to
make sure the text to speech exists as an import so that we are, it's there.
All right now, we can initialize text to speech, and I'd do that in my on create method.
So let's just set it up here, as is going to be a text to speech object with this as the context and
this as the listener, which then accordingly requires us to add the listener.
So implement the interface with the listener here.
So you see that our class now has to text to speech in IT listener and at the same time, we also added
the member on in it.
OK.
Now accordingly, we will need to have a method that will speak it out, and we already saw how to do
it in the demo.
So I'm just going to use the same approach here.
Speak out will be the method, and it's going to use our text to speech, object and speak it.
And here you could, of course, use an if statement checking of tweets exists or not, and then only
run it if it's not empty.
OK, so the new statement, if you want to be really sure.
All right, now, inside of our on in it, we are going to need to check the status and I'm going to
really just use the same code that we used in the demo because while we have to write everything from
scratch again.
So here we are going to rename the status.
You could have also left the P0, but P0 is not very descriptive.
So we're checking the status and we're checking if it was successful, then we're setting the language
of us.
And if something went wrong with the language data or the language not being supported, then we are
going to lock the error.
And also, if something went wrong with the status and we didn't get success, we also going to say
that there's something going wrong with the initialization for our text to speech.
Also, we have our own destroy method.
So here we definitely should check out teams as well and set it back.
So let's set back the text to speech if it's not now, so we stop it and then we shut it down.
Now, let's go ahead and speak it out.
So where would we speak it out?
And I would say a good point would be when we set up our exercise view.
OK, so once we set up the exercise view here, we can just go ahead and set it up.
So here we're going to just speak out.
The actual lecture wasn't the actual exercise name.
So exercise a list, which is analogous.
We need to enforce on it, and then we get it at the current position.
So current exercise position don't get name and we just pass it because this will be a strength.
So this get name returns a string, which you then can now use to speak it up because our speak out
will take that string and then speak it with text to speech.
Now, you could, of course, also say that you want to relax or added on the on rest set up, so set
up rescue.
You could also say something like rest now you could speak out and please rest for 10 seconds or whatever,
but let's just test it.
Let's see if it's going to be spoken out in our application.
So let's see their hands.
I turned on my speakers, so you will hopefully get it from the speaker.
So now it should come up.
Yeah, the it was jumping jacks.
All right.
So that seems to work.
Perfect.
All right.
So that was it.
I hope you managed to implement it by yourself.
And now you know how to use text to speech?
Oh yeah.
And by the way, one minor thing and we get rid of this exercise here.
One minor thing that we also need to set up in our manifest will be to add queries here.
So queries with the intent of the action and the action name being the task service.
So here, Android intent, thought action.
Thought T as.
Service.
Mike, so let me get rid of this here and close the action.
So this service, this will be necessary for Android 11.
And it works very well with our Android 12 emulator.
But if you really want to make sure that it's going to work well on Android 11 as well, you might have
to add these queries in here.
OK.
And that is pretty much it for this video.