'How can i determine duration of audio before playing it?

I am trying to play tts from text input via Android's AudioTrack class. I am using MODE_STREAM and min buffer size is 1024. I want to determine the length of duration for any tts before playing it.

However, upon passing the audioData (bytearray)(which I am getting from some backend api), AudioTrack class just write it directly to Android hardware in order to play it.

In this case, How can I determine the duration of that audio before playing it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source