Microphone.Start is not opening the correct microphone?

I have some simple code that lists the available microphones and then allows me to chose based on the index of an array of names generated by calling Microphone.devices.

I am having difficulty though and no matter which device I provide when calling Microphone.Start it always opens my Vive USB mic. The only way I can switch mics is to disable them in Windows.

public string Device
{
    get { return device; }
    set
    {
        if (value != null && !Microphone.devices.Contains(value))
        {
            Debug.LogError(value + " is not a valid microphone device");
            return;
        }
        device = value;
    }
}

void StartMic() {
    /*    
    foreach (string dev in Microphone.devices) {
        print (dev);
    }
    //Prints:
    //Microphone (5- USB Audio Device)
    //Microphone (High Definition Audio Device)
    */

    int minFreq;
    int maxFreq;
    Device = Microphone.devices [0]; //NO MATTER WHAT VALUE IS SPECIFIED IT WILL ALWAYS OPEN THE "Microphone (5- USB Audio Device)" DEVICE
    Microphone.GetDeviceCaps(Device, out minFreq, out maxFreq);

    recordFrequency = minFreq == 0 && maxFreq == 0 ? 44100: maxFreq;
    recordSampleSize = recordFrequency / (targetFrequency / targetSampleSize);
    sampleBuffer = new float[recordSampleSize];

    clip = Microphone.Start(Device, true, 1, recordFrequency);
    if (clip) {
        //Do Stuff
    } else {
        Debug.LogError ("Could not start microphone device." + clip);
    }
}

For some reason I can only open the first device on the list. And attempts to open other devices result in the default still being used.

Using Unity 2017.3.0f3 on Windows 8.1 x64

Any ideas?

2 Likes

It appears to be a Unity bug. Only the default audio recording device can record the audio. What is more, if you change the default recording device, you’ll need to restart the Unity before Unity recognises the new default recording device.

1 Like