Search Unity

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

Discussion in 'Editor & General Support' started by carmine, Mar 2, 2012.

  1. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    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
     
  2. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    Anyone else experiencing this? It doesn't seem to be reliable. I'd love for this to work!
     
  3. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    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
     
  4. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    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();
    }
    }
     
  5. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
  6. Pi_3-14

    Pi_3-14

    Joined:
    May 9, 2012
    Posts:
    168
    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?
     
  7. MattRix

    MattRix

    Joined:
    Aug 23, 2011
    Posts:
    121
    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.

    Code (CSharp):
    1. if(Microphone.devices.Length == 0)
    2. {
    3.     AudioSettings.Reset(AudioSettings.GetConfiguration());
    4. }
     
    VRC_Truce likes this.