Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

android - SpeechRecognizer with Google Search version 3.6.14.1337016 can't recognize other voice language except default

You can set many voice languages on the setting of latest Google search. But the problem is that SpeechRecognizer can recognize only the default language.

I implemented...

private SpeechRecognizer mGoogleRecognizer; 

private void startRecognition() {
    mGoogleRecognizer = SpeechRecognizer.createSpeechRecognizer(m_context);
    mGoogleRecognizer.setRecognitionListener(this);
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ko-KR");
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Intellectual Personal Assistant");
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, m_context.getPackageName());
    mGoogleRecognizer.startListening(intent);
}

@Override
public void onResults(Bundle results) {
    ArrayList<String> resultList = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
}

I request the recognition about Korean but the resultList includes only results of default language.

How can I get right result?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Even though this is not documented anywhere, I've been able to find out that, with the introduction of multilanguage support in its last update, Google Search is now taking a new extra in RecognizerIntent called "android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES". As suggested by its name, it is a string array that would be used to specify other languages in addition to the main one, which would still be given by RecognizerIntent.EXTRA_LANGUAGE. The problem is that Google Search ignores RecognizerIntent.EXTRA_LANGUAGE if this new extra is not given along with it. This means that adding the following line to your code is enough to solve the problem:

intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{});

But please note that, even though this works, it doesn't change the fact that there is a bug in Google Search. As I've said before, this new extra is not documented anywhere, and Google Search is not following the specification of Android's speech recognition API. As the developer of both Google Search and Android, Google should therefore either:

  1. Change the specification of the speech recognition API in Android, but this would break backward compatibility.

  2. Update the Google Search app so that it correctly follows the current specification.

The second option is obviously the most logical one, and we should therefore let Google know about the bug so that they fix it. It looks like the official Google Search Help Forum is the right place to do this, but so far nobody from Google has paid attention to the thread I created there for it (https://productforums.google.com/forum/#!topic/websearch/PUjEPmdSzSE/discussion). So if you have had this issue please post your complains there to grab Google's attention, and let's see if we get an official answer this way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...