voice overlay android

voice overlay android
Voice Overlay for Android
Platform Android
License: MIT
Android Arsenal

Overview

Voice overlay helps you turn your user’s voice into text, providing a polished UX while handling for you the necessary permission.

Demo

You can clone this repo, then run the Demo project by doing ./gradlew app:installDebug and launching the application:

Installation

The Voice overlay is available as a gradle dependency via JCenter. To install it, add the following line to your app’s build.gradle:

Usage

Basic usage

  1. In your Activity, check if you have the permission and show the appropriate Dialog:

See it implemented in the demo app.

This will display the permission dialog if the RECORD_AUDIO permission was not yet granted, then the voice input dialog once the permission is granted.

Once the user speaks, you will get their input back by implementing VoiceSpeechRecognizer.ResultsListener:

See it implemented in the demo app.

When the permission is not granted

If the user didn’t accept the permission, you should explain the permission’s rationale. If they deny the permission, you need to guide them into manually enabling it if they want to use the voice-input feature.

Voice overlay makes it easy to handle all these cases:

See it implemented in the demo app.

This will display the permission rationale when the user doesn’t allow it, and the manual instructions in case they denied it.

Customization

You can customize your voice overlay in the following ways:

Behavior

Several options let you adapt the voice overlay’s behavior to your needs.

Suggestions

You can provide suggestions of what the user could say, to give them some examples.

AutoStart

You can prevent the overlay from automatically listening to user input.

Copy text

You can change any text displayed in the overlay by overriding its resource in your strings.xml:

Layouts

You can replace the voice overlay’s layouts by your own, as long as they respect the following structure:

Permission

Create a layout called voice_input.xml with

  • ViewGroup container with id @+id/voicePermission
  • View with id @+id/close for closing the overlay when clicked
  • TextView with id @+id/title
  • TextView with id @+id/subtitle

Input

Create a layout called voice_permission.xml with

  • ViewGroup container with id @+id/voiceInput
  • VoiceMicrophone with id @+id/microphone to handle the voice input
  • TextView with id @+id/suggestions to display eventual suggestions
  • View with id @+id/close for closing the overlay when clicked
  • TextView with id @+id/title
  • TextView with id @+id/subtitle
  • An eventual TextView with id @+id/hint to display a hint on error
  • An eventual RippleView with id @+id/ripple if you want to keep the animation

177 total views, 2 views today

(Visited 37 times, 1 visits today)

You May Also Like

About the Author: Android Developer

This is Mohammad I am Android Application Developer. I am the founder of Android Tutorial Online blog. I am programming lover and professional blogger from India. I spend most of my time doing programming and helping other programmers. This Android tutorial online blog for learning and share Android code.
My Chatbot
Powered by Replace Me