How to get the decibel of sound when play sound?

Because I want to make the Sonogram.
CC4BA8CE-0DCF-4E74-AAC2-632DBE3CBA6B

You can find an example here, although the principal is still the same.

You will need to get the FFT data from the sound each time you want to update the values, values inside the FFT data are typically between 0 and 1.0. Then you will need to convert it to decibels to a value between -80 and 0 using:

db = 20 * log10(amplitude)

Where amplitude is the value from the FFT data, which is the volume as a percentage.