我正在尝试将Mp3文件转换为Wave,但是我需要特定的频率,例如: 8000 48000 ... 我知道如何将文件转换为Wave,但是我真的不知道如何更改频率。我试图采用二进制代码并更改simpleRate,但是由于它是不可变的刷新,所以它不起作用。 有没有办法可以修改不可变的同花顺?
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "MP3 File (*.mp3)|*.mp3;";
if (open.ShowDialog() != DialogResult.OK) return;
SaveFileDialog save = new SaveFileDialog();
save.Filter = "WAV File (*.wav)|*.wav;";
if (save.ShowDialog() != DialogResult.OK) return;
using (Mp3FileReader mp3 = new Mp3FileReader(open.FileName))
{
using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
{
BinaryReader reader = new BinaryReader(pcm);
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32();
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int channels = reader.ReadInt16();
int sampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int bitDepth = reader.ReadInt16();
reader.Close();
sampleRate = 8000;
using (BinaryWriter writer = new BinaryWriter(pcm))
{
writer.Write(chunkID);
writer.Write(fileSize);
writer.Write(riffType);
writer.Write(fmtID);
writer.Write(fmtSize);
writer.Write(fmtCode);
writer.Write(channels);
writer.Write(sampleRate);
writer.Write(fmtAvgBPS);
writer.Write(fmtBlockAlign);
writer.Write(bitDepth);
}
WaveFileWriter.CreateWaveFile(save.FileName, pcm);
}
}
}