0

I'm trying to use Google Speech Recognition inside my application (a launcher). When I try to use it for short commands like Call to X or say a short number like 123456789 everything works fine, but as soon as I try to give a longer input (which requires more time to say) the Speech Recognition Activity Hangs on screen and it doesn't do anything.

I couldn't find anything useful in the Logs and I don't know if I'm making something wrong when initializing the Speech Recognition.

Here's when I initialize it:

var intent = new Intent(RecognizerIntent.ActionRecognizeSpeech);

intent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
StartActivityForResult(intent, SpeechResult);

And here's where I use the result

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);


            if (requestCode == SpeechResult && data != null)
            {

                var text = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);


                getterForNumber = text[0];
                getterForNumber = getterForNumber.Replace(" ", String.Empty);

                bool inInt = getterForNumber.All(char.IsDigit);

                if (!inInt)
                {
                    var activity2 = new Intent(this, typeof(fittizioAct));
                    activity2.PutExtra("fittizioData", "Cannot Recognise the Number");
                    activity2.PutExtra("direzione", "vocale");
                    StartActivity(activity2);
                    Finish();
                }
                else
                {
                    var passNameAndNumberRubr = new Intent(this, typeof(VocalSavedAct));
                    passNameAndNumberRubr.PutExtra("saveNumberRubr", getterForNumber);
                    passNameAndNumberRubr.PutExtra("saveNameRubr", getterForName);

                    //sqldbRubrica.AddRecord(getterForName, getterForNumber);

                    StartActivity(passNameAndNumberRubr);
                    Finish();
                }




            }
            else if (requestCode == SpeechResult && data == null)
            {
                AudioManager vol = (AudioManager)this.GetSystemService(Context.AudioService);
                int volume = vol.GetStreamVolume(Android.Media.Stream.Music);
                CrossTextToSpeech.Current.Speak("Voice Command Canceled",
                pitch: 1,
                speakRate: speed,
                volume: (float)volume,
                crossLocale: locale);
            }
}

P.S. The code is in C# because I'm using Xamarin.

karthik
  • 528
  • 4
  • 19

1 Answers1

1

Try modifying the initent like this

var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
            voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);


            voiceIntent.PutExtra(RecognizerIntent.ExtraPrompt, "Speak now");

            voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500);
            voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500);
            voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000);
            voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1);
            voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default);
Aritra Das
  • 262
  • 3
  • 8