Android Text to Speech

Android has also new  feature (from Android 1.6) called Text to Speech (TTS) which speaks the text in different languages. with the help of this tutorial explains how to work with android text to speech In this tutorial i also explained changing the language type and speed level.
In this tutorial, i want to implement TTS in Android and how we can control some interesting aspects of speech engine.

Text to Speech

Now we will learn text to speech step by step

1. first we have to use the TTS in our app is initialise the engine.

engine = new TextToSpeech(this, this);

2. Implement your main Activity class from TextToSpeech.OnInitListener
This listener is used to inform our app that the engine is ready to be used

public class MainActivity extends Activity implements TextToSpeech.OnInitListener {
@Override
    public void onInit(int status) {
      if (status == TextToSpeech.SUCCESS) {
           Log.d(&Speech&, &Success!&);
           engine.setLanguage(Locale.UK);
        } 
      } 
    }


3.Read the words and speech.
Now our engine is ready to be used, we need simply pass the string we want to read. To this purpose, we use an EditText so that the user can edit his string and when he clicks on the microphone the app start reading. Without detailing too much the code because is trivial we focus our attention when user clicks on the microphone button:

 speechButton.setOnClickListener(new View.OnClickListener() { 
     @Override
     public void onClick(View v) {
        speech();
        }
    });

      private void speech() {
          engine.speak("Your text for speech", TextToSpeech.QUEUE_FLUSH, null, null);
        }

5.Control Text to Speech Engine parameters
We can control on engine to read the sentence. We can modify for example the pitch and the speech rat.

engine.setPitch((float) pitch);
engine.setSpeechRate((float) speed);
engine.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null, null);









1 comments:

thank you sir for providing this video,

please tell me know about can be use hindi TTS....

Reply