【问题标题】:Android SpeechRecognizer. How to cach the "ready" sound event?Android 语音识别器。如何捕捉“就绪”声音事件?
【发布时间】:2018-11-16 12:23:15
【问题描述】:

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
            }
        })
    }

【问题讨论】:

    标签: android kotlin speech-recognition


    【解决方案1】:

    我认为你应该使用RecognitionListener,它有一个onReadyForSpeech 方法,这样你就可以在init 上显示你的进度条并在ReadyForSpeech 上隐藏它

    【讨论】:

      【解决方案2】:

      现在我必须做这个丑陋的 hack。它会产生多余的开始收听和停止收听的声音。

      override fun onCreate(savedInstanceState: Bundle?) {
          initSpeechRecognizer()            
          speechRecognizer.startListening(speechIntent)
          speechRecognizer.stopListening()
      }
      

      【讨论】:

        猜你喜欢
        • 2012-08-10
        • 1970-01-01
        • 1970-01-01
        • 2020-04-26
        • 2011-05-05
        • 1970-01-01
        • 2019-09-10
        • 1970-01-01
        • 2016-09-26
        相关资源
        最近更新 更多