小编Aay*_*pta的帖子

使用 NAudio 拆分 Wav 文件会从每个部分中删除 1 秒

我正在使用 NAudio 将 Wav 文件分成相等间隔的多个部分。我正在使用 Mark Heath 在 Sound Code 上提供的代码版本:

 public static void TrimWavFile(string inPath, string outPath, TimeSpan cutFromStart, TimeSpan cutFromEnd)
        {
            using (WaveFileReader reader = new WaveFileReader(inPath))
            {
                using (WaveFileWriter writer = new WaveFileWriter(outPath, reader.WaveFormat))
                {
                    //int bytesPerMillisecond = reader.WaveFormat.AverageBytesPerSecond / 1000;
                    float bytesPerMillisecond = reader.WaveFormat.AverageBytesPerSecond / 1000f;
                    int startPos = (int)cutFromStart.TotalMilliseconds * (int)bytesPerMillisecond;
                    startPos = startPos - startPos % reader.WaveFormat.BlockAlign;

                    int endBytes = (int)cutFromEnd.TotalMilliseconds * (int)bytesPerMillisecond;
                    endBytes = endBytes - endBytes % reader.WaveFormat.BlockAlign;
                    int endPos = (int)reader.Length …
Run Code Online (Sandbox Code Playgroud)

.net c# audio naudio

2
推荐指数
1
解决办法
1033
查看次数

标签 统计

.net ×1

audio ×1

c# ×1

naudio ×1