Continuous speech recognition library for Android with options to use GoogleVoiceIme dialog and offline mode.

Overview

License: MIT

Android Speech Recognition

This library lets you perform continuous voice recognition in your android app with options to either use Google Voice Ime in a Dialog or perform the recognition in-app. It also provides you with an option to enforce ONLY offline speech recognition.

Installation

Gradle

Add the Jitpack repository to your root build.gradle file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency to your app's build.gradle file

dependencies {
	compile 'com.github.maxwellobi:android-speech-recognition:v1.0.0-beta.1'
}

Maven

Add the repository to your pom.xml file

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Add the dependency

<dependency>
    <groupId>com.github.maxwellobi</groupId>
    <artifactId>android-speech-recognition</artifactId>
    <version>v1.0.0-beta.1</version>
</dependency>

Usage

To use SpeechRecognition library, initialize it, set a listener for handling callbacks, then start listening.

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	SpeechRecognition speechRecognition = new SpeechRecognition(this);
	speechRecognition.setSpeechRecognitionPermissionListener(this);
	speechRecognition.setSpeechRecognitionListener(this);

	Button speakButton = findViewById(R.id.button);
    	speakButton.setOnClickListener(new View.OnClickListener(){
	    @Override
	    public void onClick(View view) {
		    speechRecognition.startSpeechRecognition();   
	    }
	});
}

Handling Permissions

By default, SpeechRecognition handles the request to grant RECORD_AUDIO permission internally and provides a callback via OnSpeechRecognitionPermissionListener interface. There is no need to request this permission in your manifest.

@Override
public void onPermissionGranted() {
	//RECORD_AUDIO permission was granted
}
@Override
public void onPermissionDenied() {
	//RECORD_AUDIO permission was denied
}

Note: use SpeechRecognition.handleAudioPermissions(false) to disable this behavior. If this is set but the permission was not granted, SpeechRecognition will throw a SecurityException

Note: Runtime permission request is available from API level 23 (Marshmallow). Lower API levels will request permissions on install, thus no callback will be triggered.

Callbacks/Listeners

To receive the speech recognition result and other event notification, you need to implement the OnSpeechRecognitionListener

@Override
public void OnSpeechRecognitionStarted() {}

@Override
public void OnSpeechRecognitionStopped() {}

@Override
public void OnSpeechRecognitionFinalResult(String s) {
	//triggered when SpeechRecognition is done listening.
	//it returns the translated text from the voice input
}
@Override
public void OnSpeechRecognitionCurrentResult(String s) {
	//this is called multiple times when SpeechRecognition is
	//still listening. It returns each recognized word when the user is still speaking
}
@Override
public void OnSpeechRecognitionError(int i, String s) {}

Note OnSpeechRecognitionCurrentResult will NOT be called if your are using the GoogleVoiceIme dialog.

Options

Method Default Description
setContext(Context) Null Use this to change SpeechRecognition current context
setPreferredLanguage(String) - Not yet implemented
handleAudioPermissions(boolean) true set false to handle audio permissions yourself. If false, then no need to setSpeechRecognitionPermissionListener()
useOnlyOfflineRecognition(boolean) false set true to force android to use its Offline Recognition Engine. By default, android uses either or both online and offline. false is recommended.
isSpeechRecognitionAvailable() - returns true or false whether the device supports speech recognition or not
useGoogleImeRecognition(boolean, String) false whether to use GoogleVoiceIme Dialog or not. If true, set a prompt to display on the dialog or null to use default.
startSpeechRecognition() - start listening for voice input
stopSpeechRecognition() - dispose resources

Errors

See SpeechRecognizer class for error definitions.

License

Copyright (c) 2018 Maxwell Obi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

You might also like...
An android project presenting some transitions you can use between activities

ActivityTransition An android project presenting some transitions you can use between activities #Integration Add the anim folder to your Android proj

Android - Annotate methods to use as listeners for a sensor.
Android - Annotate methods to use as listeners for a sensor.

