This Application Convert Text into Speech.... Enjoy it.....
Download Code (Click Here....)
Download .apk File For Android(2.2 upto) Mobile (Click Here...)
Show in Bellow Code For TextToSpeech.java
here use TextToSpeech Class for Access the functionality of conversion of text to speech...
setLanguage(Locale.ENGLISH);
method is use for set language like us , uk etc.
Also Call shutdown() method in onDestroy() for release All TextToSpeech Objects.
Show in Bellow .java code
1) First Create One XML file in which one TextView ,one EditText and one Button Show in Bellow Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="88dp"
android:text="Text To Speech"
tools:context=".TextToSpeech" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="62dp"
android:text="TextToSpeech Button" />
</RelativeLayout>
2) TextToSpeech.java
package com.example.texttospeech;
import java.util.Locale;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
// O@K Tech.
public class TextToSpeech extends Activity {
EditText mSpeechText;
Button mSubmit;
android.speech.tts.TextToSpeech ttos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_to_speech);
mSpeechText = (EditText)findViewById(R.id.editText1);
mSubmit = (Button)findViewById(R.id.button1);
mSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
speakEditText();
}
});
ttos = new android.speech.tts.TextToSpeech(this,new OnInitListener() {
@Override
public void onInit(int status) {
if(status == android.speech.tts.TextToSpeech.SUCCESS){
int langSet = ttos.setLanguage(Locale.ENGLISH);
if(langSet == android.speech.tts.TextToSpeech.LANG_NOT_SUPPORTED || langSet == android.speech.tts.TextToSpeech.LANG_MISSING_DATA){
Log.e("TextToSpeech", "Language is Not Support.");
// Below Three Line is Optional so Comment it.
Intent inSp = new Intent();
inSp.setAction(android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(inSp);
}
else{
mSubmit.setEnabled(true);
speakEditText();
}
}
else{
Log.e("TextToSpeech", "TextToSpeech is not Init....");
}
}
});
}
protected void speakEditText() {
String txt = mSpeechText.getText().toString();
ttos.speak(txt, android.speech.tts.TextToSpeech.QUEUE_FLUSH, null);
Toast.makeText(this, "Call SpeakEdit Method", Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroy() {
if(ttos != null){
ttos.stop();
ttos.shutdown();
}
super.onDestroy();
}
}
3) OutPut Show in Bellow image..................
Download Code (Click Here....)
Download .apk File For Android(2.2 upto) Mobile (Click Here...)
Show in Bellow Code For TextToSpeech.java
here use TextToSpeech Class for Access the functionality of conversion of text to speech...
setLanguage(Locale.ENGLISH);
method is use for set language like us , uk etc.
Also Call shutdown() method in onDestroy() for release All TextToSpeech Objects.
Show in Bellow .java code
1) First Create One XML file in which one TextView ,one EditText and one Button Show in Bellow Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="88dp"
android:text="Text To Speech"
tools:context=".TextToSpeech" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="62dp"
android:text="TextToSpeech Button" />
</RelativeLayout>
2) TextToSpeech.java
package com.example.texttospeech;
import java.util.Locale;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
// O@K Tech.
public class TextToSpeech extends Activity {
EditText mSpeechText;
Button mSubmit;
android.speech.tts.TextToSpeech ttos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_to_speech);
mSpeechText = (EditText)findViewById(R.id.editText1);
mSubmit = (Button)findViewById(R.id.button1);
mSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
speakEditText();
}
});
ttos = new android.speech.tts.TextToSpeech(this,new OnInitListener() {
@Override
public void onInit(int status) {
if(status == android.speech.tts.TextToSpeech.SUCCESS){
int langSet = ttos.setLanguage(Locale.ENGLISH);
if(langSet == android.speech.tts.TextToSpeech.LANG_NOT_SUPPORTED || langSet == android.speech.tts.TextToSpeech.LANG_MISSING_DATA){
Log.e("TextToSpeech", "Language is Not Support.");
// Below Three Line is Optional so Comment it.
Intent inSp = new Intent();
inSp.setAction(android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(inSp);
}
else{
mSubmit.setEnabled(true);
speakEditText();
}
}
else{
Log.e("TextToSpeech", "TextToSpeech is not Init....");
}
}
});
}
protected void speakEditText() {
String txt = mSpeechText.getText().toString();
ttos.speak(txt, android.speech.tts.TextToSpeech.QUEUE_FLUSH, null);
Toast.makeText(this, "Call SpeakEdit Method", Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroy() {
if(ttos != null){
ttos.stop();
ttos.shutdown();
}
super.onDestroy();
}
}
3) OutPut Show in Bellow image..................
Comments
Post a Comment