DreamsCoder.com

We Code your Dreams


home > Simple Text-to-Speech Android App




Simple Text-to-Speech Android App









package com.example.basic;
import java.util.Locale;
import android.os.Bundle;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	EditText e;
	Button b;
	String nam;
	TextToSpeech ttobj;
	

	@Override
	protected void onCreate(Bundle s) {
	super.onCreate(s);
	setContentView(R.layout.activity_main);
		
	e = (EditText)findViewById
(R.id.editText1);
findViewById(R.id.editText2);
    
    b = (Button)findViewById(R.id.button1);

        
        /* Creating Object of textToSpeech*/
        ttobj=new TextToSpeech
(getApplicationContext(), 			      new TextToSpeech.OnInitListener() 
{
	  @Override
	public void onInit(int status) 
        {
        if(status != TextToSpeech.ERROR)
         {
			                             ttobj.setLanguage(Locale.UK);

          }				
    }

		
});//TextToSpeech
        
        /*Button Listener*/
        b.setOnClickListener(new View.OnClickListener()
        {
        
        @Override
     public void onClick(View v)
     {
       	 nam = e.getText().toString();	
    	 speakText(); //call to method SpeechToText()
    	 
    
     }//onClick

        }); //onClickListener
    		}//onCreate Bundle

	 public void speakText(){
	   
	      Toast.makeText(getApplicationContext(),
nam, Toast.LENGTH_SHORT).show();
	      
	      ttobj.speak(nam,
TextToSpeech.QUEUE_FLUSH, null);
	      
	   }//onspeakText

}//classs

Label - android





by - Chinmay Mahajan





Are you looking for something else?


Suggested Programs




Working with SQlite Database in Android


How to check values inserted in SqliteDatabase


How to retrieve values from SQlite Database


Simple Android program to insert values into Database


Error while Creating New Android Project in Eclipse