5

I did try giving time in millisecond to these below given extras

Recognizer Intent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
Recognizer Intent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
Recognizer Intent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS

But doesn't effect the voice listen time! The voice listen time i get now is just 3 second! How do I achieve a Listen time of 10 seconds

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

1

It seems that it only works on ICS below : https://stackoverflow.com/a/17675098/9427932

But you can always customize the google speech by creating your own class and inherit the speechrecognizer, I wrote these code on Xamarin Android, so it will be pretty much similar to android:

public class CustomRecognizer : Java.Lang.Object, IRecognitionListener, TextToSpeech.IOnInitListener
{
private SpeechRecognizer _speech;
private Intent _speechIntent;


public string Words;


public CustomRecognizer(Context _context)
{
    this._context = _context;
    Words = "";
    _speech = SpeechRecognizer.CreateSpeechRecognizer(this._context);
    _speech.SetRecognitionListener(this);
    _speechIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
    _speechIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
    _speechIntent.PutExtra(RecognizerIntent.ActionRecognizeSpeech, RecognizerIntent.ExtraPreferOffline);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000); 
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);
}

void startover()
{
    _speech.Destroy();
    _speech = SpeechRecognizer.CreateSpeechRecognizer(this._context);
    _speech.SetRecognitionListener(this);
    _speechIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
    _speechIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);
StartListening();
}
public void StartListening()
{
    _speech.StartListening(_speechIntent);
}

public void StopListening()
{
    _speech.StopListening();
}

public void OnBeginningOfSpeech()
{

}

public void OnBufferReceived(byte[] buffer)
{
}

public void OnEndOfSpeech()
{

}

public void OnError([GeneratedEnum] SpeechRecognizerError error)
{
    Words = error.ToString();
    startover();
}

public void OnEvent(int eventType, Bundle @params)
{
}

public void OnPartialResults(Bundle partialResults)
{
}

public void OnReadyForSpeech(Bundle @params)
{
}

public void OnResults(Bundle results)
{

    var matches = results.GetStringArrayList(SpeechRecognizer.ResultsRecognition);
    if (matches == null)
        Words = "Null";
    else
        if (matches.Count != 0)
        Words = matches[0];
    else
        Words = "";

    //do anything you want for the result
    }
    startover();
}

public void OnRmsChanged(float rmsdB)
{

}

public void OnInit([GeneratedEnum] OperationResult status)
{
    if (status == OperationResult.Error)
        txtspeech.SetLanguage(Java.Util.Locale.Default);
}}

you can call startover() to immidiately start recording after it ends, so it will seems like a "continuous speech" (10 second in your case)

  • I Implemented this, But the Google Listen Dialog dosen't appear now! As per my research even You tube ,Play Store has this feature it stays active for 8 seconds approx. Is there any other way of implementation? if yes can i get a link of an example – Preetham Ivan D'Souza Apr 18 '18 at 07:37
  • Yes, that's true, the Google Listen Dialog won't appear, you have to customize your own UI when implementing the code, but you can change the functionality and workaround for your case. n.b : almost all speech recognition stop recording when it is on silence (no audio received). – Vincent Elbert Budiman Apr 18 '18 at 08:53
  • Yes,I got it. But is there an specific reason why those extras don't work? the value's that i give are just not considered. i want to make sure that initially when i click on the Mic icon voice recognition dialog pop's up and should wait for 5 seconds without any voice input( voice inactive timeout) i.e Max Wait time for Voice input should be 5sec. How do i achieve this? – Preetham Ivan D'Souza Apr 18 '18 at 09:05
  • Yes, https://stackoverflow.com/a/17675098/9427932. Even on the android developer page : https://developer.android.com/reference/android/speech/RecognizerIntent.html , it said that _Additionally, depending on the recognizer implementation, these values may have no effect_ . And the only workaround i know is just to restart the recording if it's ended while below 10 second. (The UX will have no big difference i think) – Vincent Elbert Budiman Apr 18 '18 at 09:12
  • Yes,May be thats that only solution left! but do you have any idea of how You tube might have implemented it? will Recognition Service be of any use? – Preetham Ivan D'Souza Apr 18 '18 at 09:24
  • I am not sure about Youtube, is it using google recognizer intent or the Google Cloud Speech API? – Vincent Elbert Budiman Apr 18 '18 at 09:33
  • Not sure about that too! Can i get any reference as in how do i implement the above mentioned solution(restart the recording if it's ended while below 10 second)? – Preetham Ivan D'Souza Apr 18 '18 at 10:00
  • Above solution already restart the recording (by calling **startover()** on the end of **"OnResult()"** method. If you want the exact 10 second, you have to also implement your own timer and check whether startover() should be called or not. – Vincent Elbert Budiman Apr 18 '18 at 10:07