I have been trying to implement textToSpeech on a microphone that you can press on, but the textToSpeech turns red and "unresolved reference" is displayed.
Here is the code from the Main Activity:
vh.miketv.setOnClickListener {
val text: String =
celldata!![position].getText_eng().toString() + " " + celldata[position].getText_spn()
textToSpeech.speak(text, QUEUE_FLUSH, null)
}
return view
Also, here is everything that I have imported:
import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.speech.tts.TextToSpeech
import android.speech.tts.TextToSpeech.*
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.GridView
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import main.com.cellappkotlin.model.CellDataBean
import java.util.*
I have also tried in Java, and it worked with the following code, but I can't figure it out how to make it work in Kotlin as well:
public void onClick(View view) {
String text = celldata.get(i).getText_eng()+" "+celldata.get(i).getText_spn();
textToSpeech.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
The text to speech works generally in this app, I have implemented it somewhere else and everything was okay, but only in this particular case, when I want to press on that microphone, it doesn't seem to work.
Could someone help me understand what is wrong, please? Thank you very much.