Created
May 12, 2020 16:28
-
-
Save StephenVinouze/0eca1e522246e3d4c4a5c39343b18c58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var isActivated: Boolean = false | |
private val activationKeyword: String = "<YOUR_KEYWORD>" | |
override fun onResults(results: Bundle) { | |
val matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION) | |
val scores = results.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES) | |
if (matches != null) { | |
if (isActivated) { | |
isActivated = false | |
stopRecognition() | |
} else { | |
matches.firstOrNull { it.contains(other = activationKeyword, ignoreCase = true) } | |
?.let { | |
isActivated = true | |
} | |
startRecognition() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment