Search code examples
mp3naudio

mp3 to sample array NAudio


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.


Solution

  • 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?