2

I am try to implement Continues Speech Recognition in my Android Application. I have followed this Link coding. this Continues Speech Recognition worked before two days. But now Speech Recognition not working good it will be taking more time for speech listening. how to resolve this problem. Please guide me. Thanks

Recognition coding:

// starts the service
    protected void startListening() {
        try {
            initSpeech();
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
             if (!intent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE))
            {
                intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                        "com.dummy");
            }
            sr.startListening(intent);
        } catch(Exception ex) {
            Log.d("SpeechRecognitionService", "Bei der Initialisierung des SpeechRecognizers ist ein Fehler aufgetreten");
        }
    }

    // stops the service
    protected void stopListening() {
        if (sr != null) {
            sr.stopListening();
            sr.cancel();
            sr.destroy();
        }
        sr = null;
    }

    protected void initSpeech() {
        if (sr == null) {
            sr = SpeechRecognizer.createSpeechRecognizer(this);
            if (!SpeechRecognizer.isRecognitionAvailable(context)) {
                Toast.makeText(context, "Speech Recognition is not available",
                        Toast.LENGTH_LONG).show();
                finish();
            }
            sr.setRecognitionListener(VoiceRecognitionListener.getInstance());
        }
    }

User starts speaking

public void onBeginningOfSpeech() {
            System.out.println("Starting to listen");
        }

        public void onBufferReceived(byte[] buffer) { }

        // User finished speaking
        public void onEndOfSpeech() {
            System.out.println("Waiting for result...");
        }
Raj
  • 485
  • 9
  • 18
  • Are you getting an error? In that case, what error? – Zoe Jul 04 '16 at 07:42
  • no error.. but speech listening taking more time @ Polarbear – Raj Jul 04 '16 at 07:44
  • taking more time how? – Zoe Jul 04 '16 at 07:44
  • speech listening started. but result we will be coming 3 to 4 minutes.. but before two day result will be came 50 to 60 sec – Raj Jul 04 '16 at 07:47
  • I don't understand the problem – Zoe Jul 04 '16 at 07:48
  • please refer above code @polar onBeginningOfSpeech() will be stared but onEndOfSpeech will be taking 4 to 5 minutes – Raj Jul 04 '16 at 07:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116344/discussion-between-polarbear0106-and-raj). – Zoe Jul 04 '16 at 07:52
  • check this thread too, maybe it can help: http://stackoverflow.com/questions/24909280/integrate-google-voice-recognition-in-android-app – Ispas Claudiu Jul 04 '16 at 07:52
  • 1
    Your problem may be related to one of the bugs linked from the answer http://stackoverflow.com/q/38150312/1256219 – brandall Jul 04 '16 at 20:04
  • @brandall i have tried your workaround solution but still now i am facing this problem. – Raj Jul 05 '16 at 06:28
  • Your implementation will no longer work as Google's recognizer is completely broken. If you don't speak within a short period of the recognition starting, then `onResults()` is never called. `stopSpeech()` is broken, as well as `rms`. For continuous recognition, look at using PocketSphinx – brandall Jul 05 '16 at 06:53
  • @brandall thanks for your reply. hear after i am try to implement PocketSphinx. but i have get some solution for RecognizerIntent.. – Raj Jul 05 '16 at 07:10
  • i have changed this line intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); to intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US"); – Raj Jul 05 '16 at 07:11
  • LANGUAGE_‌​MODEL_WEB_SEARCH response taking 3 to 5min EXTRA_LANGUAGE, "en-US" response 1 to 2 min – Raj Jul 05 '16 at 07:13
  • I think you'll find it depends on ambient noise. The implementation should obviously send the results within seconds, so something is very broken. `EXTRA_LANGUAGE` & `EXTRA_LANGUAGE_MODEL` are different variables. – brandall Jul 05 '16 at 07:15
  • @brandall.. please guide me how to resolve this problem. we are published our app in app store. our app fully based on Speech Recognizer – Raj Jul 05 '16 at 07:22
  • There is no fix I'm afraid, thousands of developers will be in the same situation, including me. All you can do is use a different recognition provider (search Google for java voice recognition) until Google fix it. – brandall Jul 05 '16 at 07:29
  • thanks for your support @ brandall once you are fixed this issues please post. – Raj Jul 05 '16 at 07:33

1 Answers1

3

I found the solution to reducing the time between speaking and receiving the results.

Request PARTIAL RESULTS as these are delivered before the FULL RESULTS.

I used these EXTRAS:-

mRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, Locale.getDefault().getLanguage().trim());
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 100);

mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);

mSongSpeechRecognitionListener = new SongSpeechRecognitionListener(mRippleBackground, mFloatingActionButton);

mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(mSongSpeechRecognitionListener);

Then in partial results

public void onPartialResults(final Bundle partialResults) {
    Log.i(LOG_TAG, "onPartialResults()");

    final List<String> partialResultList = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

for (final String result : partialResultList) {

    if (result.isEmpty()) {
    } else {
        mPartialResults++;
        if (mPartialResults == mPartialResultsMAX) {
            Log.i(LOG_TAG, "onPartialResults() EXECUTE");
            mFloatingActionButton.setEnabled(true);
            mAsyncTask.execute(result);
                break;
            }
        }
    }
}

I set mPartialResultsMAX to 2 as it seemed the first partial result was only ever a single word

When you receive PARTIAL RESULTS you may want to cancel the speech recogniser.

Hector
  • 4,016
  • 21
  • 112
  • 211
  • thanks for your coding. i have update your coding in our application it will be working good.. – Raj Jul 05 '16 at 09:36