Voice to Text | Kotlin | Android Jetpack Compose

Andres Sandoval
3 min readNov 15, 2024

This tutorial demonstrates how to create a Button composable in Jetpack Compose that triggers speech recognition when clicked. The implementation begins by checking for the necessary audio recording permissions. Once permissions are granted, it launches the speech recognition activity.

The provided code example showcases a “Speak” button. Here’s how it works:

  • When tapped, the app verifies if it has audio recording permission.
  • If permission is granted, it opens a speech recognition screen, allowing you to speak.
  • If not, it prompts the user to grant permission.

The recognized speech is processed through the speechRecognizerLauncher callback, where further handling of the recognized input can be implemented. For more details, refer to the GitHub code example.

Android Compose
Demo https://github.com/AndreSand/VoiceToText

Follow the steps below

1. Launcher for Speech Recognition

  • rememberLauncherForActivityResult creates an activity launcher that starts an external activity for a result, in this case, for speech recognition.

--

--

Andres Sandoval
Andres Sandoval

No responses yet