Microphone.devices is empty (out of nowhere) :(

I was having a lot of fun playing with the new Microphone feature. Then it stopped working. I rebooted, closed my projects, etc. but now Microphone.devices.Length = 0 no microphones are found.

Any ideas?

-Carmine

Anyone else experiencing this? It doesn’t seem to be reliable. I’d love for this to work!

Hey did you find a solution to this? I’m finding this problem after pressing play once, needing a reboot of unity to fix, not that fixing it is doing much good

Yes!

Had to do with getting permission for the microphone… I did something like this:

public IEnumerator RequestAuthorize()
{
requestPending = true;
yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
if (Application.HasUserAuthorization(UserAuthorization.Microphone))
{
InitMicrophone();
}
}

This should only need to be done for webplayer afaik. Check Unity - Scripting API: Application.RequestUserAuthorization

Carmine, you legend!

Yes, if you build for the web player, then subsequently every time you hit the play button in the EDITOR player it requires this microphone authentication step.

i.e. even though you are in the editor player, the name on the unity window title bar says ‘MyProj – WebPlayer’, and it does indeed require this permission, even to work in the editor player.

alternatively, just building onto a different platform, just the act of hitting the build button once with a different platform specified, means that now the editor player is virtualising that platform and the microphone would work as expected.

I guess the best plan would be to switch your build target to Windows or OSX, depend on which you are using.

PS is there a bug in here anyone?

Resurrecting this in case anyone else encounters the same issue I did and finds this thread via google. I was trying to use the Microphone while in the editor (ie. not in play mode). It works at first, but eventually fails because of a feature called “Output Suspension”. Output Suspension is a thing Unity does where it shuts off all audio devices in the editor if they haven’t been used for a while, so that Unity doesn’t prevent Windows from suspending/sleeping.

This is a problem when you’re trying to use the microphone as an input device in the editor, but luckily I figured out a solution. Obviously you could just turn off the Output Suspension feature, but a better solution is to re-enable the audio devices whenever you are trying to use the microphone. You’ll know there are no audio-devices because the list of available microphones will be zero length.

if(Microphone.devices.Length == 0)
{
    AudioSettings.Reset(AudioSettings.GetConfiguration());
}
2 Likes