I have been trying to find a way to have my application speak a response instead of just provide a text response. I feel like it should be easy but I cannot find what I need. I have found many examples of taking user input and converting it to speech, but I only want to have a predetermined phrase spoken. Can anyone tell me what I am missing when searching for info or provide any sources?
Edit: I have been trying at this for a while now. This is the code I have at the moment. There are no errors and the rest of the app works fine, but the message is not spoken on launch.
class MainActivity : AppCompatActivity() {
//declaring variable for speech recognition
private val REQ_CODE_SPEECH_INPUT = 100
private lateinit var mTTS:TextToSpeech
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mTTS = TextToSpeech(applicationContext, TextToSpeech.OnInitListener { status ->
if (status != TextToSpeech.ERROR){
//if there is no error then set language
mTTS.language = Locale.getDefault()
}
})
val helloWorld: String = "hello there"
mTTS.speak(helloWorld, TextToSpeech.QUEUE_FLUSH, null)
}
}