MP3
Convert an MP3 to WAV
1) Add the using references for NAudio to your project:
using NAudio; using NAudio.Wave;
2) Assuming that you are going to find the location of a MP3 and save the WAV file to the same location:
public static void Mp3ToWav(string mp3File, string outputFile) { using (Mp3FileReader reader = new Mp3FileReader(mp3File)) { WaveFileWriter.CreateWaveFile(outputFile, reader); } }
3) You now have a WAV file in the directory of your MP3.
The complete sample program:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using NAudio; using NAudio.Wave; namespace ConvertMP3toWAV { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void cmbOpen_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { txtLocation.Text = openFileDialog.FileName; } } private void cmbConvert_Click(object sender, EventArgs e) { string outputFileName = txtLocation.Text; outputFileName = outputFileName.Substring(0, txtLocation.TextLength - 3) + "wav"; Mp3ToWav(txtLocation.Text, outputFileName); } public static void Mp3ToWav(string mp3File, string outputFile) { using (Mp3FileReader reader = new Mp3FileReader(mp3File)) { WaveFileWriter.CreateWaveFile(outputFile, reader); } } } }