C# 把m4a格式文件转为MP3格式

直接上代码:

   先引用 

           using NAudio.Wave;
           using NAudio.Lame;

1, 文件列表来自于根目录里所有的m4a文件

string directloc = @"G:\mp3\MP3";
string[] fyles = Directory.GetFiles(directloc);
NAudio.Wave.BlockAlignReductionStream stream = null;
NAudio.Wave.DirectSoundOut output = null;

2,遍历数组中,逐一单个文件进行转换。

MediaFoundationReader mfM4A = new MediaFoundationReader(fyles[i]);
stream = new NAudio.Wave.BlockAlignReductionStream(mfM4A);

var dd = fyles[i].Split("\\");
string mp3FileName = "";
if (dd != null)
{
    var ddd = dd[dd.Length - 1];
    if (ddd != null)
    {
        mp3FileName = ddd.ToString();//.Replace(".mp3", "");
    }
}
//output = new NAudio.Wave.DirectSoundOut();
//output.Init(mfM4A);
//output.Play();
// G:\mp3\ToMp3New

using (var mp3FileReader = new LameMP3FileWriter("G:\\mp3\\ToMp3New\\" + mp3FileName, stream.WaveFormat, LAMEPreset.ABR_320))
{
    stream.CopyTo(mp3FileReader);
}

你可能感兴趣的:(C#,C#,音频)