Talking Clock And Text To Seach Converter
Designing Part:
Layout file: Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg23"><TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<AnalogClock
android:id="@+id/myAnalogClock"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I can speech"/>
<TextView
android:id="@+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView1"
android:text="Enter The Text For Speech:"/>
<EditText android:layout_width="match_parent"
android:id="@+id/txtspeek"
android:hint="Enterr Text Here"
android:hint="Enterr Text Here"
android:layout_height="109dp"/>
<Button android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Speek"
android:textSize="20dip"
android:textStyle="bold"
android:id="@+id/speek"/>
</LinearLayout>
TalkingClockActivity.java.java as shown in below:
package com.murali.speechtime;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class TalkingClockActivity extends Activity implements OnInitListener {
TextToSpeech myTTS;
AnalogClock MyAnalogClock;
TextView MyText;
Button Speek;
EditText TextSpeech;
private int mHour, mMinute;
AnalogClock MyAnalogClock;
TextView MyText;
Button Speek;
EditText TextSpeech;
private int mHour, mMinute;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myTTS = new TextToSpeech(this, this);
MyAnalogClock = (AnalogClock)findViewById(R.id.myAnalogClock);
MyAnalogClock.setOnClickListener(MyAnalogClockOnClickListener);
MyText = (TextView)findViewById(R.id.myText);
TextSpeech=(EditText) findViewById(R.id.txtspeek);
Speek=(Button) findViewById(R.id.speek);
Speek.setOnClickListener(new OnClickListener() {
MyAnalogClock = (AnalogClock)findViewById(R.id.myAnalogClock);
MyAnalogClock.setOnClickListener(MyAnalogClockOnClickListener);
MyText = (TextView)findViewById(R.id.myText);
TextSpeech=(EditText) findViewById(R.id.txtspeek);
Speek=(Button) findViewById(R.id.speek);
Speek.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
public void onClick(View v) {
// TODO Auto-generated method stub
String speech=TextSpeech.getText().toString();
myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
}
@Override
protected void onDestroy() {
super.onDestroy();
myTTS.shutdown();
myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
}
@Override
protected void onDestroy() {
super.onDestroy();
myTTS.shutdown();
}
private AnalogClock.OnClickListener MyAnalogClockOnClickListener = new AnalogClock.OnClickListener(){
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
String myTime= "Now is "
+ String.valueOf(mHour)
+ " Hour "
+String.valueOf(mMinute)
+ " Minute";
+ String.valueOf(mHour)
+ " Hour "
+String.valueOf(mMinute)
+ " Minute";
MyText.setText(myTime);
myTTS.speak(myTime, TextToSpeech.QUEUE_FLUSH, null);
}
};
}
myTTS.speak(myTime, TextToSpeech.QUEUE_FLUSH, null);
}
};
}
We click on Analog Clock It tell Current Time.
Comments
Post a Comment