用c#合并wav文件。

 也做c#语音合成,参考了你的示例程序,给我很大帮助,谢谢!
Wave合并的关键在于  1: 复制一个头   2: 调整文件大小,数据大小 3: 数据区合并。 你在程序中只合并的文件长度。
因为不同的wave文件 ,数据区的位置是不一样的,一般在“data"后面 ,这是我的代码:
 FileStream fs_1 = new FileStream(tb1.Text, FileMode.Open, FileAccess.Read);
            FileStream fs_2 = new FileStream(tb2.Text, FileMode.Open, FileAccess.Read);
            byte[] bInfo = new byte[56];
            fs_1.Read(bInfo, 0, 56);
            byte[] bInfo2 = new byte[56];
            fs_2.Read(bInfo2, 0, 56);       
          //  byte[] filesize = System.BitConverter.GetBytes((int)wavinfo_1.filesize + (int)wavinfo_2.filesize);
            int file1size = System.BitConverter.ToInt32(bInfo, 4);
            int file2size = System.BitConverter.ToInt32(bInfo2, 4);
            byte[] filesize = System.BitConverter.GetBytes(file1size +file2size);
            byte[] datasize = System.BitConverter.GetBytes(System.BitConverter.ToInt32(bInfo, 52) + System.BitConverter.ToInt32(bInfo2, 52)+48);                
            FileStream tofile = new FileStream("D://123.wav", FileMode.CreateNew);
          byte[] dushu_1 = new byte[file1size];
           byte[] dushu_2 = new byte[file2size];
            BinaryWriter w = new BinaryWriter(tofile);
           

            for (int i = 4, j = 0; i < 8; i++, j++)
            {
                bInfo[i] = filesize[j];
            }

            for (int i = 52, j = 0; i < 56; i++, j++)
            {
                bInfo[i] = datasize[j];
            }
            w.Write(bInfo);
            fs_1.Read(dushu_1, 0, file1size);
            w.Write(dushu_1, 0, file1size);

            fs_2.Read(dushu_2, 0, file2size);
            w.Write(dushu_2, 0, file2size);
            w.Flush();
            w.Close();
            fs_1.Close();
            fs_2.Close();
            tofile.Close();

你可能感兴趣的:(用c#合并wav文件。)