English To Hindi
Creating a Simple Phrases Translator for English to Hindi Convertion.
In the below tutorial, we’re going to build an application which will play 8 different phrases. The phrases are daily use terms and sentences in English language, translated to Hindi language(audio) on tapping the respective phrase.
- This tutorial assumes, you have a basic working knowledge of android studio and the framework in place.
- Have audio files or be able to create using tools such as audacity
First, launch the Android Studio and open a new project with an empty activity. Once the gradle build finishes, continue with setting up the layout of the application.
An empty project by default has a TextView set up within a Constraint Layout. So, go ahead and delete the Text View and pull in a grid view on top of the existing constraint layout. For the grid, add the rowCount and columnCount attributes of layout, as 4 and 2 respectively.
These counts can be anything you want. We are using a 4X2 layout, as we want our application to have 8 buttons, which will play 8 different phrases.
Now for each of the grid cell, add a Button. One for each cell of the grid. So, go ahead and start placing Buttons for each of the cells.
onClick function to each of the buttons
For our application we are using 8 prompts:
- How are you?
- Please meet me sometime.
- Shall we meet tomorrow?
- Where are we?
- What are we doing?
- What time is it?
- Yesterday, Today, Tomorrow
For playing these prompts, we are going to place the audio files for the phrases in
res/raw folder of the app.
And the audio files should be named, same as the tag values for buttons. You can select different names as well, but that will complicate the process unnecessarily.
Add these tags to each one of the buttons places created in the grid at Step 2.
Now let us add the
playPhrase method to
The function takes in
View as a parameter. We declare a Button variable,
buttonPressed to capture the tag value from the variable.
Then we declare a MediaPlayer variable,
mediaPlayer and then we call
create() method of MediaPlayer class on the
We then pass, context and the resource to be played, as parameters to the method.
After this configuration is completed, we just need to call
start() method on
mediaPlayer. And we are good to go.
This completes the application as we wanted it to work and we are now good to go for packaging the program into an “.apk” file.
The application looks like below on Nexus 5X.
Keep coding! Have fun.
The full code of the application is available at GitHub: Github/The-Cyberian