Advanced Godot | Using Text To Speech In Godot on Android

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is mitch with findpoint cgi and today we're gonna talk about adding text to speech to godot inside of android so we're gonna go through the process of downloading the plugin we're gonna go ahead and implement that plugin and then we are going to go ahead and have our phone say hello to us now this is really cool because it provides a very cool interaction with the user and it can help bring some accessibility to your application so one of the big struggles that people have who are blind is that they can't interact with a lot of applications because they're blind they can't really see it but having text-to-speech could help with that so that's what i have in store for you guys today so let's go ahead and get started okay so the first thing that we need to do is we need to go ahead and download the godot android text to speech plugin which is created by i bardinov i'm not sure if that's exactly how you say their name but it's created by by this guy and um it's a really cool plugin that makes this really simple for us to do so we're going to come down here to the release section here we're going to go ahead and click on that and then we are going to go ahead and download it now i have a link to this in the description below for you guys so go ahead and pull it from there and we will click on this and download it now you'll see windows already pops up for me with it but i'm going to go back to my downloads and extract it so we'll go ahead and extract this all right so we have ourselves an aar file and a gdap file now if you guys haven't done android plugins before basically the aar file is a compiled library for android to understand how to use the text to speech library and the gdap is the linker almost to how godot understands how to use the aar file and if you guys have any questions let me know i also have a tutorial on how to create these and i'll leave a link in the description below for that now we're going to do is we are going to go ahead and make our godot project here so i'm going to open up godot all right and i'm going to go ahead and do a new project and i'm going to say android android tts tutorial go ahead and create that folder create an edit and i'm going to have to resize this for you guys all right so now that we're inside of godot we need to go ahead and install our android build template what our android build template is going to do is it's going to allow us to compile our android app with additional plugins so to do that we have to go up to project and install android build template so we're going to go ahead and click on that and we are going to go ahead and click install what that's going to do is it's going to uncompress all the android build sources so that way we can build our own android app and actually control the build process manually which allows us a lot of flexibility so what i'm going to do is i'm going to right click on our res file i'm going to go down to open in file manager and that's going to pop up my my project folder location so i'm going to go ahead and go into android and i'm going to go into plugins and you'll see that this folder is currently empty and what we're going to do is we're going to copy our two files here our aar and our gdap file we're just going to go ahead and grab those copy them and paste them right into here all right so now that they're in here we're going to go back to cadeau and you'll see that we have this little android folder here that means that so far we've done everything correct so what we need to do now is we need to go up to project export and then we need to go ahead and add our android export so we will add it under a preset here and go ahead and click and now we need to go ahead and include our plugin into our build and we need to use custom build you can see down here it says hey use custom build must be enabled to be able to use plugins so we need to come up here and say hey i want to use my custom builds so go ahead and click on for that then we'll go ahead and click close so now that we've gotten up to this point we've loaded our plugin we've set up all of our stuff at this point we can go ahead and set up our scene and get into some coding so what we're going to do is we'll go up to 2d scene we will right click add in a child node and we're going to add in two buttons now you don't need to have two buttons to do this you can do this through code but i'm doing this because it's just easier to do it this way for me to show on a tutorial so i'm going to go ahead and duplicate this button and drag it down and we're going to name the first button set language and actually i don't want this the space here so we'll say set language and then we'll go ahead and say say hello all right we'll go ahead and say on the text say hello and we'll say set language let's go ahead and say set language all right so now we've got to go ahead and link these to our script right but we don't have a script yet so we need to build that so let's go ahead and right click on our node 2d and let's go ahead and attach a script and then let's just call this tts manager we'll go ahead and hit enter and you will see that we now have our script here so we need to go ahead and link our buttons to our script so we click on it it executes stuff inside of our script right so we go up to set language we can go over to node and we can go ahead and double click on our button down and go ahead and link it to our node 2d we got to do the same thing with our say hello so we go to node signal and do it with button down there we go and what that's doing is it's connecting those signals so when you press that button it emits a signal and then calls the code that's in this section so now that we have all of our signals created what we need to do is we need to create our text-to-speech plug-in inside of code right so we need to do is we need to get a reference to that plugin so we can say it's var tts and in our ready we can say hey if engine dot has underscore singleton and we need to say what the singleton is now how do we know what the name of the singleton is right we just downloaded it from some guy on the internet we don't know what that singleton name is right well what we can do is we go to our project we can go to export and then we can hover over our plugin here and there is the name of it so you can see it says plugin slash the name of the plugin so in this case it's godot tts we have to make sure that our case is correct because if we do it with lowercase g or lowercase t it's not going to work so we need to make sure that it's perfectly the same so we'll come in here and we'll say godot tts so if the engine has that singleton then we're going to go ahead and say tts is equal to engine.get good.tts and the reason why we have this if statement here is if you run this we'll go ahead and save this we don't want it to throw an error so if i don't have this little bit of code here and we attempt to run this you'll see in our debugger we have a crash right here saying hey we didn't we don't have that singleton and that's a massive problem because the singleton only gets loaded when we are on our android system so that's just something to keep in mind so we'll say hey if engine has singleton so now what we can do is we can go ahead and initialize our tts and i'm going to do that in our set language button down because we're setting our language right so we can say tts dot init init text to speech and we need to go ahead and give it a language so in my case i'm going to say english and then they want a country of origin and in my case i'm going to use us because i am from the united states now this is all well and good but what if i put something like english and i put something like you know papa john's right well that wouldn't work right it would crash out on us because that's not a valid location so what we need to do is we need to make sure that this is available that it actually exists and we're not just trying to initialize something that's broken right so we can do is we can say if tts dot is language available and it's the exact same as as we did here so we'll just go ahead and grab these and put that like that and we can go ahead and tab this in and what this is doing is it's saying hey is this language available if it is then let's go ahead and initialize it if it's not right so we could we could actually come in here and say else print quote language is not available if we wanted to right we could just kind of print out a thing saying hey this this doesn't work um in my case i'm initializing with english us so it's going to work but i'm just saying that you can have that nice little um check there to make sure that it doesn't blow up on you and now the last thing that we need to do is we come into our say hello button and we need to call that text to speech so tts dot text to speech and we're just going to go ahead and say hello and that should be all of the code we need to do to enable text-to-speech inside of godot for android so i'm gonna go ahead and grab my phone and i will be right back okay so now that we have my phone plugged in what we can do is we can now export this out to our phone now in my case i have a little android guy up here in the upper right hand corner next i'm going to stop godot real quick but i have a little android icon up here in the upper right hand corner if you don't have this then you don't have android debugging on and you need to go in to your android settings and enable it and that's different for every phone so you're probably going to need to google it so that way you can go and find it but as soon as you have android debugging on this little android guy will show up and if you don't have this what you can do is you can just go to project export and then export out your project as an apk file and then just manually copy it over and install it if you want to do that route but i'm going to go the shortcut and just go ahead and click on my little google pixel icon here so this is going to build and i will be right back all right so now you can see it on my android device here so if i go ahead and click set language you'll see that nothing's happened but if i click on say hello hope my volume's all the way down let's go ahead and click on say hello hello and you can hear that it now says hello hello so now the question is what if we're talking a lot and we want to make the texas speech engine stop talking right like let's say it's just babbling on about stuff that we don't really need it to say how do we get it to stop well we can actually call a function specifically for that so let's go ahead and do that so we'll come to our node 2d we are going to right click add in a button again and we will go ahead and make this button about the right size and we'll put it right below the previous buttons here we'll go ahead and name this button stop and then we will go ahead and go to our text and call it stop as well then we'll go ahead and go to our node do button down and attach it to our script and for us to get this to stop all we need to do is called tts dot stop and that's all we need to do so if we were to say hello and i wanted to say just a bunch of words here and i go ahead and save this and i make sure that my phone is plugged in because it looks like my android guy disappeared on me and then i click on my little android guy and i go ahead and i load my my language and i click say hello hello i am talking though now this is very long so we'll go ahead and hit stop and you will see that it stops so if i click it again and then i click stop it stops it immediately simple enough now you can come over here and look at the different supported languages and you can see here's all the different supported languages and their codes and their different country of origin so you could type like denmark or belgium you could be dutch or you could do something like english australia or something like that unfortunately you cannot set the um gender or the different type i know you can in the api but the creator of the plugin hasn't implemented that yet however i'm sure that they would implement it if people asked them to um but this will give you a pretty good rent reference of all of the different languages that is supported inside of the plug-in now i'll leave a link to this in the description below so you guys can go through them and find the correct language for you and the correct thing for you so you can mess around with it and play around with it but that is all i have for you guys today so if you like this video go ahead and hit that like button hey you know if you dislike this video go ahead and hit that dislike button because i am here to make content for you guys now this video was a viewer suggestion and as with all of my videos so if you have a suggestion let me know because i'm here to make content for you guys and this is what my channel is all about is making content that you guys want if you have any questions about this video hit me up in the comments below or jump on the discord and we can have a conversation link is in the description below i'll be more than happy to talk to you but that is all i have for you guys today so thank you so much again for watching and i will see you all next time thanks [Music] you
Info
Channel: FinePointCGI
Views: 153
Rating: undefined out of 5
Keywords: godot, godot engine, godot tutorial, godot android, godot game engine, godot android export, godot engine tutorial, advanced godot | getting user location in android, godot 2d, godot to android, export godot to android, godot engine android tutorial, godot how to android, godot compiling for android, godot android brasil, godot export android, godot android tutorial, godot tutorial android, godot location android, godot publish to android, godot android app
Id: -u5w80lD4Aw
Channel Id: undefined
Length: 17min 4sec (1024 seconds)
Published: Mon Dec 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.