在此代码中, 我正在使用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;
}
}
答案 0 :(得分:0)
您可以使用AudioFileReader
,它会为您提供可以调整的音量属性(1.0为满量程)。它还会将音频转换为带有IEEE浮点样本的ISampleProvider
,但我认为LAME接受IEEE float,否则使用SampleToWaveProvider16
返回到16位整数样本。