基本信息
源码名称:NAudio实现mp3转换成wav
源码大小:0.42M
文件格式:.zip
开发语言:C#
更新时间:2018-07-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

NAudio实现mp3格式和wav格式相互转换



using Alvas.Audio;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestMp3Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            string mp3file;
            //输入音频地址
            Console.Out.Write("Please enter the mp3 path:");
            mp3file = Console.In.ReadLine();

            //替换后缀
            string wavfile = mp3file.Replace(".mp3", ".wav");
            //string wavfile = mp3file.Replace(".wav", ".mp3");
            string wavpath = wavfile;

            //文件名
            int index = wavfile.LastIndexOf("\\");
            string wavname = wavfile.Substring(index   1, wavfile.Length - index - 1);
            index = mp3file.LastIndexOf("\\");
            string mp3name = mp3file.Substring(index   1, mp3file.Length - index - 1);

            Console.Out.WriteLine("Converting {0} to {1}", mp3name, wavname);

            //读取MP3.  mp3——>wav
            using (Mp3FileReader reader = new Mp3FileReader(mp3file))
            {
                //调用CreatePcmStream方法
                using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
                {
                    //创建转换后的文件
                    WaveFileWriter.CreateWaveFile(wavfile, pcmStream);
                    Console.Out.WriteLine("Conversion finish and wav is saved at {0}.\nPress any key to finish.", wavpath);
                    Console.In.ReadLine();
                }
            }
            //WaveFileReader : wav ——> mp3
            //using (WaveFileReader reader = new WaveFileReader(mp3file))
            //{
            //    using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
            //    {
            //        WaveFileWriter.CreateWaveFile(wavfile, pcmStream);
            //        Console.Out.WriteLine("Conversion finish and MP3 is saved at {0}.\nPress any key to finish.", wavpath);
            //        Console.In.ReadLine();
            //    }
            //}


        }
    }
}