我对android.speech.SpeechRecognizer方法有一些疑问
speechRecognizer.startListening(speechIntent)
有时,播放“就绪”声音要花很长时间(通常是在应用重新运行之后)。我找不到类似onSpeechRecognitionReady的监听器。如何捕获此事件以创建progressBar?
我以此方式初始化识别器
private fun initSpeechRecognizer() {
speechIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US")
speechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this)
speechRecognizer.setRecognitionListener(object : RecognitionListenerAdapter(){
override fun onResults(results: Bundle) {
val matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
tv_speech.text = matches[0]
btn_speech.isChecked = false
}
})
}
答案 0 :(得分:1)
我认为您应该使用具有RecognitionListener方法的onReadyForSpeech,以便可以在init上显示进度条,并在ReadyForSpeech上将其隐藏
答案 1 :(得分:0)
现在,我必须执行此丑陋的操作。它会产生多余的开始聆听和停止聆听声音。
<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">New User Registration</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Username" ng-model="newUser.username">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Email" ng-model="newUser.email">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Full Name" ng-model="newUser.fullName">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="saveUser();">Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="close()">Close</button>
</div>
</div>