2012年8月17日 星期五
TextToSpeech
public final class Cq_TextToSpeechActivity extends Activity implements OnInitListener,OnClickListener, android.view.View.OnClickListener{
/** Called when the activity is first created. */
private TextToSpeech tts;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tts = new TextToSpeech(getApplicationContext(), this);
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(this);
}
//關閉
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
tts.shutdown();
}
//開始
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS){
tts.speak("I'm ready!", TextToSpeech.QUEUE_FLUSH, null);
}else{
System.out.println("Oops!");
}
}
//處理TextToSpeech
public void onClick(final View v) {
// TODO Auto-generated method stub
TextView TextView01 = (TextView)findViewById(R.id.editText1);
tts.speak(TextView01.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
TextView TextView01 = (TextView)findViewById(R.id.editText1);
tts.speak(TextView01.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
}
*******************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Talk" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:text="I love Ta ta because she is cute, gorgeous, charming and intelligent. If you don't believe me, you may dial 0961234567. And ask for Ta ta Chen. You're going to love her.
The following message is brought by CQ Corporation.">
</EditText>
</LinearLayout>
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言