I have to convert spx audio file (in ogg format) to mp3 file. I've tried a couple of thing and so far nothing is working.
I've tried using the LameMP3FileWriter from the Naudio.Lame library.
private void WriteOggStreamToMp3File(Stream oggStream, string mp3FileName)
{
var format = new WaveFormat(8000, 1);
using (var mp3 = new LameMP3FileWriter(mp3FileName, format, LAMEPreset.ABR_128))
{
oggStream.Position = 0;
oggStream.CopyTo(mp3);
}
}
Doesn't work great as the outputted mp3 file is nothing but static noise.
I've also found this sample from the NSpeex codeplex page (https://nspeex.codeplex.com/discussions/359730) :
private void WriteOggStreamToMp3File(Stream oggStream, string mp3FileName)
{
SpeexDecoder decoder = new SpeexDecoder(BandMode.Narrow);
Mp3WriterConfig config = new Mp3WriterConfig();
using (Mp3Writer mp3 = new Mp3Writer(new FileStream(mp3FileName, FileMode.Create), config))
{
int i = 0;
int bytesRead = 0;
while (i < speexMsg.SpeexData.Length)
{
short[] outData = new short[160];
bytesRead = decoder.Decode(speexMsg.SpeexData, i, speexMsg.FrameSize, outData, 0, false);
for (int x = 0; x < bytesRead; x++)
mp3.Write(BitConverter.GetBytes(outData[x]));
i += speexMsg.FrameSize;
}
mp3.Flush();
}
}
Unfortunately, Mp3WriterConfig and Mp3Writer are not part of the current library (NSpeex). And I have no idea what "speexMsg" is supposed to be.
So my question is : how can I convert a spx (in a ogg file) to mp3 using c#?