Program/Android Java

TTS 예제

너구리V 2011. 4. 11. 22:56

UK / US 는 되는데... KOREAN 있는데 안되는..

 import java.util.Locale;

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.Button;
import android.widget.EditText;

public class good extends Activity implements OnInitListener {
  TextToSpeech _tts;
  boolean _ttsActive = false;
  EditText editT;
  Button bt_start;
  String str;
  
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  this.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // 옆으로
  setContentView(R.layout.main);
  editT = (EditText)findViewById(R.id.et);
  
  bt_start = (Button)findViewById(R.id.read);
  bt_start.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
             str = editT.getText().toString();
             _tts.setLanguage(Locale.US);
          _ttsActive = true;
          _tts.speak(str,
          TextToSpeech.QUEUE_FLUSH, null);
             }
      });
  }

  @Override
  public void onPause(){
  super.onPause();

  try{
   if (_tts != null){
    _tts.stop();
    _ttsActive = false;
   }
  }catch(Exception e){}
  }

  @Override
  public void onResume(){
  super.onResume();

  _tts = new TextToSpeech(getApplicationContext(), this);
  }

  @Override
  public void onDestroy(){
  super.onDestroy();
  try{
   if (_tts != null){
    _tts.shutdown();
    _tts = null;
   }
  }catch(Exception e){}
  }

  @Override
  public void onInit(int status) {
  }
}


 <?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"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="What do you want say?"
    />
    <EditText
    android:id ="@+id/et"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
    <Button
    android:id="@+id/read"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Read"
    />
</LinearLayout>
반응형