Git Product home page Git Product logo

kontinuousspeechrecognizer's Introduction

KontinuousSpeechRecognizer

Release Build Status API Android Arsenal GitHub license

Prelude

Speech recognition is designed to listen commands for a brief moment and deactivate on its own. I wanted to mimic the "OK Google" recognition pattern. Use it with care to prevent battery drain.

The recognizer is managed on its own via the KontinuousRecognitionManager and exposes methods such as startRecognition, stopRecognition, cancelRecognition and destroyRecognizer. It is up to you to manage the lifecycle of this manager from your view.

The recognizer will be listening and be respawned all the time once you call startRecognition and until you call stopRecognition. It expects an activation keyword, such as "Ok Google", then once detected will yield the result to the client and stop listening. A sound system will be heard once the activation keyword is detected but you can decide to mute it.

The workflow is explained as follow :

Speech recognition

Getting started

In your AndroidManifest.xml file, add the following line if your manifest merger is disabled :

<uses-permission android:name="android.permission.RECORD_AUDIO" />

If you are developing an application targeting SDK 23, remember to take care of runtime permission.

In your Activity, create the KontinuousRecognitionManager :

companion object {
   /**
    * Put any keyword that will trigger the speech recognition
    */
   private const val ACTIVATION_KEYWORD = "<YOUR_ACTIVATION_KEYWORD>"
}

private val recognitionManager: KontinuousRecognitionManager by lazy {
       KontinuousRecognitionManager(this, activationKeyword = ACTIVATION_KEYWORD, shouldMute = false, callback = this)
   }

override fun onCreate(savedInstanceState: Bundle?) {
   super.onCreate(savedInstanceState)
   setContentView(R.layout.activity_main)

   recognitionManager.createRecognizer()
   
   if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
       ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO), RECORD_AUDIO_REQUEST_CODE)
   }
}

override fun onDestroy() {
   recognitionManager.destroyRecognizer()
   super.onDestroy()
}

override fun onResume() {
   super.onResume()

   if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
       startRecognition()
   }
}

override fun onPause() {
   stopRecognition()
   super.onPause()
}

We also provide an optional RecognitionCallback interface that yields all RecognitionListener callbacks in addition to a few custom ones corresponding to the keyword detection and the speech recognition availability (it is known to be unsupported on a range of devices).

Gradle Dependency

Add this in your root build.gradle file:

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

Then add the following dependency in your project.

dependencies {
    implementation "com.github.StephenVinouze:KontinuousSpeechRecognizer:{latest_version}"
}

Pull requests

I welcome and encourage all pull requests. I might not be able to respond as fast as I would want to but I endeavor to be as responsive as possible.

All PR must:

  1. Be written in Kotlin
  2. Maintain code style
  3. Indicate whether it is a enhancement, bug fix or anything else
  4. Provide a clear description of what your PR brings
  5. Enjoy coding in Kotlin :)

kontinuousspeechrecognizer's People

Contributors

stephenvinouze avatar svinouze avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.