Ejemplo n.º 1
0
        /// <summary>Convert WAV file to MP3 using libmp3lame library, setting ID3 tag</summary>
        /// <param name="waveFileName">Filename of WAV file to convert</param>
        /// <param name="mp3FileName">Filename to save to</param>
        /// <param name="tag">ID3 tag data to insert into file</param>
        /// <param name="bitRate">MP3 bitrate in kbps, defaults to 128kbps</param>
        /// <remarks>Uses NAudio to read, can read any file compatible with <see cref="NAudio.Wave.AudioFileReader"/></remarks>
        public static void WaveToMP3(string waveFileName, string mp3FileName, ID3TagData tag, int bitRate = 128)
        {
            byte[] tagBytes = null;

            using (var reader = new AudioFileReader(waveFileName))
                using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, 128, tag))
                {
                    reader.CopyTo(writer);
                    tagBytes = writer.GetID3v2TagBytes();
                }

            if (tagBytes != null)
            {
                var dectag = ID3Decoder.Decode(tagBytes);
            }
        }