在这段代码中,我使用 NAudio 和 Lame 将 wav 文件转换为 mp3 流,并且我得到 mp3 流输出没有任何问题。但除此之外,我还想将音量设置为最终的 mp3 流。任何帮助是极大的赞赏。
public byte[] ConvertWavToMP3(byte[] bt, uint bitrate)
{
MemoryStream ms = new MemoryStream(bt);
ms.Seek(0, SeekOrigin.Begin);
var ws = new WaveFileReader(ms);
byte[] wavdata = null;
using (MemoryStream wavstrm = new MemoryStream())
using (WaveFileWriter wavwri = new WaveFileWriter(wavstrm, ws.WaveFormat))
{
ws.CopyTo(wavwri);
wavdata = wavstrm.ToArray();
}
WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(ws.WaveFormat.SampleRate, ws.WaveFormat.BitsPerSample, ws.WaveFormat.Channels);
Yeti.Lame.BE_CONFIG beconf = new Yeti.Lame.BE_CONFIG(fmt, bitrate);
using (MemoryStream mp3strm = new MemoryStream())
using (Mp3Writer mp3wri = new Mp3Writer(mp3strm, fmt, beconf))
{
mp3wri.Write(wavdata, 0, wavdata.Length);
byte[] mp3data = mp3strm.ToArray();
return mp3data;
}
}