1
I would like help, I have the following situation.
I have a web application in which to return an audio file according to the requests. However (I believe) because these audios are of format . wav I could not hear them, but when returning a recording . mp3 it was possible to listen to it normally.
I tried to implement some way to convert the . wav files to . mp3 using Nuget package Naudio with the code below but was not successful.
private void ConvertWavMP3(string wavFile)
{
try
{
using (var wavRdr = new WaveFileReader(wavFile))
using (var mp3Writer = new LameMP3FileWriter(wavFile.Replace(".wav", ".mp3"), wavRdr.WaveFormat, 128))
{
wavRdr.CopyTo(mp3Writer);
}
}
catch (Exception ex)
{
MessageBox.Show("Error converting wav to mp3.", "CONVERSION ERROR");
}
}
private static void ConvertMp3ToWav(string mp3File)
{
try
{
using (Mp3FileReader reader = new Mp3FileReader(mp3File))
{
//using (WaveStream pcmStream = new WaveFormatConversionStream(new WaveFormat(8000, 16, 1), reader))
using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
{
WaveFileWriter.CreateWaveFile(mp3File.Replace(".mp3", ".wav"), pcmStream);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error converting mp3 to wav.", "CONVERSION ERROR");
}
}
Enter the code you used for your initial attempt, which we will help.
– Marcelo Shiniti Uchimura
Sorry I ended up saving the question without the code! Changed!
– Victor Augusto
Bit rate is wrong, use
LamePreset.ABR_128
in place of128
, inusing (var mp3Writer = new LameMP3FileWriter(wavFile.Replace(".wav", ".mp3"), wavRdr.WaveFormat, 128)) { ... }
– Marcelo Shiniti Uchimura
I believe this approach can work: https://stackoverflow.com/a/22889091/4312593
– Netinho Santos
@Marcelouchimura as I return the converted file ?
– Victor Augusto
@Victoraugusto, you are using which version of ASP.NET?
– Marcelo Shiniti Uchimura
@Marcelouchimura 4.5.2
– Victor Augusto