안드로이드 개발 질문/답변
(글 수 45,052)
package com.android.testpr;
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;
public class testandroid extends Activity implements TextToSpeech.OnInitListener {
private TextToSpeech tts; Button test; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
tts = new TextToSpeech(this, this); test = (Button) findViewById(R.id.bb);
test.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { // TODO Auto-generated method stub tts.speak("hello, android", TextToSpeech.QUEUE_FLUSH, null); } }); }
@Override protected void onDestroy() { if(tts != null){ tts.stop(); tts.shutdown(); } super.onDestroy(); }
public void onInit(int status){ if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TextToSpeech", "Language is not available."); } else { test.setEnabled(true); tts.speak("start TTS Services", TextToSpeech.QUEUE_FLUSH, null); } } else { Log.e("TextToSpeech", "Could not initialize TextToSpeech."); } } }
이게 Tutorial 에서 가져온 TextToSpeech 소스 인데요
이것만 돌리면 잘 돌아가는데
여기서 위에 tts 선언부를 똑같이 onCreate 안에 가져다 쓰고
onDestroy 와 onInit 을 똑같이 써서 붙였는데
디버깅을 해보면 onInit 함수에 아예 들어가질 않더군요 (물론 그 프로젝트도 implements TextToSpeech.OnInitListener 해줬습니다.)
왜 onInit 에 접근을 하지 않는 걸까요 ㅠㅠ
google api 때문인것도 아닌거 같은데.
혹시 같은 경험 있으신분 있으면 답변 부탁드립니다아아아아아
아 여기에서 문제가 tts = new TextToSpeech(this, this) 쪽 문제인거 같은데요. 이게 TabActivty 에서 불러온 것중 한 액티비티 인데요. 그럼 this가 바껴야 하는건가요?? 참고로 TextToSpeech(Context context, OnInitListener init) 입니다 ㅠㅠㅠ