如何使用C#将WAV文件拆分为两个或更多部分 [英] How to split wav file into two or more parts using c#

查看:214
本文介绍了如何使用C#将WAV文件拆分为两个或更多部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码用于在按钮click事件中将600mb的音频wav大文件分为两部分.

Here the below code for splitting a large 600mb audio wav file into two parts inside button click event..

protected void Button1_Click(object sender, EventArgs e)
{
string inputFile = Server.MapPath("~/inputPath/BetterFasterCheaperGovt-HD+720p.wav"); // Substitute this with your Input File 
    FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
    int numberOfFiles = 2;
    int sizeOfEachFile = (int)Math.Ceiling((double)fs.Length / numberOfFiles);
    for (int i = 1; i <= numberOfFiles; i++)
    {
        string baseFileName = Path.GetFileNameWithoutExtension(inputFile);
        string extension = Path.GetExtension(inputFile);
        FileStream outputFile = new FileStream(Path.GetDirectoryName(inputFile) + "\\" + baseFileName + "_" + i.ToString().PadLeft(3, Convert.ToChar("0")) + extension, FileMode.Create, FileAccess.Write);
        int bytesRead = 0;
        byte[] buffer = new byte[sizeOfEachFile];
        if ((bytesRead = fs.Read(buffer, 0, sizeOfEachFile)) > 0)
        {
            outputFile.Write(buffer, 0, bytesRead);
        }
        outputFile.Close();
    }
    fs.Close();
    ClientScript.RegisterStartupScript(this.GetType(), "popup", "alert('success');", true);
}

它成功地拆分为两个文件,每个文件大小相同,即300mb,但 part1.wmv为300mb,显示长度为1hr 16min part2.wmv为300mb,长度为0.

it splits successfully into two file each of same size i.e., 300mb but the part1.wmv is 300mb showing length as 1hr 16min part2.wmv is 300mb length is 0.

意味着part2.wav中没有音频,只会创建空白的损坏文件.

means there is no audio in part2.wav only blank corrupted file is created.

请帮助我解决此问题. 谢谢!

please help me out with fixing the issue. Thanks!!

推荐答案

看看

这篇关于如何使用C#将WAV文件拆分为两个或更多部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