Estou fazendo um projeto inicial para testar as funcionalidades da biblioteca de SpeechRecognizer da google para android, porém na hora se subir o App estou tendo problemas, nesse caso ele simplesmente fecha e sem mesmo dar uma mensagem de crash, o erro aparentemente é relacionado a Thread main(essa é uma parte do erro):
02-11 20:59:00.930 16313-16313/? E/propClient: PropClient failed to load
02-11 20:59:01.077 25677-25677/? E/adbd: recv: OPEN 0000000f 00000000 0015:73 68 65 6C 6C 3A 6C 6F 67 63 61 74 20 2D 76 20 6C 6F 6E 67 00
service_to_fd: shell:logcat -v long
02-11 20:59:01.090 16315-16315/? E/propClient: PropClient failed to load
02-11 20:59:08.294 19965-19965/? E/rs$DefaultThreadFactory: ===== Detect pool-thread leak =====
02-11 20:59:08.295 19965-19965/? E/rs$DefaultThreadFactory: dalvik.system.VMStack.getThreadStackTrace(Native Method)
java.lang.Thread.getStackTrace(Thread.java:1536)
MainActivity.kt
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.speech.RecognitionListener
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.support.v4.content.ContextCompat
import android.util.Log
import java.util.*
class MainActivity : AppCompatActivity() {
lateinit var sr: SpeechRecognizer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
checkPermission()
configureSpeechRecognizer()
}
fun configureSpeechRecognizer(){
sr = SpeechRecognizer.createSpeechRecognizer(this)
var mSpeechRecognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
sr.setRecognitionListener(Ouvinte())
}
fun checkPermission(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED){
var intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package: $packageName"))
startActivity(intent)
finish()
}
}
}
class Ouvinte: RecognitionListener{
var TAG = "speechOuvinte"
override fun onReadyForSpeech(p0: Bundle?) {
Log.d(TAG, "onReadyForSpeech")
}
override fun onRmsChanged(p0: Float) {
Log.d(TAG, "onRmsChanged")
}
override fun onBufferReceived(p0: ByteArray?) {
Log.d(TAG, "onBufferReceived")
}
override fun onPartialResults(p0: Bundle?) {
Log.d(TAG, "onPartialResults")
}
override fun onEvent(eventType: Int, p1: Bundle?) {
Log.d(TAG, "onEvent: $eventType")
}
override fun onBeginningOfSpeech() {
Log.d(TAG, "onBeginningOfSpeech")
}
override fun onEndOfSpeech() {
Log.d(TAG, "onEndOfSpeech")
}
override fun onError(error: Int) {
Log.d(TAG, "onError: $error")
}
override fun onResults(result: Bundle?) {
Log.d(TAG, "onReadyForSpeech")
var data = result!!.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
for(i: Int in data.indices){
Log.d(TAG, "dados: $data[i]")
}
}
}
}
O layout da main é bem simples pois no momento não utilizo nenhum componente de tela. Estou aberto a sugestões, até mesmo se quiserem me indicar um tutorial para essa biblioteca que vocês usaram e acreditam que será de grande aprendizado, por favor aproveitar essa pergunta para compartilhar! Obrigado !