Steps for setting up.
1. create TextVoice.java class file in src folder in eclipse and copy bellow content
2. create textvoice.xml file in layout folder in eclipse and paste bellow content given for textvoice.xml file.
its just a class file in src folder in eclipse (if you use eclipse for code).
- package com.yadav.ruepshmusicrecorder;
- import java.util.Locale;
- import android.app.Activity;
- import android.os.Bundle;
- import android.speech.tts.TextToSpeech;
- import android.view.MenuItem.OnMenuItemClickListener;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- public class TextVoice extends Activity implements OnClickListener,
- OnMenuItemClickListener {
- TextToSpeech tts;
- EditText e;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.textvoice);
- e = (EditText) findViewById(R.id.etinput);
- Button b = (Button) findViewById(R.id.bTextToVoice);
- b.setOnClickListener(this);
- tts = new TextToSpeech(TextVoice.this,
- new TextToSpeech.OnInitListener() {
- @Override
- public void onInit(int status) {
- // TODO Auto-generated method stub
- if (status != TextToSpeech.ERROR) {
- tts.setLanguage(Locale.US);
- }
- }
- });
- }
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String toSpeak = e.getText().toString();
- tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
- }
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- protected void onPause() {
- // TODO Auto-generated method stub
- if (tts != null) {
- tts.stop();
- tts.shutdown();
- super.onPause();
- }
- }
- }
2. textvoice.xml file content:
it should be in layout folder
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Enter Text Below"
- android:textSize="30sp" />
- <EditText
- android:id="@+id/etinput"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="10sp"
- android:ems="10" >
- <requestFocus />
- </EditText>
- <Button
- android:id="@+id/bTextToVoice"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="10sp"
- android:text="Text to voice" />
- </LinearLayout>
3. AndroidMenifest file content
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.yadav.ruepshmusicrecorder"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="10" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".TextVoice"
- android:label="@string/app_name" >
- </activity>
- </application>
- </manifest>
Thats it u r done...............;
just build the project and press crtl+f11;
i assume that u know how to create and setup android application project;
enjoy...;
just build the project and press crtl+f11;
i assume that u know how to create and setup android application project;
enjoy...;
hey roops
ReplyDeleteweldone...keep it up...:)
thnks.....
DeleteThanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post. Joe Biden Speech transcripts
ReplyDelete