Android Voice - Speech Recognition ( Android + Arduino )
by RakaAmburo in Teachers > Pre-K
126 Views, 3 Favorites, 0 Comments
Android Voice - Speech Recognition ( Android + Arduino )
Welcome again to this new auto-mate tutorial. Many years ago when I was a child I saw a documentary of a girl investigating voice control technology. I remember getting so mesmerized by that idea. Controlling the world that surrounds us with the voice. In my infant mind, it was something very close to sourcery. And I think nowadays still is, kind of.
Arthur C. Clarke Any sufficiently advanced technology is indistinguishable from magic.
Now all we know is that is possible and every day is improving. In this tutorial, the first, of the voice series, we will explore how to harvest the power of your Android device to control absolutely everything. Am going to show you how to implement a very simple app that can capture your voice and translate it into text. Based on that text result we will trigger an action in a remote device, so let's get started.
Supplies
For this tutorial, we will need almost the same as the previous one. The computer, the phone, the android studio installed and of course review the supplies of our previous tutorials. No more logins series!
Android app from scratch! and Download from git an Android app and install!
Diagram
A simple diagram showing the different components.
Download Repository From Git
You may go to this GitHub URL and download the code we will work with. Beare in mind you can download de repository and then switch to UnlockVoiceAndUdp branch.
Main Class
Now once you download the code from GitHub you will see basically that it has a MainActivity class. This class is the core of the application and it handles all the necessary configurations to:
- Activate the mobile microphone.
- Listen to your voice until you stop speaking.
- And then process that speech and put it into words.
Lets Go a Little Bit Deeper
Let's see a little bit of the code in detail. As you can see the class is a little bit large, which is not a good practice, but in this case, for the sake of having a simple example, we will bypass that principle. So let's go briefly through all methods.
onCreate()
Here we will be setting the basic configurations for the elements in place in the app like the progress bar, the tile, and the capturing voice button.
onResume() and onPause()
Will be setting the behavior on these two events of the application life cycle.
createSpeech() and askForPermission()
Will be in charge of preparing all the settings required by the voice recognition system of the Android device like the language and granting access to the device resources.
onBeginningOfSpeech() and onEndOfSpeech()
Will be setting the flags that are required for the behavior of the progress bar changing and showing the progress of the operation.
onError()
Will be handling possible errors
onResults()
Will be handling the positive result by showing mainly the result.
Adding UPD
Now that we have achieved this important task that transforms sound into words. We can move forward into our next objective, to trigger some action based on those words. Now to do that we will join the path of this tutorial with the noMoreLogin series No more logins series! and take benefit of the Android code we wrote to send UPD signals to our local network. So basically we will send a UDP signal to unlock our computer once a correct voice instruction is received. you will find the updated code in the GitHub URL. let's get into it:
New Methods
As you can see we will be adding the sendBroadcast and getBroadcastAddress methods. And add a few lines in onResults methods that will be checking the result text. If the text matches what we expect. we will be sending the signal. To summarize what we explained in UDP tutorial, getBroadcastAddress will be getting the local network address and sendBroadcast will be preparing and sending the message coming as a parameter.
Compile, Send, Install and Run
Finally, we can compile and send the file to our phone/tablet install the app and run it.
Beautiful!
What Is Coming Next
Now even though this is an incredible achievement. Notice that this can be an incredible breakthrough for new ideas since we can connect and trigger many actions and by adding a more powerful coding strategy we can enhance and improve the capacity of controlling many things. So in the next tutorials, we will be going through that path.
Hope you have enjoyed this work of mine.
See you in the next one and have a good one.