Android Wear脱机语音识别

时间:2015-07-02 09:01:34

标签: java android offline wear-os voice-recognition

我尝试使用离线语音识别制作Android Wear项目。它在线工作,与手机连接,但我希望磨损设备是独立的。

这是我的在线识别代码:

private static final int SPEECH_RECOGNIZER_REQUEST_CODE = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    startSpeechRecognition();
}

private void startSpeechRecognition() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    startActivityForResult(intent, SPEECH_RECOGNIZER_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SPEECH_RECOGNIZER_REQUEST_CODE) {      
        if (resultCode == RESULT_OK) {
            List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            String recognizedText = results.get(0);
            Log.d("VOICE TEST : ", recognizedText);
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

非常感谢。

1 个答案:

答案 0 :(得分:0)

Android Wear语音识别器需要连接手机和互联网才能工作。所以你想要实现的目标是不可能的。

您可以通过断开手机与佩戴者的连接,然后尝试使用任何“Ok Google”命令来自行测试。它不起作用。