android text to speech 0 supported languages on nexus 7 -
i'm working on little app gives user option "speak" couple of commands app respond.
i've got speech recognition working , commands registered. being recognized , means, answer should played.
only issue is: doesn't.
here's bit of code use determine languages supported google's tts engine (i'm developing older version of android "tts.getavailablelangues()" isn't in there unfortunately):
locale[] locales = locale.getavailablelocales(); list<locale> localelist = new arraylist<locale>(); (locale locale : locales) { int res = speaker.islanguageavailable(locale); if (res == texttospeech.lang_country_available) { log.d(tag, "language: " + locale); localelist.add(locale); } } log.d(tag, "languages available: " + localelist.size());
the output of last log always: "languages available: 0"
and indeed, if run bit of code:
int id = speaker.setlanguage(locale.english); checkid(id);
it'll come "language not supported" error. odd, given i'm trying use 1 of default languages: english (uk, us, doesn't matter, it's "not supported").
so, obviously, when try run
speaker.getlanguage();
it returns null...
even stranger initlistener reports "texttospeech.success"
private oninitlistener listener = new oninitlistener() { @override public void oninit(int status) { if (status == texttospeech.success) { log.d(tag, "tts engine started succesfully"); } else if (status == texttospeech.error) { log.d(tag, "seems error occured :c"); } } };
so log shows: "tts engine started succesfully".
and actual code use run tts:
public void speak(string text, context context, oninitlistener listener) { string tag = "dashboardactivity"; log.d(tag, "speaking started in dummy module"); texttospeech speaker = new texttospeech(context, listener); // int id = speaker.setlanguage(locale.uk); int id = speaker.setlanguage(locale.english); speaker.speak(text, texttospeech.queue_flush, null); }
there doesn't seem wrong code, or missing something?
here's list of things i've tried/checked/installed:
- tts installed
- voice data installed (multiple voices uk , english)
- if press "listen example" button in settings works!
so, i'm sitting there's no reason shouldn't working. question then:
- am missing something? (special permissions? data?)
- why code tts engine supports 0 languages out of 400-something "locales"?
- how can fix this?
ok, fixed it. didn't think time tts engine needs initialize called "speak" right after instantiating it.
i moved oninit listener , presto: works!
here's oninitlistener now:
private oninitlistener listener = new oninitlistener() { @override public void oninit(int status) { if (status == texttospeech.success) { log.d(tag, "tts engine started succesfully"); log.d(tag, "setting language default"); int id = tts.setlanguage(locale.getdefault()); checkid(id); tts.speak(mmessagetospeak, texttospeech.queue_flush, null); } else if (status == texttospeech.error) { log.d(tag, "seems error occured :c"); } } };