SensorAnnotations Annotate methods to use as listeners for sensor events. public class MyActivity extends Activity { /** * Perform actions as

It's a cool animation which can use in splash or somewhere else.

What's Particle ? It's a cool animation which can use in splash or anywhere else. Demo Article 手摸手教你用Canvas实现简单粒子动画 Attributes name format description

Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API
Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API

What is Postman? Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API Usage P

FilePicker is a small and fast file selector library that is constantly evolving with the goal of rapid integration, high customization, and configurability~
FilePicker is a small and fast file selector library that is constantly evolving with the goal of rapid integration, high customization, and configurability~

Android File Picker 🛩️ 中文简体 Well, it doesn't have a name like Rocky, Cosmos or Fish. Android File Picker, like its name, is a local file selector fra

Android Country Picker is a Kotlin-first, flexible and powerful Android library that allows to integrate Country Picker with just a few lines.
Android Country Picker is a Kotlin-first, flexible and powerful Android library that allows to integrate Country Picker with just a few lines.

1. Add dependency dependencies { implementation 'com.hbb20:android-country-picker:X.Y.Z' } For latest version, 2. Decide your use-case

Android library. Flexible components for chat UI implementation with flexible possibilities for styling, customizing and data management.  Made by Stfalcon
Android library. Flexible components for chat UI implementation with flexible possibilities for styling, customizing and data management. Made by Stfalcon

ChatKit for Android ChatKit is a library designed to simplify the development of UI for such a trivial task as chat. It has flexible possibilities for

FPSAnimator is very easy animation library for Android TextureView and SurfaceView.
FPSAnimator is very easy animation library for Android TextureView and SurfaceView.

FPSAnimator A simple but powerful Tween / SpriteSheet / ParabolicMotion / animation library for Android TextureView and SurfaceView. Features The cont

Comments
  • Library used for offline recognition

    Library used for offline recognition

    Hey

    I have two more quick questions.

    1. How does this library achieve offline speech recognition?
    2. Does it use google speech api for offline speech recognition?
    opened by ChrisTomAlx 0
  • Not listening continuously

    Not listening continuously

    It stops listening even if my voice drops for a second... Please provide a method to specify the number seconds to keep listening to my voice... Thanks..

    opened by Aman-chatterjee 2
  • add support for different languages

    add support for different languages

    Currently, SpeechRecognition uses a language model based on free-form speech recognition. See here. By specifying EXTRA_LANGUAGE_PREFERENCE we can provide an option to set the preferred language, from a list of device installed languages, to listen and translate on.

    opened by maxwellobi 1
Releases(v1.0.0-beta.1)
Owner
Maxwell Obi
Performance driven entrepreneur, Software Engineer - I code, live, love & drive.
Maxwell Obi
Image-search - An Image search android app with offline support

image-search Image search app built using bing image search API via paging 3. Fe

Suraj Vaishnav 3 Feb 17, 2022
Android library to animate Floating Action Button to Bottom Sheet Dialog and vice-versa

FabulousFilter Show some ❤️ and star the repo to support the project This library is the implementation of filter-concept posted on MaterialUp.com. It

Krupen Ghetiya 2.6k Jan 3, 2023
Android Library to create Lottie animation view dialog easily with a lot of customization

LottieDialog Android Library to create Lottie animation view dialog easily with a lot of customization Why you should use Lottie Dialog You have no li

Amr Hesham 39 Oct 7, 2022
Android Library to create Lottie animation view dialog easily with a lot of customization

Android Library to create Lottie animation view dialog easily with a lot of customization

Amr Hesham 39 Oct 7, 2022
Animated Loader or Animated Progress Dialog android code.

AnimatedLoadingIndicator LoadingIndicator This is a simple but effective animated Loading Indicator which can easily ready to use integrated few lines

Yash Agarwal 95 Nov 15, 2022
Chandrasekar Kuppusamy 799 Nov 14, 2022
Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension.

ViewBinding Delegate Extension Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension. Binding inst

Cuong V. Nguyen 3 Dec 13, 2021
Examples of the use of animations in jetpack compose and view, as well as measurements of perfomance

AndroidAnimationWorld Примеры использования анимаций в jetpack compose и view, а также замеры perfomance для

Lukian Zhukov 7 Oct 22, 2022
Introduction your app to the user , Easy to use and set Items as you want

Introduction App This lib helps to introduce the App-by view page based on Kotlin. Features Easy Set up Items: Title, Describe, Background, Buttons Ap

S.M.Zendehbad 0 May 6, 2022
The lib can make the ActivityOptions animations use in Android api3.1+

ActivityOptionsICS 本项目停止维护 =========== f you are thinking on customizing the animation of Activity transition then probably you would look for Activit

Kale 591 Nov 18, 2022