locked
Microphone access

    Question

  • I have seen the win8 capture sample, but I was wanting to do something similar with the microphone..  Is this possible in win8?

     

    thanks

    Friday, September 16, 2011 9:28 PM

Answers

All replies

  • Audio capture is performed using the same WinRT object that was used for Video capture in the win8 capture sample you mentioned. To do audio only capture set the StreamingCaptureMode property to Audio:

    settings.StreamingCaptureMode = StreamingCaptureMode.Audio.

    Refer to scenario number 4 in the Win8 Capture sample for where you could make this modification.

    -Richard Fricks


    Monday, September 19, 2011 8:37 PM
  • thanks for the answer.  The other question I have, is there a way to monitor Microphone levels,  (for the purpose of using hands free voice detection?)  We have a voice server running to detect certain commands, and only want to record when the levels are above a certain threshold.

     

    thanks

    wes

    Tuesday, September 20, 2011 9:19 PM
  • In a C++ app, you can monitor microphone levels using the IAudioMeterInformation interface.  Something like this:

    #pragma comment( lib, "mmdevapi" )
    #include <mmdeviceapi.h>

    using namespace Windows::Media::Devices; 

    String^ id = MediaDevice::GetDefaultAudioCaptureId(AudioDeviceRole::Console);

    hr = ::ActivateAudioInterface(id->Data(), __uuidof(IAudioMeterInformation), (void**)&pAudioMeterInformation);

    There's a known bug where ActivateAudioInterface's calling convention is not specified (it should be __stdcall.)  You can work around that by modifying the default calling convention for the project to __stdcall:

    Project Properties | Configuration Properties | C/C++ | Calling Convention - change to __stdcall (/Gz)

    Or you can declare ActivateAudioInterface manually:

    extern "C" HRESULT __stdcall ActivateAudioInterface(_In_ PCWSTR pwstrDeviceInterfaceInstanceId,
                                   _In_ REFIID iid,
              _Outptr_ void** ppInterface);


    Matthew van Eerde
    Tuesday, September 20, 2011 10:20 PM
  • Tuesday, September 20, 2011 10:28 PM
    Moderator
  • Thanks Maurits,

    If I have to use C++ I will, but was hoping for something more javascripty, but Frank's solution seems like he misunderstood, I want to monitor sound, not set microphone levels, which seems to be what volumePercent will get me. 

    Tuesday, September 20, 2011 10:43 PM
  • I believe AudioDeviceController.VolumePercent allows you to turn the volume up and down, not monitor the level of the sound coming in to the microphone.  (Of course, if you turn the volume up or down, that may impact the level of the sound.)


    Matthew van Eerde
    Tuesday, September 20, 2011 10:43 PM
  • Hi Wes,

    Do you want to take the sound received via the mic and analzye the level of the sound?

     

    thanks

    Frank

    Tuesday, September 20, 2011 11:31 PM
    Moderator
  • yes, thats exactly it Frank.  Making some progress, but SLOWWWWLY ;) If anyone has any tips, much appreciated.

     

    wes

    Wednesday, September 21, 2011 9:17 PM
  • actually Mauritis,  __uuidof(IAudioMeterInformation), gives a compiler error, stating no GUID id exists for this object.

     

    wes

    Wednesday, September 21, 2011 9:34 PM
  • Sorry, I was incorrect: IAudioMeterInformation is available for classic apps only, not for Metro apps.
    Matthew van Eerde
    Thursday, September 22, 2011 12:38 AM
  • Hi Wes,

    I discussed your issue with our media team and they said you would calculate the RMS values yourself.

    thanks

    Frank

    Thursday, September 22, 2011 6:02 PM
    Moderator