【问题标题】:How to detect android speech is in offline or online如何检测android语音是离线还是在线
【发布时间】:2021-01-12 09:03:08
【问题描述】:

我关注this question在android上做离线演讲。
我下载了谷歌语音中的语言,它可以离线工作。
问题是我想知道 它当前在离线或在线语音上运行,(就像 Apple 语音转文本一样,有一个 api 可以检查)以在我的应用中正确显示语音流
我想知道有没有办法做到这一点?
这是我的代码:

    val intentSpeech =  Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
    intentSpeech.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US")
    intentSpeech = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
    intentSpeech.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
    intentSpeech.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
    intentSpeech.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            packageName)
    val recognizer = SpeechRecognizer.createSpeechRecognizer(this)
    recognizer.setRecognitionListener(this)

P/s:我可以看到 google 的 Read Along 应用程序在离线或在线模式下都能完美运行。
我正在尝试对 android 语音 api 做同样的事情。有可能吗?

【问题讨论】:

    标签: android kotlin speech-to-text


    【解决方案1】:

    对于离线语音转文本,您可以使用 Google 的默认 STT 模型,但它似乎是不连续的。

    private fun startSpeechToText() {
        val speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this)
        val speechRecognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        speechRecognizerIntent.putExtra(
            RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
        )
        speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
    
        speechRecognizer.setRecognitionListener(object : RecognitionListener {
            override fun onReadyForSpeech(bundle: Bundle?) {}
            override fun onBeginningOfSpeech() {}
            override fun onRmsChanged(v: Float) {}
            override fun onBufferReceived(bytes: ByteArray?) {}
            override fun onEndOfSpeech() {}
            override fun onError(i: Int) {}
    
            override fun onResults(bundle: Bundle) {
                val result = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
                if (result != null) {
                    // result[0] will give the output of speech
                }
            }           
            override fun onPartialResults(bundle: Bundle) {}
            override fun onEvent(i: Int, bundle: Bundle?) {}
        })  
        // starts listening ...
        speechRecognizer.startListening(speechRecognizerIntent)
    

    }

    如果您不想使用 google,因为它需要下载语音转文本的离线模型。

    离线 STT 的另一个选项是 Vosk API,因为它具有用于实时 STT 的英语和其他语言预训练模型。

    https://github.com/alphacep/vosk-android-demo

    参考:https://www.geeksforgeeks.org/offline-speech-to-text-without-any-popup-dialog-in-android/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      相关资源
      最近更新 更多