ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î

Android Text To Speech(TTS)
7³â Àü
http://upadhyayjiteshandroid.blogspot.kr/2013/01/android-text-to-speechtts.html


In  this  blog  the  TTS  is  discussed  as  it  is  always  nice  to  use  TTS  in  android  .  we  just  need  to  follow  few  steps.
  make  a  new  project  with  name  AndroidTextToSpeech  and  a  main  activity  with  the  name  AndroidTextToSpeechActivity.java  and  a  layout  as  main.xml

1)  copy  the  following  code  to  yours  AndroidTextToSpeechActivity.java


import  java.util.Locale;

import  android.app.Activity;
import  android.os.Bundle;
import  android.speech.tts.TextToSpeech;
import  android.util.Log;
import  android.view.View;
import  android.widget.Button;
import  android.widget.EditText;

public  class  AndroidTextToSpeechActivity  extends  Activity  implements
    TextToSpeech.OnInitListener  {
  /**  Called  when  the  activity  is  first  created.  */

  private  TextToSpeech  tts;
  private  Button  btnSpeak;
  private  EditText  txtText;

  @Override
  public  void  onCreate(Bundle  savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tts  =  new  TextToSpeech(this,  this);

    btnSpeak  =  (Button)  findViewById(R.id.btnSpeak);

    txtText  =  (EditText)  findViewById(R.id.txtText);

    //  button  on  click  event
    btnSpeak.setOnClickListener(new  View.OnClickListener()  {

      public  void  onClick(View  arg0)  {
        speakOut();
      }

    });
  }

  @Override
  public  void  onDestroy()  {
    //  Don't  forget  to  shutdown!
    if  (tts  !=  null)  {
      tts.stop();
      tts.shutdown();
    }
    super.onDestroy();
  }

  public  void  onInit(int  status)  {
    //  TODO  Auto-generated  method  stub

    if  (status  ==  TextToSpeech.SUCCESS)  {

      int  result  =  tts.setLanguage(Locale.US);

      //  tts.setPitch(5);  //  set  pitch  level

      //  tts.setSpeechRate(2);  //  set  speech  speed  rate

      if  (result  ==  TextToSpeech.LANG_MISSING_DATA
          ||  result  ==  TextToSpeech.LANG_NOT_SUPPORTED)  {
        Log.e("TTS",  "oops  it  is  not  supported");
      }  else  {
        btnSpeak.setEnabled(true);
        speakOut();
      }

    }  else  {
      Log.e("TTS",  "Initilization  Failed");
    }

  }

  private  void  speakOut()  {

    String  text  =  txtText.getText().toString();

    tts.speak(text,  TextToSpeech.QUEUE_FLUSH,  null);
  }
}

2)  and  now  in  this  step  you  need  to  make  a  layout  as  follows  at  main.xml


<?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"
        android:background="#044372">
      
  <TextView  android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Text  To  Speech  (TTS)"
              android:padding="15dip"
              android:textColor="#ffffff"
              android:textSize="26dip"
              android:gravity="center"
              android:textStyle="bold"/>
  
        <EditText  android:id="@+id/txtText"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:hint="Enter  your  text  here"
                android:layout_marginTop="20dip"              
                android:layout_margin="10dip"/>
      
        <Button  android:id="@+id/btnSpeak"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:text="Text  to  Speech"
                  android:layout_margin="10dip"/>

</LinearLayout>

3)  run  the  program    at  emulator/device  and  you  can  see  the  output

ÃßõÃßõ : 264 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
217
MediaPlayer Ŭ·¡½º »ç¿ë¹ý
216
¾Èµå·ÎÀ̵忡¼­ audio player ½ÇÇàÇϱâ
215
[Android] MediaPlayer À½¾ÇÀç»ý±â ¸¸µé±â
214
Eclipse¿Í Android NDK ¿¬µ¿Çϱâ
213
Android Sliding Drawer Functionality ¾Èµå·ÎÀÌµå ½½¶óÀ̵ù µå·Î¿ì ¿¹Á¦ sample
212
Android Speech To Text
211
Android WebPageLoader with progress-bar
Android Text To Speech(TTS)
209
Android Playing Audio from a web url
208
Button height different from background height in Android image design
207
Android Getting Started with Material Design
206
Using toast inside timertask perfect
205
³×Æ®¿öÅ© »óÅ [Android]
204
Webview source [Android]
203
°øÀ¯ Intent [Android]
202
intent uri ¸ðÀ½ [Android]
201
http requestWebViewClient [Android]
200
ij½Ã »èÁ¦
199
ij½Ã Áö¿ì±â [Android]
198
¹Ù·ÎÇ®¾î(¼öÇÐ ¹®Á¦ ÁúÀÇÀÀ´ä SNS) ¿¡ »ç¿ëµÈ ¿ÀǼҽº ¶óÀ̺귯¸® [Android]
197
Webviw [Android]
196
¿ÀǼҽº ¶óÀ̺귯¸® ¸ðÀ½ [Android]
195
Android webview °³¹ß½Ã ¾Ë¾ÆµÖ¾ß ÇÒ °Íµé [Android]
194
webview µ¿¿µ»ó Àç»ý [Android]
193
[Android] Webview 404 ¿¡·¯ ó¸®
192
[Android] webview ssl ¹®Á¦
191
[Android] Webview url ¼û±â±â
190
[Android] AlarmManager ÀÏÁ¤½Ã°£ À̺¥Æ® ½ÇÇà
189
¾Èµå·ÎÀÌµå ¿ÀǼҽº ³¡ÆÇ
188
android studio DefaultHttpClient, HttpClient import ¿¡·¯
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.