Wednesday, 15 January 2014

Text to speech in android


Text to speech converter android

Follow the simple step to create this application:

                  Here, is the coding for converter the text into the speech. Its very useful to read stores by the mobile itself and etc.

1)A TextToSpeech instance can only be used to synthesize text once it has completed its initialization. Implement the TextToSpeech.OnInitListenerto be notified of the completion of the initialization.


@Override

public void onInit(int status) {

if (status == TextToSpeech.SUCCESS) {
Toast.makeText(TtsActivity.this, "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show();
}
else if (status == TextToSpeech.ERROR) {
Toast.makeText(TtsActivity.this, "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
}
}


2)check whether the TextToSpeech Engine available in the current device by startActivityForResult intent.


Intent checkIntent = new Intent();

checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);


3) if the TextToSpeech engine in available create the TextToSpeech instance.

TexttoSpeech tts;

tts=new TexttoSpeech(this,this);

4)if TexttoSpeech engine not available install it,

TexttoSpeech tts;

tts=new TexttoSpeech(this,this);
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);

5)Finally,Enter the text into the edittext field,Then click button to perform the speech action,after click button using tts.speak(); method to speech the text.

tts.speak(text,TexttoSpeech.QUEUE_ADD,null);


Screenshot:





Text to speech android example















No comments: