无法在LINUX上使用NAudio生成峰

ivqmmu1c  于 2023-03-01  发布在  Linux
关注(0)|答案(1)|浏览(273)

我尝试在Linux dotnet core 6.0上使用NAudio生成峰值(.mp3音频),使用此代码(如下所示)用于wavesurfers.js

using(var reader = new AudioFileReader(file))
{
    var samples = reader.Length / (reader.WaveFormat.Channels * reader.WaveFormat.BitsPerSample / 8);

    var max = 0.0f;
    // waveform will be a maximum of 4000 pixels wide:
    var batch = (int)Math.Max(40, samples / 4000);
  
    float[] buffer = new float[batch];
    int read;
    
    while((read = reader.Read(buffer,0,batch)) == batch)
    {
        for(int n = 0; n < read; n++)
        {
            max = Math.Max(Math.Abs(buffer[n]), max);
        };
        console.write(max);//peak ex: 0.342424, this can be store in array or .peak file 
      console.write(',');
        max = 0;    
        
    }
}
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'Msacm32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libMsacm32.dll: cannot open shared object file: No such file or directory
   at NAudio.Wave.Compression.AcmInterop.acmFormatSuggest2(IntPtr hAcmDriver, IntPtr sourceFormatPointer, IntPtr destFormatPointer, Int32 sizeDestFormat, AcmFormatSuggestFlags suggestFlags)
   at NAudio.Wave.Compression.AcmStream.SuggestPcmFormat(WaveFormat compressedFormat)
   at NAudio.Wave.AcmMp3FrameDecompressor..ctor(WaveFormat sourceFormat)
   at NAudio.Wave.Mp3FileReader.CreateAcmFrameDecompressor(WaveFormat mp3Format)
   at NAudio.Wave.Mp3FileReaderBase..ctor(Stream inputStream, FrameDecompressorBuilder frameDecompressorBuilder, Boolean ownInputStream)
   at NAudio.Wave.Mp3FileReader..ctor(String mp3FileName)
   at NAudio.Wave.AudioFileReader.CreateReaderStream(String fileName)
   at NAudio.Wave.AudioFileReader..ctor(String fileName)
   at Program.<Main>$(String[] args) in /home/adil/Blob Test/Program.cs:line 288

我开始知道NAudio只能在Windows上工作。有些地方建议我可以使用NAudio.Core。NAudio.Core到底是什么?我对C#非常陌生,试图了解如何使用NAudio.Core,但找不到文档或任何说明。
如果不可能,有没有其他方法或软件包可以用来实现这一点,最好是麻省理工学院?(我不能使用音频波形由于许可限制)。

hwamh0ep

hwamh0ep1#

您可以直接使用Mp3FileReader和使用NLayer的帧解压缩器。
此代码片段显示如何使用它将MP3文件转换为WAV:

using (var reader = new Mp3FileReader(infile, wf => new Mp3FrameDecompressor(wf)))
{
    WaveFileWriter.CreateWaveFile(outfile, reader);
}

相关问题