Home

Awesome

What Is This?

This is a native binary that allows Unity developers to ask Windows what is the currently default microphone. Currently Unity doesn't seem to support this, so I wrote this wrapper that asks Windows directly. This is useful for users who have a computer with more than one microphone and they can set it through the SteamVR audio preferences or Windows Audio Controls. PS: I wrote this specifically for VR, but it works just fine for regular Windows apps too.

How To Get Started

    [DllImport("UnityMicLister", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
    private static extern uint GetDefaultMicrophoneName(out IntPtr argument);

    /// <summary>
    /// Gets the friendly name of the microphone that SteamVR has set as the default
    /// </summary>
    /// <returns>null if none found, otherwise it's the name of the default microphone</returns>
    public static string DefaultMicrophoneName()
    {
        IntPtr argument;
        uint result = GetDefaultMicrophoneName(out argument);

        if (result == 0)
        {
            string micName = Marshal.PtrToStringUni(argument);
            return micName;
        }
        else
        {
            Debug.LogError("Failed to query windows for the default microphone");
            return null;
        }
    } 

License

MIT License