使用NAudio从Kinect捕获音频

时间:2014-01-26 14:31:40

标签: c# audio kinect naudio

我编写了以下代码,用于从Kinect捕获4声道音频。但是,当我尝试播放文件时,看起来音频显着加快。知道为什么会发生这种情况或者解决这个问题的可能方法吗?

public void Record4channels()
    {
       // recording length = 5 seconds
        int recordingLength = (int)5 * 4 * 16000*2;
          int count, totalCount = 0;

           // sample rate: 16 KHz, bits/ sample : 16, Channel count : 4 
            var format = new NAudio.Wave.WaveFormat(16000, 16,4);

         var audio = new byte[format.AverageBytesPerSecond];

        using (var writer = new NAudio.Wave.WaveFileWriter("c:\\kinectAudio2.wav",format))
        {

            using (Stream audioStream = this.sensor.AudioSource.Start())
            {
                while ((count = audioStream.Read(audio, 0, audio.Length)) > 0 && totalCount < recordingLength)
                {
                    writer.Write(audio, 0, count);
                    totalCount += count;
                }
            }
        }        
    }

1 个答案:

答案 0 :(得分:0)

每个样本的比特数可能是32而不是16。

我在linux上录制了一个带freenect的音频。这是soxi的输出:

Input File     : 'test.wav'
Channels       : 4
Sample Rate    : 16000
Precision      : 32-bit
Duration       : 00:00:03.68 = 58880 samples ~ 276 CDDA sectors
File Size      : 942k
Bit Rate       : 2.05M
Sample Encoding: 32-bit Signed Integer PCM