Unity Kinect v2音频输入 [英] Unity Kinect v2 audio input
问题描述
我正在努力让音频输入与团结一致。身体追踪工作正常。我按照音频基础教程进行了调整,并以类似于Body教程的方式对其进行了调整。
I am trying to get audio input to work for with unity. Body tracking works fine. I followed the audio basics tutorial and adapted it for unity in a similar way to the Body tutorial was done.
这是我当前代码的一小部分。即使_AudioReader.AcquireLatestBeamFrames();返回一个非空列表,它始终只有一个元素在列表中,为null。想法?
Here is a snippet of my current code. Even though _AudioReader.AcquireLatestBeamFrames (); returns a non null list, it always only has one element in the list, which is null. Ideas?
void Start ()
{
_Sensor = KinectSensor.GetDefault();
if (_Sensor != null)
{
_Reader = _Sensor.BodyFrameSource.OpenReader();
if (!_Sensor.IsOpen)
{
_Sensor.Open();
}
//initialize audio reader
var audioSource = _Sensor.AudioSource;
this.audioBuffer = new byte[audioSource.SubFrameLengthInBytes];
_AudioReader = _Sensor.AudioSource.OpenReader ();
}
}
void Update ()
{
if (_Reader != null) {
var frame = _Reader.AcquireLatestFrame ();
if (frame != null) {
if (_Data == null) {
_Data = new Body[_Sensor.BodyFrameSource.BodyCount];
}
frame.GetAndRefreshBodyData (_Data);
frame.Dispose ();
frame = null;
}
}
if (_AudioReader != null) {
var audioFrames = _AudioReader.AcquireLatestBeamFrames ();
if (audioFrames != null) {
// it gets here just fine
if (audioFrames [0] != null) {
// it never gives me any audio frames!
var subFrameList = audioFrames [0].SubFrames;
foreach (AudioBeamSubFrame subFrame in subFrameList) {
// Check if beam angle and/or confidence have changed
bool updateBeam = false;
if (subFrame.BeamAngle != this.beamAngle) {
this.beamAngle = subFrame.BeamAngle;
updateBeam = true;
}
if (subFrame.BeamAngleConfidence != this.beamAngleConfidence) {
this.beamAngleConfidence = subFrame.BeamAngleConfidence;
updateBeam = true;
}
if (updateBeam) {
// Refresh display of audio beam
this.AudioBeamChanged ();
}
// Process audio buffer
推荐答案
它至少工作一次还是什么都没发生?你是如何处理audioFrames对象或subFrameList的?
Does it work at least once or nothing happens at all? How are you disposing the audioFrames object or subFrameList?
var audioFrames = _AudioReader.AcquireLatestBeamFrames ();
var subFrameList = audioFrames [ 0 ]。 子框架 ;
与所有框架对象一样,它们必须处理,这可能是这里的问题。 subFrameList应该是AudioBeamFrame类型,它有.Dispose(),以及audioFrames
[ 0 < span class ="pun">] 。从AcquireLatestBeamFrames返回的集合可能是问题,因为它没有Dispose,但您可以投射它(未测试)。我将调查这个
并将其报告给团队。
As with all the frame objects they have to be disposed which might be the issue here. subFrameList should be of type AudioBeamFrame which has a .Dispose(), as well as, audioFrames [0]. The returned collection from AcquireLatestBeamFrames may be the issue since that does not have a Dispose, but you may be able to cast it(not tested). I will look into this and report it to the team.
这篇关于Unity Kinect v2音频输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!