I am trying to organize the speech-to-text commands in a certain order. I have a GridView with some cells. Once you press on the button "start", you must say the word from the first cell, then the word from the second cell etc. Right now, it recognizes any command (from any cell), for example, when you open the app, you can say the word from the 5th cell, and it will be recognized and the cell highlighted, but I am trying to do something so that you must say the words in order, from 1 to 9. That means, I can't say "two", "three", or "four" before "one".
Here is what I've implemented so far in the Main Activity:
private fun onClickMic() {
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
intent.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.US)
startActivityForResult(intent, 10)
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK && data != null) {
when (requestCode) {
10 -> {
val text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
textCommand(text!![0])
}
}
}
}
private fun textCommand(text: String) {
when (text) {
"1" -> dataBeanArrayList[count + 1].isSelected = true
"2" -> dataBeanArrayList[count + 2].isSelected = true
"3" -> dataBeanArrayList[count + 3].isSelected = true
"4" -> dataBeanArrayList[count + 4].isSelected = true
"5" -> dataBeanArrayList[count + 5].isSelected = true
"6" -> dataBeanArrayList[count + 6].isSelected = true
"7" -> dataBeanArrayList[count + 7].isSelected = true
"8" -> dataBeanArrayList[count + 8].isSelected = true
"9" -> finish()
}
cellAdapter!!.notifyDataSetChanged()
}
I tried to find a solution, but I couldn't find anything that helped. Thank you.