<uses-permission android:name="android.permission.RECORD_AUDIO"/>
add the classes :
LangAdapter
STTUtilKt
in the main activity :
add global var :
var sttUtilKt:STTUtilKt?=null
in the onCreat method add :
sttUtilKt = STTUtilKt(this,this)
askPermission()
add this functions to the main activity :
to use :
runSpeechRecognition() //run speech recog.
sttUtilKt!!.getSttIn() // get speech recog results
add the classes :
LangAdapter
STTUtilKt
in the main activity :
add global var :
var sttUtilKt:STTUtilKt?=null
in the onCreat method add :
sttUtilKt = STTUtilKt(this,this)
askPermission()
add this functions to the main activity :
Code:
//region STT speech to text
private fun runSpeechRecognition() {
//handle the speech recognition intent
val intent = sttUtilKt!!.runSpeechRecognition()
if (sttUtilKt!!.hasAudioPermission)
{
try
{
startActivityForResult(intent, sttUtilKt!!.RECOGNITION_RESULT)
}
catch (e: ActivityNotFoundException) {
Toast.makeText(this.applicationContext, "ERROR", Toast.LENGTH_SHORT).show()
}
catch (e:Exception) {
Log.e("WTF", "runSpeechRecognition: " + e.message)
}
}
}
protected override fun onActivityResult(requestCode:Int, resultCode:Int, data:Intent?) {
super.onActivityResult(requestCode, resultCode, data)
sttUtilKt!!.onActivityResult(requestCode,resultCode,data)
}
override fun onRequestPermissionsResult(requestCode:Int, @NonNull permissions:Array<String>, @NonNull grantResults:IntArray) {
//GPS beefup
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
sttUtilKt!!.onRequestPermissionsResult(requestCode,permissions,grantResults)
}
private fun askPermission() {
//create a list of permissions
sttUtilKt!!.askPermission()
}
//endregion
to use :
runSpeechRecognition() //run speech recog.
sttUtilKt!!.getSttIn() // get speech recog results