I'm trying to build an app by using Google's voice recognition sdk. Below is my code for this project. The problem is, when the user clicks the speaker button (image button that prompts Google Voice Recognizer) and starts to talk, if the user says a bit long, then the "Tap to Speak" stays freeze, meaning the result was not received ( although if I touch phone, it becomes ready to receive user input)
However when I use Google app installed in my Smartphone ( Factory version I think ), it detects my voice really well even if I say a bit long sentence ( having 10-15 words and even more ).
How can I realize this function or Is Google using different engine than Google voice recognizer in Android?
Below is my code!
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,"en-US");
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 200000);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 200000);
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String tem_result = "";
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtSpeechInput.setText(result.get(0));
if (result.get(0).toLowerCase().equals(examples[index]))
{
txtSpeechInput.setText("correct:" + result.get(0).toLowerCase());
index += 1;
txtSpeakThis.setText(examples[index]);
}
else
{
txtSpeechInput.setText("wrong:" + result.get(0).toLowerCase());
}
}
else if ( resultCode == RecognizerIntent.RESULT_CLIENT_ERROR){
Toast.makeText(this,"client error", Toast.LENGTH_LONG).show();
}
else if ( resultCode == RecognizerIntent.RESULT_AUDIO_ERROR){
Toast.makeText(this,"RESULT_AUDIO_ERROR", Toast.LENGTH_LONG).show();
}
else if ( resultCode == RecognizerIntent.RESULT_NETWORK_ERROR){
Toast.makeText(this,"RESULT_NETWORK_ERROR", Toast.LENGTH_LONG).show();
}
else if ( resultCode == RecognizerIntent.RESULT_NO_MATCH){
Toast.makeText(this,"RESULT_NO_MATCH", Toast.LENGTH_LONG).show();
}
else if ( resultCode == RecognizerIntent.RESULT_SERVER_ERROR){
Toast.makeText(this,"RESULT_SERVER_ERROR", Toast.LENGTH_LONG).show();
}
break;
}
}
}