Text To Speech Android Applications Source Code Free Download

# activity_text_to_speak.xml


<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#31244e"
    tools:context="com.example.texttospeak.TextToSpeak" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="14dp"
        android:layout_y="16dp"
        android:text="Enter Text"
        android:textColor="#FFFFFF"
        android:textSize="20dip" />

    <EditText
        android:id="@+id/txtText"
        android:layout_width="273dp"
        android:layout_height="126dp"
        android:layout_x="18dp"
        android:layout_y="53dp"
        android:ems="10"
        android:hint="Enter Your Text......"
        android:scrollHorizontally="true"
        android:textColor="#FFFFFF"
        android:textSize="25dip" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="43dp"
        android:layout_y="381dp"
        android:text="Vishal and Vivek"
        android:textColor="#008000"
        android:textSize="30dip"
        android:textStyle="italic" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="94dp"
        android:layout_y="330dp"
        android:text="Develop By"
        android:textColor="#008000"
        android:textSize="20dip"
        android:textStyle="italic" />

    <Button
        android:id="@+id/btnspeak"
        android:layout_width="122dp"
        android:layout_height="wrap_content"
        android:layout_x="87dp"
        android:layout_y="241dp"
        android:text="Listen"
        android:textSize="25dip" />

</AbsoluteLayout>


# TextToSpeak.java

 package com.example.texttospeak;

import java.util.Locale;

import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TextToSpeak extends ActionBarActivity implements OnInitListener
{
private int result=0;
private TextToSpeech tts;
private Button btnclick;
private EditText txtText;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_to_speak);

tts=new TextToSpeech(this,this);
btnclick=(Button)findViewById(R.id.btnspeak);
txtText=(EditText)findViewById(R.id.txtText);

btnclick.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View arg0)
{

speakout();

// TODO Auto-generated method stub

}
});
}

public void onDestroy()
{
if(tts!=null)
{
tts.stop();
tts.shutdown();
//tts.shutdown();



}
super.onDestroy();
}

public void onInit(int status)
{
if(status==TextToSpeech.SUCCESS)
{
result=tts.setLanguage(Locale.US);


if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED)
{
Toast.makeText(getApplicationContext(), "Missing Data", Toast.LENGTH_LONG).show();

btnclick.setEnabled(false);

}
else
{
btnclick.setEnabled(true);
}
}
else
{
Log.e("TTS","Missing");


}
}

private void  speakout()
{
String text=txtText.getText().toString();
if(result!=tts.setLanguage(Locale.US))
{
Toast.makeText(getApplicationContext(), "Enter Right Words", Toast.LENGTH_LONG).show();

}
else
{
//Toast.makeText(getApplicationContext(), "Missing Data", Toast.LENGTH_LONG).show();

tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);

}
}
}









Text To Speech Android Applications Source Code Free Download Text To Speech Android Applications Source Code Free Download Reviewed by Unknown on 07:13 Rating: 5

No comments:

Powered by Blogger.