HowTo Use Voice Control / Commands in your Unity3D Game

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it what's up Jason here from unity3d college in this video I'm going to show you how you can use a simple script to add voice controls to your game first I'll demonstrate and then I'll jump into the code and show you how it's done turn right fire turn left turn left fire cool so as you can see it works pretty well doesn't always catch everything I say but that time it worked out great now let me jump in and show you what we need to do the first thing you need is to go into the build settings so or her plater setting so there are build settings and just hit player and then over here on the windows tab you need to make sure that the microphone capability is enabled this will allow it to listen in and actually take the commands and I do have this in PC mode so we don't have to switch over to universal windows now the code is pretty simple let me open it up and let's take a quick look up here at the top so I've got a couple of serialized fields here this is just for the Cannonball so that I can spawn a cannonball and shoot it off it's just a sphere with a rigidbody and then I have another serialize field for the point where I want to launch the Cannonball from and this is just a child inside the right here it's just a child of the cannon I just like to use this as a simple way to determine where the Cannonball is going to fire from there it is it's just if I turn it on the renderer you can see where it's at let's jump back over to the code again and see how the actual voice recognition works so we have a dictionary here of string and action and this is gonna align our keywords to different methods that we'll call and then we have a keyword recognizer this is the component that's doing all of the heavy lifting so in our start we're calling we're adding a couple entries to our dictionary so we have a fire one turn right and turn left in each of these like I said just links to an action which is just a method in here so fire instantiates a cannonball at the fire point add some force in the forward direction and writes out boom to the log turn right and turn left just call transform rotate turn it left or right and then once we have these set up we have these the dictionary ready we instantiate the new keyword recognizer and we need to pass in all of the actions as an array of strings so we pass in all of these keywords as an array and then we register for the on phrase recognized event and then when we get a phrase that's recognized it just calls this this method right here we log out the keyword just so we can see what it is and then we just call invoke on whatever action is in this dictionary so this is just a nice simple way of setting up a bunch of different keywords and not having any switch statements or if statements we just invoke the action for the keyword the only other thing that you need is to make sure that you call keyword recognizer start when you're done setting it up and then it'll all just work you can launch your cannonballs turn things or use this for any other kind of game so I hope this helps if you have questions feel free to leave a comment below or hit me up on unity3d college thanks for watching don't forget to Like and hit subscribe
Info
Channel: Jason Weimann
Views: 31,535
Rating: undefined out of 5
Keywords: Unity3D, Unity Voice Control, Unity Voice Commands, Unity3D Voice, Unity3D Voice Control, Unity3D Voice Commands
Id: Xau3hFEcn0U
Channel Id: undefined
Length: 3min 18sec (198 seconds)
Published: Fri Sep 08 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.