Sir, Thanks for your answer. I also tried your provided source but it’s also using only a mic and is very hard to understand,  I’m using this project as an example.

  
      

      github.com
  

  
    

6-4/Tensorflow_lite/lite/examples/sound_classification/android at... 4

  91afe9ee34446558da2f6f9e4ec7535a2aac4c61/Tensorflow_lite/lite/examples/sound_classification/android

  Contribute to onwood/6-4 development by creating an account on GitHub.

  

  
    
    
  

  


This project using the  * TFLite Task Library 2 is very easy.
I’m using this code to prepare the wav file, please check out this
object AudioConverter {
fun readAudioSimple(path: File): FloatArray {
    val input =
        BufferedInputStream(FileInputStream(path))
    val buff = ByteArray(path.length().toInt())
    val dis = DataInputStream(input)
    dis.readFully(buff)
    // remove wav header at first 44 bytes
    return floatMe(shortMe(buff.sliceArray(buff.indices)) ?: ShortArray(0)) ?: FloatArray(
        0
    )
}

fun FloatArray.sliceTo(step: Int): List<FloatArray> {
    val slicedAudio = arrayListOf<FloatArray>()
    var startAt = 0
    var endAt = 15600
    val stepSize = if (step != 0) (15600 * (1f / (2 * step))).toInt() else 0
    while ((startAt + 15600) < this.size) {
        if (startAt != 0) {
            startAt = endAt - stepSize
            endAt = startAt + 15600
        }
        slicedAudio.add(this.copyOfRange(startAt, endAt))
        startAt = endAt
    }
    return slicedAudio
}

private fun shortMe(bytes: ByteArray): ShortArray {
    val out = ShortArray(bytes.size / 2)
    ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(out)
    return out
}

private fun floatMe(pcms: ShortArray): FloatArray {
    val floats = FloatArray(pcms.size)
    pcms.forEachIndexed { index, sh ->
        // The input must be normalized to floats between -1 and +1.
        // To normalize it, we just need to divide all the values by 2**16 or in our code, MAX_ABS_INT16 = 32768
        floats[index] = sh.toFloat() / 32768.0f

    }
    return floats
}
}

I’m Student, please help me. I really need this solution.