I am trying to create a speech-to-text app, and once you say a specific word, you should hear a sound for 5 seconds and then see a image. However, I am only able to see the image, but I don't hear the sound.
Here is the block of code for this sound in the Main Activity:
private fun protocolDist() {
sounds!!.play(sound1, 1.0f, 1.0f, 1, 0, 1f)
Thread {
for (i in 0..5) {
try {
Thread.sleep(1000)
} catch (e: InterruptedException) {
e.printStackTrace()
}
val finalI = 5 - i
textTest!!.post { textTest!!.text = finalI.toString() }
}
runOnUiThread { imMain!!.setImageResource(R.drawable.img1) }
}.start()
}
Also, depending on the version, there are two different types:
private fun createSoundPool() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
createNewSoundPool()
} else {
createOldSoundPool()
}
}
I am not sure what I did wrong or if I forgot something. Any ideas? Thanks.