Speech to Text Application in Android using Jetpack Compose
Speech to Text is used in most applications such as Google Search for searching any query. For using this feature user simply has to tap on the microphone icon and speak the query he wants to search. The speech of the user will be converted to text. In this article, we will take a look at How we can use speech to text feature within our android application using Jetpack Compose.
Step by Step Implementation
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.
Step 2: Adding dependency for using the custom icons
Navigate to Gradle Scripts > build.gradle and add the below dependency in the dependencies section. We will be using this dependency for using custom icons such as the Microphone icons within our application.
After adding this dependency simply sync your project to install it.
Step 3: Adding color in the Color.kt file
Navigate to the app > java > your app’s package name > ui.theme > Color.kt file and add the below code to it. Comments are added in the code to get to know in detail.
Step 4: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Step 5: Adding permissions in AndroidManifest.xml
Now for using the microphone we have to specify microphone permissions. So for adding these permissions. We have to navigate to app > manifest > AndroidManifest.xml and add the below permissions to it. Comments are added in the code to get to know in detail.
Now run your application to see the output of it.