Android SpeechRecognizer Vuzix M300

时间:2017-08-01 07:42:42

标签: android speech-recognition vuzix

我有一个Vuzix m300(更新1.2),我正在尝试使用语音控制来运行我的应用程序。我真的找不到任何特定于m300的代码示例(我认为是因为它是新的?)。内置的语音识别器工作正常。但是当我尝试通过android.speech.SpeechRecognizer使用它时,我认为识别不可用......

我已经尝试了一些我在互联网上找到的代码,虽然有些代码可以在m100上运行。没有什么对我有用。

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //grant access to internet
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        //set layout
        setContentView(R.layout.activity_main);    
        boolean b = SpeechRecognizer.isRecognitionAvailable(getApplicationContext());
        final List<ResolveInfo> services = getApplicationContext().getPackageManager().queryIntentServices(
                new Intent(RecognitionService.SERVICE_INTERFACE), 0);
        b = isPackageInstalled(this.getApplicationContext(), "com.google.android.googlequicksearchbox");
    }
    public static boolean isPackageInstalled(@NonNull final Context ctx, @NonNull final String packageName) {
        try {
            ctx.getApplicationContext().getPackageManager().getApplicationInfo(packageName, 0);
            return true;
        } catch (final PackageManager.NameNotFoundException e) {
            return false;
        }

b始终为false且列表服务为空... 因此我认为Vuzix上没有安装SpeechRecongnizer,但有(Vuzix内置?)。 我愿意接受任何建议!

编辑: 我已经安装了谷歌即时应用程序和谷歌应用程序,现在我可以启动SpeechRecognizer。但由于某种原因,应用程序不会对我的声音做出反应。一段时间后,我得到一个SpeechRecognizer ERROR_SPEECH_TIMEOUT。 同样的应用程序在我的Android手机上工作正常,所以我认为它与Vuzix M300有关吗? 我在onCreate中的代码:

speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication().getPackageName());
    speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "de-DE");
    speechRecognizer.setRecognitionListener(prepareRegnitionListener());
    speechRecognizer.startListening(speechRecognizerIntent);

和休息:

private RecognitionListener prepareRegnitionListener() {
    // TODO Auto-generated method stub
    return new RecognitionListener() {

        @Override
        public void onRmsChanged(float rmsdB) {
            //Didn´t use
        }

        @Override
        public void onResults(Bundle results) {
            ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            Log.d(MainActivity,"Completed speech recognition: Result: " + matches);
            String match = matches.get(0);
        }

        @Override
        public void onReadyForSpeech(Bundle params) {
            Log.d(MainActivity, "ReadyforSpeech");
        }

        @Override
        public void onPartialResults(Bundle partialResults) {
            // Nothing

        }

        @Override
        public void onEvent(int eventType, Bundle params) {
            // Nothing

        }

        @Override
        public void onError(int error) {
            switch (error){
                case SpeechRecognizer.ERROR_AUDIO:
                    Log.e(MainActivity,"Failed to recognize speech: Audio recording error.");
                    startListening(1000);
                    break;
                case SpeechRecognizer.ERROR_CLIENT:
                    Log.e(MainActivity,"Failed to recognize speech: Insufficient permissions.");
                    startListening(1000);
                    break;
                case SpeechRecognizer.ERROR_NO_MATCH:

                    Log.d(MainActivity,"Failed to recognize speech: No recognition results matched. Retrying...");
                    startListening(1000);
                    break;
                default:
                    Log.e(MainActivity,"Failed to recognize speech. Unknown error" + error);
                    startListening(1000);

            }


        }

        @Override
        public void onEndOfSpeech() {
            Log.d(MainActivity, "EndofSpeech");
        }

        @Override
        public void onBufferReceived(byte[] buffer) {
            //Didn´t use

        }

        @Override
        public void onBeginningOfSpeech() {
            Log.d(MainActivity, "beginnofSpeech");//Do something when speaking starts
        }
    };
}

调用了onReadyforSpeech方法,但之后没有任何反应,而且错误被抛出。

2 个答案:

答案 0 :(得分:3)

我对vuzix Android版本并不熟悉,但显然它没有您需要的Google软件包。我也有这个问题,我已经通过下载和安装Google App和Google Now App的apks解决了这个问题。

你可以在这里试试:

Google app

Google Now

答案 1 :(得分:1)

要以编程方式访问内置语音识别的Vuzix,首先需要下载并安装M300 SDK。见https://www.vuzix.com/Developer/KnowledgeBase/Detail/43

安装SDK后,Android sdk / add-ons / addon-vuzixm300sdk-vuzix-23 / docs文件夹中有关于如何使用内置语音识别服务的文档。见https://www.vuzix.com/Developer/KnowledgeBase/Detail/45

jar库(com.vuzix.sdk.speechrecognitionservice.jar)位于Android sdk / add-ons / addon-vuzixm300sdk-vuzix-23 / libs文件夹中。