0

I habe a problem wit my Android App. My device is a Vuzix M300 and I am trying to get voice control to work. My problem is that when I initialize my SpeechRecognizer and call the startListining method, everything runs, expect that no speech is recognized. I have tried the same code on an Android phone it worked like fine.

Here is my Code:

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

    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
    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");
    speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, false);

    speechRecognizer.setRecognitionListener(prepareRegnitionListener());
    speechRecognizer.startListening(speechRecognizerIntent);
    //startListening(0);
}

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
            ArrayList<String> matches = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            Log.d(MainActivity,"Completed speech recognition: Result: " + matches);
        }

        @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
        }
    };
}

private void startListening(int delay){
    if(delay > 0){
        Timer t = new Timer();
        t.schedule(new TimerTask(){

                       @Override
                       public void run() {
                           mainHandler.post(new Runnable() {

                               @Override
                               public void run() {
                                   speechRecognizer.startListening(speechRecognizerIntent);
                                   Log.d(MainActivity,"Start delayed listening to speech");
                                   speechRecognizer.stopListening();
                               }
                           });

                       }}
                , delay);
    }else{
        speechRecognizer.startListening(speechRecognizerIntent);
        Log.d(MainActivity,"Start instant listening to speech.");
    }


}

I am running the Vuzix with Android 6 and the Vuzix firmware 1.2 (latest Version).

I get the error code ERROR_SPEECH_TIMEOUT like i would get, if no speech input is given (but I give).

I have already tried several things like using the startActivityForResult method to get the voice control running (with the same results...)

manderda
  • 80
  • 1
  • 8
  • Try DroidSpeech, this takes care of all the heavy lifting and it is very easy to implement - https://github.com/vikramezhil/DroidSpeech – Vikram Ezhil Aug 25 '17 at 11:57

1 Answers1

0

You have to set the permissions for your app and for the Google APKs manually, after this it worked for me with the Google Speech Recognizer in my App.

Headman
  • 1
  • 2