我使用了以下SpeechRecoginzer代码,我想获得语音的置信度得分。
private fun initSpeech() {
mSpeech = SpeechRecognizer.createSpeechRecognizer(activity)
mIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
// mIntent!!.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 20000000);
mIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
mSpeech!!.setRecognitionListener(this)
}
@SuppressLint("SetTextI18n")
override fun onResults(bundle: Bundle) {
val words = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
val scores = bundle.getFloatArray(android.speech.SpeechRecognizer.CONFIDENCE_SCORES)
Log.e("scores", "" + scores!![0])
Log.v("myapp", words!![0])
tvScore.text = (scores[0]*100).toInt().toString()
}
当我们将上述代码与Media Recorder一起使用时,当时SpeechRecognizer类正在获取错误代码5。
任何人都有解决方案,请帮助我。那对我很有帮助。
谢谢!