안드로이드스튜디오 TTS를 만드는 도중 import에서 annotation이 없다고하는 오류에 대하여
조회수 686회
MainActivity 코드입니다. package com.example.jhttskorean;
import android.app.Activity; import android.os.Build; import android.speech.tts.TextToSpeech; import android.support.annotation.RequiresApi; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText;
import androidx.annotation.RequiresApi;
import java.util.Locale;
public class MainActivity extends Activity implements TextToSpeech.OnInitListener {
private TextToSpeech tts;
private Button btn_Speak;
private EditText txtText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TextToSpeech(this, this);
btn_Speak = findViewById(R.id.BtnSpeak);
txtText = findViewById(R.id.txtText);
btn_Speak.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View v) {
speakOut();
}
});
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void speakOut() {
CharSequence text = txtText.getText();
tts.setPitch((float) 0.6);
tts.setSpeechRate((float) 0.1);
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "id1");
}
@Override
public void onDestroy() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.KOREA);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
btn_Speak.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initialization Failed!");
}
}
} 이며 package android.support.annotation does not exist라는 오류 메세지가 뜹니다. 어떻게 해결해야하나요?
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력