Sunday, January 31, 2010

Android Text-To-Speech(TTS)

Here is a simple example to try out the Text-to-Speech feature in android. It's very simple to just invoke the text to speech engine. Here's the main snippet.

001// success, create the TTS instance
002mTts = new TextToSpeech(this, this);
003
004
005String language = (String) languageSelector.getSelectedItem();
006if (languageSelector.getSelectedItemId() == 0) {
007 mTts.setLanguage(Locale.ENGLISH);
008} else {
009 mTts.setLanguage(localeMap.get(language));
010}
011String text = textToConvert.getText().toString();
013if (text == null) {
014 text = "please select the language and enter any text";
015}
016mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
017



Here's how it looks!!