2012.11.13 09:53

ispeech TTS 한글 사용

 

ispeech-sdk-1.1-beta.jar

ispeech홈페이지(http://www.ispeech.org/) 에서 모바일에서 사용하기 위한 등록 절차를 마치면

API 키값을 받을 수 있다. 키값과 첨부된 파일의 jar 파일을 포함시킨후 아래와 같은 소스를 돌리면 한글을

말해주는 것을 확인할 수 있다.

 


api 참고는 (http://www.ispeech.org/api/)

 

Androidmanifest.xml 설정

 


액티비티 설정

다음과 같이 추가


<!-- The following three lines are required to used iSpeech's Android SDK. -->

<activity android:name="org.ispeech.iSpeechFramework" android:theme="@android:style/Theme.Translucent" />

<meta-data android:name="ispeech_api_key" android:value="등록시 받아온 키값" />

<meta-data android:name="debug" android:value="false" />

<!-- For production servers, debug is false.  For development servers, debug is true. -->

<!-- Make sure to have the meta data debug value set to "true" for testing. -->

 

 

 

 


소스설정

 


TTSActivity.java

package com.example.tts2;

 


import java.net.URLEncoder;

 


import org.ispeech.SpeechSynthesis;

import org.ispeech.SpeechSynthesisEvent;

import org.ispeech.error.BusyException;

import org.ispeech.error.InvalidApiKeyException;

import org.ispeech.error.NoNetworkException;

 


import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.EditText;

import android.widget.Toast;

 


import com.example.R;

 


public class TTSActivity extends Activity{

  private static final String TAG = "iSpeech SDK Sample";

  SpeechSynthesis synthesis;

  Context mContext;

 

  public void onCreate(Bundle icicle){

   super.onCreate(icicle);

   mContext = this.getApplicationContext();

 

   setContentView(R.layout.tts);

 

   ((EditText)findViewById(R.id.text)).setText(R.string.tts_sample_text);

   findViewById(R.id.speak).setOnClickListener(new OnSpeakListener());

   findViewById(R.id.stop).setOnClickListener(new OnStopListener());

 

   prepareTTSEngine();

  }

 

  private void prepareTTSEngine(){

   try{

    synthesis = SpeechSynthesis.getInstance(this);

    synthesis.setSpeechSynthesisEvent(new SpeechSynthesisEvent(){

     public void onPlaySuccessful(){

      Log.d(TAG, "onPlaySuccessful");

     }

   

     public void onPlayStopped(){

      Log.d(TAG, "onPlayStopped");

     }

   

     public void onPlayFailed(Exception e){

      Log.d(TAG, "onPlayFailed");

      e.printStackTrace();

     }

   

     public void onPlayStart(){

      Log.d(TAG, "onPlayStart");

     }

   

     @Override

     public void onPlayCanceled(){

      Log.d(TAG, "onPlayCanceled");

     }

    });

   }catch(InvalidApiKeyException e){

    Log.d(TAG, "Invalid API key\n" + e.getStackTrace());

    Toast.makeText(mContext, "ERROR: Invalied API key", Toast.LENGTH_LONG).show();

   }

  }

 

  private class OnSpeakListener implements OnClickListener{

   public void onClick(View v){

    try{

   

     String ttsText = ((EditText) findViewById(R.id.text)).getText().toString();

                                // "Voice" - 음성 설정, "kr 국가, korean 언어, female 성별

     synthesis.addOptionalCommand("Voice", "krkoreanfemale");

     synthesis.speak(ttsText);

   

    }catch(BusyException e){

     Log.d(TAG, "SDK is busy");

     e.printStackTrace();

     Toast.makeText(mContext, "ERROR: SDK is busy", Toast.LENGTH_LONG).show();

    } catch (NoNetworkException e) {

     // TODO Auto-generated catch block

     Log.d(TAG, "Network is not available\n" + e.getStackTrace());

     Toast.makeText(mContext, "ERROR: Network is not available", Toast.LENGTH_LONG).show();

    } catch(Exception e){

     e.printStackTrace();

    }

   }

  }

 

  public class OnStopListener implements OnClickListener{

   public void onClick(View v){

    if(synthesis != null){

     synthesis.stop();

    }

   }

  }

 

  @Override

  protected void onPause(){

   synthesis.stop();

   super.onPause();

  }

}

 

 

출처 : http://blog.naver.com/PostView.nhn?blogId=gh2501&logNo=159249098


 

Trackback 54 Comment 0