C# 使用NAudio实现wav互转MP3

        /// 
        /// 将wav转为MP3
        /// 
        /// in wav文件
        /// out MP3文件
        public static void ConvertWAVtoMP3(string sourceFile, string desFile)
        {
            MediaFoundationApi.Startup();
            using (var reader = new WaveFileReader(sourceFile))
            {
                MediaFoundationEncoder.EncodeToMp3(reader, desFile);
            }
        }

        /// 
        /// 将mp3转为wav
        /// 
        /// in mp3文件
        /// out wav文件
        public static void ConvertMP3toWAV(string sourceFile, string desFile)
        {
            using (var reader = new Mp3FileReader(sourceFile))
            {
                WaveFileWriter.CreateWaveFile(desFile, reader);
            }
        }

更多方案参见:

https://github.com/naudio/NAudio/blob/master/Docs/ConvertMp3ToWav.md

https://github.com/naudio/NAudio/blob/master/Docs/MediaFoundationEncoder.md

你可能感兴趣的:(音视频处理,C#,C#,NAUDIO)