안드로이드스튜디오 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라는 오류 메세지가 뜹니다. 어떻게 해결해야하나요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)