does Android SpeechRecognizer can recognize only English? -
i using following code recognize text. @ first invoke dialog choose language recognition. pass argument recognizerintent. unfortunatly, "en-us" recognized on phone(i tried "fr-fr" , "ru-ru"). there have not done or how can narrow list working languages?
code
public void recognize(view v) { intent detailsintent = new intent( recognizerintent.action_get_language_details); sendorderedbroadcast(detailsintent, null, new languagedetailschecker( context), null, activity.result_ok, null, null); } private class languagedetailschecker extends broadcastreceiver { context contextapp; public languagedetailschecker(context context) { this.contextapp = context; } @override public void onreceive(context context, intent intent) { bundle results = getresultextras(true); arraylist<string> languages = new arraylist<string>(); if (results.containskey(recognizerintent.extra_language_preference)) { languagepreference = results .getstring(recognizerintent.extra_language_preference); } if (results.containskey(recognizerintent.extra_supported_languages)) { languages = results .getstringarraylist(recognizerintent.extra_supported_languages); } supportedlanguages = new string[languages.size()]; supportedlanguages = languages.toarray(supportedlanguages); alertdialog.builder b = new builder(contextapp); (string s : supportedlanguages) { log.d("supported languages", s); } b.settitle("choose language"); b.setitems(supportedlanguages, new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dialog.dismiss(); chooselanguage(which); } }); b.show(); } private void chooselanguage(int i) { int = i; intent intent = new intent(recognizerintent.action_recognize_speech); intent.putextra(recognizerintent.extra_language_model, supportedlanguages[which]); intent.putextra(recognizerintent.extra_language_preference, supportedlanguages[which]); intent.putextra( recognizerintent.extra_only_return_language_preference, supportedlanguages[which]); log.d("languages choosen", supportedlanguages[which]); startactivityforresult(intent, 300); } }
proble cause wrong extras. replace method
private void chooselanguage(int i) { int = i; intent intent = new intent(recognizerintent.action_recognize_speech); intent.putextra(recognizerintent.extra_language_model, supportedlanguages[which]); intent.putextra(recognizerintent.extra_language, supportedlanguages[which]); log.d("languages choosen", supportedlanguages[which]); startactivityforresult(intent, 300); }
Comments
Post a Comment