• 大小: 6KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: 其他
  • 标签: wav  截取  分割  毫秒  

资源简介

wav格式文件截取指定时间段内容,精确到毫秒级 使用方法 WavFileCut_Console.exe 原始文件.wav 新生成文件.wav 开始时间毫秒数 结束时间毫秒数

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WavFileCut
{
    public class WavFormat
    {
        public int      _bitsPerSample;
        public int      _channels;
        public int      _sampleRate;
        public long     _byteRate;
    }

    public class WavFile
    {
        private WavFormat   _wavFormat;
        private long        _fileLength;
        private string      _filePath;
        private byte[]      _audioData;

        public WavFile(string filePath)
        {
            _filePath = filePath;
        }

        public WavFormat WavFormat
        {
            get
            {
                if (_wavFormat == null)
                {
                    _wavFormat = GetWavFormat();
                }

                return _wavFormat;
            }
            set
            {
                _wavFormat = value;
            }
        }

        public long FileLength
        {
            get
            {
                if (_wavFormat == null)
                {
                    _wavFormat = GetWavFormat();
                }

                return _fileLength;
            }
            set
            {
                _fileLength = value;
            }
        }

        public long PlayTime
        {
            get
            {
                if (_wavFormat == null)
                {
                    _wavFormat = GetWavFormat();
                }

                return _audioData.Length / _wavFormat._byteRate;
            }
        }

        public byte[] AudioDataBytes
        {
            get
            {
                if (_wavFormat == null)
                {
                    _wavFormat = GetWavFormat();
                }

                return _audioData;
            }
            set
            {
                _audioData = value;
            }
        }

        public void SetWavFormat(int bitsPerSample int channels int sampleRate)
        {
            _wavFormat = new WavFormat();
            _wavFormat._bitsPerSample = bitsPerSample;
            _wavFormat._channels = channels;
            _wavFormat._sampleRate = sampleRate;
        }

        public void WriteWavFile(byte[] audioData)
        {
            WriteWavFile(_wavFormat audioData 0 audioData.Length);
        }

        public void WriteWavFile(WavFormat wavFormat byte[] audioData int startIndex int length)
        {
            FileStream fs = null;
            BinaryWriter bw = null;
            try
            {
                fs = new FileStream(_filePath FileMode.Create FileAccess.Write);
                bw = new BinaryWriter(fs);
                fs.Position = 0;
                bw.Write(new char[4] { ‘R‘ ‘I‘ ‘F‘ ‘F‘ });
                bw.Write((int)(length + 44 - 8));
                bw.Write(new char[8] { ‘W‘ ‘A‘ ‘V‘ ‘E‘

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1450  2013-03-14 14:51  WavFileCut\WavFileCut\Properties\AssemblyInfo.cs

     文件       6954  2013-03-14 14:56  WavFileCut\WavFileCut\WavCut.cs

     文件       2623  2013-03-14 14:53  WavFileCut\WavFileCut\WavFileCut.csproj

     文件       1428  2013-03-14 15:08  WavFileCut\WavFileCut.sln

     文件        964  2013-03-14 15:08  WavFileCut\WavFileCut_Console\Program.cs

     文件       1466  2013-03-14 14:56  WavFileCut\WavFileCut_Console\Properties\AssemblyInfo.cs

     文件       2811  2013-03-14 15:12  WavFileCut\WavFileCut_Console\WavFileCut_Console.csproj

     目录          0  2013-03-14 14:51  WavFileCut\WavFileCut\Properties

     目录          0  2013-03-14 14:56  WavFileCut\WavFileCut_Console\Properties

     目录          0  2013-03-14 15:13  WavFileCut\WavFileCut

     目录          0  2013-03-14 15:13  WavFileCut\WavFileCut_Console

     目录          0  2013-03-14 15:12  WavFileCut

----------- ---------  ---------- -----  ----

                17696                    12


评论

共有 条评论