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?