没有互联网的Android语音识别

时间:2017-11-01 05:33:13

标签: android voice-recognition voice

我目前正在尝试创建语音转语音应用程序。我的手机将连接到无法连接到互联网的WiFi。我目前正在使用RecognizerIntent,因为WiFi没有互联网连接,所以需要更长的时间。

有没有办法使用立即使用离线语言套餐的RecognizerIntent,而不是先尝试连接到Google服务器?

我对此很陌生,感谢您的帮助!

private void askSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            "Hi speak something");
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {

    }
}

// Receiving speech input

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case REQ_CODE_SPEECH_INPUT: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> result = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                voiceInput.setText(result.get(0));
            }
            break;
        }

    }
} 

0 个答案:

没有答案