Audio Script?

I copied some code from @Untherow, I assume the script worked for her/him but it didn’t work for me. Here’s the code:

/// <summary>
/// Trims silence from both ends in an AudioClip.
/// Makes mp3 files seamlessly loopable.
/// </summary>
/// <param name="inputAudio"></param>
/// <param name="threshold"></param>
/// <returns></returns>
Audio trimSilence(AudioClip inputAudio, float threshold = 0.05f)
{
    // Copy samples from input audio to an array. AudioClip uses interleaved format so the length in samples is multiplied by channel count
    float[] samplesOriginal = new float[inputAudio.samples * inputAudio.channels];
    inputAudio.GetData(samplesOriginal, 0);
    // Find first and last sample (from any channel) that exceed the threshold
    int audioStart = Array.FindIndex(samplesOriginal, sample => sample > threshold),
        audioEnd = Array.FindLastIndex(samplesOriginal, sample => sample > threshold);
    // Copy trimmed audio data into another array
    float[] samplesTrimmed = new float[audioEnd - audioStart];
    Array.Copy(samplesOriginal, audioStart, samplesTrimmed, 0, samplesTrimmed.Length);
    // Create new AudioClip for trimmed audio data
    AudioClip trimmedAudio = AudioClip.Create(inputAudio.name, samplesTrimmed.Length / inputAudio.channels, inputAudio.channels, inputAudio.frequency, false);
    trimmedAudio.SetData(samplesTrimmed, 0);
    return trimmedAudio;
}

My audio is in mp3 and wav form. Two separate files, same audio. I’ve got the mp3 file in the edit. My audio file is called “Sad Hell Presents Roll a Ball The Soundtrack” because this is a game I’m making for my Facebook group, Sad Hell.
Which part of the code is wrong for me?

By the way, the link leads to where I copied the code from.

Hello,

I would need to see the audio file and/or code where you’re calling this function. Do you mean the problems is that the audio file(s) are not looping seamlessly?

The best way to make seamlessly loopable soundtrack is that you just import the perfectly tuned/trimmed soundtrack in WAV format into Unity. Then let Unity to do the compressing into OGG Vorbis to make the audio file very small size in your game.

102872-capture.png