mp3 to sample array NAudio

684 views Asked by At

How can I use NAudio library to get sample float array from mp3 file?

Here is my code:

        float[] buffer = new float[2000];

        AudioFileReader reader = new AudioFileReader(filePath);
        reader.Read(buffer, 0, 2000);

After that buffer is always empty (only zeros inside).

You could also provide me another useful library in C# to realize this.

1

There are 1 answers

0
Mark Heath On BEST ANSWER

You're reading the first 2000 samples which is only going to be around 20ms of audio, so it's quite possible that your MP3 starts with a bit of silence. Have you tried reading further into the file?