Cannot hear the sound activated by a specific word (speech-to-text)

Viewed 18

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.

1 Answers

everything seems okay in that code, maybe you forgot to add a function at the end that enables the sound. Try:

private fun loadSounds() {
        sound_sound1 = sounds!!.load(this, R.raw.sound1, 1)
    }

I hope it helps.

Related