How to Build a Simple Voice Typer App in Android using Java?
- Android App Development Fundamentals for Beginners
- Guide to Install and Set up Android Studio
- How to Create/Start a New Project in Android Studio?
- Running your first Android app
- Spinner in Android
- RecognizerIntent in Android
In this article, we are going to build a simple Voice Typer app in Android using Java. This is a glimpse of the application we are going to build. The application contains a single Activity with two TextViews, one Spinner to choose language, an EditText to display the message, and two clickable ImageViews one to give voice input and the other to copy the message to the clipboard. We are going to use RecognizerIntent class to get voice input from users. A sample video is given below to get an idea about what we are going to do in this article.
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Adding Vector Assets
Let’s add the necessary vector assets and drawable resource files. Go to app > res > drawable and add the following XML files.
ic_mic.xml (Mic Icon)
ic_copy.xml (Clipboard Icon)
et_bg.xml (Custom Background for EditText)
Here is a screenshot for reference.
Step 3: Working with the activity_main.xml file
We have added the necessary resource files for the application we are building. Now, Let’s design the UI for our application. Add this layout resource file to app > res > layout. Below is the code for the activity_main.xml file.
Step 4: Working with the MainActivity.java file
Now it’s time to initialize everything in MainActivity and implement Spinner and RecognizerIntent. Here is the complete code for MainActivity. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
That’s it. Now we can run the application. Make sure that your project contains all the following files.
Here is the preview of the final application.