简体   繁体   English

使用NAudio从Kinect捕获音频

[英]Using NAudio to capture audio from Kinect

I've written the following code which is supposed to capture 4 channel audio from Kinect. 我编写了以下代码,该代码应该从Kinect捕获4声道音频。 However, when I try playing back the file, it looks like the audio speeds up significantly. 但是,当我尝试播放文件时,音频速度似乎会大大提高。 Any idea on why this happens or a possible solution to this problem? 关于为什么会发生这种情况的任何想法,或对此问题的可能解决方案?

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;
                }
            }
        }        
    }

Maybe the number of bits per sample is 32 and not 16. 也许每个样本的位数是32,而不是16。

I've recorded an audio with freenect in linux. 我已经在Linux中用freenect录制了音频。 Here's the output of soxi: 这是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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM