This is a very straightforward tutorial 😀
There is little available on the Internet regarding API integrations in small game projects. Indie games are pushing the envelope every day, changing the paradigm of gaming. It’s only a matter of time before your next game project requires some form of data ingress/egress via API.
Take a standard visual novel. They are a dime-a-dozen, however! An interactive short story where the player voices their own intent to progres the game? That is truly unique. Voice input as a mechanic, be it for communication, navigation, interacting with the game world, is a fairly unexplored method of control.
This tutorial hopes to provide you with the steps to get a very basic Speech to Text game set up, using Google’s open APIs.
- Create a new Unity Projet
- Navigate to Github and follow the instructions from this open-source project for Unity Google Streaming Speech-To-Text
- You will need to add a dependency to the Packages/manifest.json in your project — perform this step as instructed in the GitHub repo.
- The Setup steps include the Google Cloud Speech-To-Text Quickstart guide — Follow this guide to generate a Service account private key JSON file.
- Place the file (name it “gcp_credentials.json”) in a folder called Assets/StreamingAssets in order for your speech-to-text package to use.
- Create a GameObject, name it “InputManager”
- Add a new component, named “StreamingRecognizer” (this should be available if all the previous steps have been completed)
- By this point you are ready to test! Make sure you have a microphone that you can pick up audio. Check off the “Enable Debug Logging” mode flag in the StreamingRecognizer component, and play the scene. If you don’t have any errors, you will see debug messages in Unity’s console with what Google believes you’ve said!
- You can add a TestMesh Pro text object to a canvas on screen and view the process in real time! Given a TMP Text object “completedText”, you can show text on screen using the following in InputManager.
Then add the OnInterim and OnFinalResult functions to your StreamingRecognizer, and you are done! Congratulations, you are now capturing voice input that you can use in your game.
What kind of amazing games are you excited to make with this functionality? Let me know in the comments, and happy coding!