Get Audio TimeLine

Hello!

I am trying to get the audio timeline of a music playing on a game.

In Editor, when i select the audio, it shows on the inspector the timeline. There are anyway to get this as an image for example, with code?

I did it.

Sharing my raw code. A function that receives an audioclip and return a sprite with the timeline.

I apply also an low pass filter to better results.

One sample returned image:

[64181-sem-nome.png*_|64181]

    public static Sprite getMusicTimeline(AudioClip audioClip)
    {
        float[] dataClip;
        Texture2D texture;
        int[] dataFinal;

        dataClip = new float[audioClip.samples];
        audioClip.GetData(dataClip, 0);

        texture = new Texture2D(500, 400, TextureFormat.ARGB32, false);

        dataFinal = new int[texture.width];

        for (int x = 0; x < texture.width; x++)
        {
            int indexData = (int)Functions.mapTruncate(x, 0, texture.width, 0, dataClip.Length - 1);

            int valueOnImage = (int)(Functions.mapTruncate(dataClip[indexData], 0, 1f, 0, texture.height / 2 - 1));

            dataFinal[x] = valueOnImage;
        }

        for (int i = 4; i < dataFinal.Length - 4; ++i)
            dataFinal _= (dataFinal[i - 4] + dataFinal[i - 3] + dataFinal[i - 2] + dataFinal[i - 1] + dataFinal *+ dataFinal[i + 1] + dataFinal[i + 2] + dataFinal[i + 3] + +dataFinal[i + 4]) / 5;*_

for (int x = 0; x < texture.width; x++)
{

for (int y = texture.height / 2 - 1; y < dataFinal[x] + texture.height / 2 - 1; y++)
texture.SetPixel(x, y, Color.white);
for (int y = dataFinal[x] + texture.height / 2 - 1; y < texture.height; y++)
texture.SetPixel(x, y, Color.clear);

for (int y = texture.height / 2 - 1; y > texture.height / 2 - 1 - dataFinal[x]; y–)
texture.SetPixel(x, y, Color.white);
for (int y = texture.height / 2 - 1 - dataFinal[x]; y >= 0; y–)
texture.SetPixel(x, y, Color.clear);
}

texture.Apply();

Rect rec = new Rect(0, 0, texture.width, texture.height);

return Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);
}
_*