Android Change language of speech to text to Japanese not working -
hi i'm making japanese learning app android. 1 of features speak app in japanese check if saying words correctly. got working promptspeechinput
did not ui
getting in way decided go rout , have fragment implement recognitionlistener
. reason japanese not working , shows english words. i'm not sure what's wrong.
here code speech fragment
public class speechfragment extends fragment implements recognitionlistener { private textview textviewinput; private togglebutton buttonspeak; private speechrecognizer speech = null; private intent recognizerintent; public speechfragment() { // required empty public constructor } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view view = inflater.inflate(r.layout.fragment_speech, container, false); speech = speechrecognizer.createspeechrecognizer(this.getcontext()); speech.setrecognitionlistener(this); recognizerintent = new intent(recognizerintent.action_recognize_speech); 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.japanese); recognizerintent.putextra(recognizerintent.extra_max_results, 3); textviewinput = (textview) view.findviewbyid(r.id.textviewinput); buttonspeak = (togglebutton) view.findviewbyid(r.id.buttonspeak); buttonspeak.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { speech.startlistening(recognizerintent); } else { speech.stoplistening(); } } }); return view; } @override public void onresume() { super.onresume(); } @override public void onpause() { super.onpause(); if (speech != null) { speech.destroy(); } } @override public void onbeginningofspeech() { textviewinput.settext("speak"); } @override public void onbufferreceived(byte[] buffer) { } @override public void onendofspeech() { buttonspeak.setchecked(false); } @override public void onerror(int errorcode) { string errormessage = geterrortext(errorcode); textviewinput.settext(errormessage); buttonspeak.setchecked(false); } @override public void onevent(int arg0, bundle arg1) { } @override public void onpartialresults(bundle arg0) { } @override public void onreadyforspeech(bundle arg0) { } @override public void onresults(bundle results) { arraylist<string> matches = results .getstringarraylist(speechrecognizer.results_recognition); string text = ""; (string result : matches) text += result + "\n"; textviewinput.settext(text); } @override public void onrmschanged(float rmsdb) { } public static string geterrortext(int errorcode) { string message; switch (errorcode) { case speechrecognizer.error_audio: message = "audio recording error"; break; case speechrecognizer.error_client: message = "client side error"; break; case speechrecognizer.error_insufficient_permissions: message = "insufficient permissions"; break; case speechrecognizer.error_network: message = "network error"; break; case speechrecognizer.error_network_timeout: message = "network timeout"; break; case speechrecognizer.error_no_match: message = "no match"; break; case speechrecognizer.error_recognizer_busy: message = "recognitionservice busy"; break; case speechrecognizer.error_server: message = "error server"; break; case speechrecognizer.error_speech_timeout: message = "no speech input"; break; default: message = "didn't understand, please try again."; break; } return message; }
}
try 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, locale.japanese); intent.putextra(recognizerintent.extra_max_results, 3); getactivity().startactivityforresult(intent,requestcode);
after override onactivityresult() method in activity file(where called fragment)
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); arraylist<string> words=data.getextras().getstringarraylist(recognizerintent.extra_results); //here can spoken words }
Comments
Post a Comment