none
AEC (Acoustic Echo Cancellation) in C#

    Question

  • Can anyone point me to any C# example code that shows how to use the Acoustic Echo Cancellation on Kinect.

    (I've seen the C++ AEC example ,but I'm looking for similar in C#)

    thanks.

    Steve.

    Monday, July 18, 2011 9:53 PM

Answers

  • Steve,

    We don't have a full C# sample, but hopefully the following snippet will help you get started (it mirrors _tmain function from C++ sample):

    KinectAudioSource audio = new KinectAudioSource();
    audio.SystemMode = SystemMode.OptibeamArrayAndAec;
    
    short micIndex = -1;
    foreach (AudioDeviceInfo info in audio.FindCaptureDevices())
    {
      micIndex = info.DeviceIndex;
      break;
    }
    audio.MicrophoneIndex = micIndex;
    audio.SpeakerIndex = 0;
    
    Stream audioStream = audio.Start();
    
    // Read from stream

    Note that the snippet above does not perform error checking and also assumes default speaker device. If you have multiple speaker devices, you will need to do a managed wrapper around MMDevice API, or find a pre-existing open source managed wrapper that satisfies your needs. Maybe http://www.codeproject.com/KB/vista/CoreAudio.aspx will help you in this front.

    Eddy

     


    I'm here to help
    Monday, July 18, 2011 10:34 PM

All replies

  • Steve,

    We don't have a full C# sample, but hopefully the following snippet will help you get started (it mirrors _tmain function from C++ sample):

    KinectAudioSource audio = new KinectAudioSource();
    audio.SystemMode = SystemMode.OptibeamArrayAndAec;
    
    short micIndex = -1;
    foreach (AudioDeviceInfo info in audio.FindCaptureDevices())
    {
      micIndex = info.DeviceIndex;
      break;
    }
    audio.MicrophoneIndex = micIndex;
    audio.SpeakerIndex = 0;
    
    Stream audioStream = audio.Start();
    
    // Read from stream

    Note that the snippet above does not perform error checking and also assumes default speaker device. If you have multiple speaker devices, you will need to do a managed wrapper around MMDevice API, or find a pre-existing open source managed wrapper that satisfies your needs. Maybe http://www.codeproject.com/KB/vista/CoreAudio.aspx will help you in this front.

    Eddy

     


    I'm here to help
    Monday, July 18, 2011 10:34 PM
  • Eddy,

    thank's for the help, I hadn't realised it was quite as straight forward as I couldn't see past all the C++ :-)

    One more area I'm a little confused about on the AEC functionality, 

    I note the following error message from the MicArrayEchoCancellation example.

    "You must be rendering sound through the speakers before you start recording in order to perform echo cancellation"

    Does that requirement occur just because of the use of AEC with recording ? or is it the same if I use AEC with Speech recognition?

    Is the requirement to have audio playing from the speakers , a continuous requirement.

    for example , can I have audio playing from the speakers just while the Kinect is initialising and then I'm ok?

    if I have audio playing from the speakers and the audio stops at some stage, will that cause problems?

    Is there any way to work-around the requirement to have audio playing from the start ?

    thanks again,

    Steve.

    Tuesday, July 19, 2011 3:36 PM
  • Steve,

    the echo that is being cancelled is echo from feedback loop between microphone and speaker device, which is why the AEC API may return errors/exception if you try to perform AEC processing with no sound coming out from speaker device. If the sound from microphone is being fed to speakers as you speak, rather than having a continuous source of sound, this should be enough to avoid problem. For the sake of the sample, though, we thought it would be easier to showcase AEC at work with the continuous background sound.

    As a corollary to this behavior, if you don't expect any sound to be coming out from speakers as you speak into microphone, then you don't need AEC, and in that case you will probably be better off just configuring noise suppression:

     

    audio.SystemMode = SystemMode.OptibeamArrayOnly;
    audio.FeatureMode = true;
    audio.NoiseSuppression = true;

     

    Hope this helps,
    Eddy

     


    I'm here to help
    Tuesday, July 19, 2011 9:41 PM
  •  

    Hi Eddy,

    I have an existing speech controlled Microsoft MediaCenter app that I'm adding Kinect to. So sometimes there will be music playing when I give a voice command and sometimes not. The AEC could be very benificial in this scenario as it seems to do a good job when I tested it using theMicArrayEchoCancellation sample in the SDK. I'll give it a try and see how I get on. Is it practical to turn the AEC on and off on the fly or would I need to reinitialise the KinectAudioSource each time?

    thanks,

    Steve. 

    Tuesday, July 19, 2011 10:10 PM
  • You shouldn't have to construct a new KinectAudioSource each time, but you would have to call KinectAudioSource.Stop(), set new parameters and then call KinectAudioSource.Start() again for the new parameters to take effect.

    Eddy


    I'm here to help
    Wednesday, July 20, 2011 10:03 PM