Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Audio Microphone.Start() not working properly!

Discussion in 'Audio & Video' started by EIONtech1, Apr 14, 2020.

  1. EIONtech1

    EIONtech1

    Joined:
    Jun 28, 2019
    Posts:
    4
    I've been frustrated with this for months now, and I have read every forum and tried multiple solutions. Nothing is working! Maybe this is a bug? IDK...
    I am trying to have Unity playback microphone audio when the user presses a button. Then have the microphone stop "recording" to an audioclip once the button is pressed again. Sounds simple.
    I am using
    Code (CSharp):
    1. _audioSource.clip = Microphone.Start(chosenDevice, true, 10, maxFreq);

    From what I understand the "true" bool means that the audioclip will record over itself after 10 seconds has been reached. So in theory, real-time microphone playback.
    I use this to play the audio from the microphone:
    Code (CSharp):
    1. while (!(Microphone.GetPosition(null) > 0)) { }
    2.     Debug.Log("Start Mic(pos): " + Microphone.GetPosition(null));
    3.     _audioSource.Play();
    THE PROBLEM: The microphone starts playing like it should. Then after 10 seconds or so, the microphone stops recording. If the _audioSource.clip is set to loop, it just starts repeating the 10 seconds or so of the previously recorded AudioClip. After this happens you can no longer "record" with the mic.
    On windows, a microphone icon pops up in the tray when an application is using the microphone. When you first start the app and press the mic button to start microphone playback, the mic icon in the tray appears. After 10 seconds or so the mic icon disappears. When I try to start the mic back up, the mic icon appears for 1 second then disappears.

    Is anyone else having this issue or is it just me? Its so frustrating because it seems like it should be a simple thing! Even if I remove the while statement and just use _audioSource.Play(), it does the same thing.
     
  2. EIONtech1

    EIONtech1

    Joined:
    Jun 28, 2019
    Posts:
    4
    EDIT: Okay... This may be an issue with having mixers with effects on them active in the scene. I tried Microphone.Start() in a new clean project and it works perfectly. On my main project I have the microphone audiosource running through a mixer that is past to the Master that has Echo and Reverb on it.
    Could that be the issue? I have tried to disable both effects on main project and still the same problem... but that is the only thing I can think of at the moment.
     
    Last edited: Apr 24, 2020
  3. nyonge

    nyonge

    Joined:
    Jul 11, 2013
    Posts:
    49
    @EIONtech1 any updates here? Been hitting similar walls recently
     
  4. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    I have the same issue...
     
  5. harini

    harini

    Unity Technologies

    Joined:
    May 28, 2015
    Posts:
    45
    Hi,
    Can you please file a bug with a repro project so that we can take a look at it?

    Thanks and regards,
    Harini
     
  6. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Ended up using a third party because Microphone by unity is glitchy and has those looping issues.

    Works well with Natdevice asset on the asset store
     
  7. spuchals

    spuchals

    Joined:
    Sep 29, 2018
    Posts:
    8
    I've just found that the AudioMixer shows the AudioListener component is inactive when that happens.

    You can apparently disable 'Auto Mixer Suspend' on the AudioMixer asset in Project, which will disable that feature designed to save on processing power https://forum.unity.com/threads/audio-mixers-are-inactive.673120/

    upload_2022-5-6_13-8-56.png

    Also, in Edit > Project settings > Audio, you will have that option which could cause a similar issue, note that in Build it would work properly.

    upload_2022-5-6_12-50-21.png

    STILL...
    Now the AudioListener isn't inactive, but the issue persists... Muting/unmuting the microphone AudioSource (or disabling/enabling it, not sure which one) kinda solves the problem, but introduces a huge Latency... Maybe need to rerun a Setup of it's parameters then.
    Still... I can't find a way to detect when the AudioSource stops capturing and then resetup it by code.
     
    Last edited: May 6, 2022
  8. spuchals

    spuchals

    Joined:
    Sep 29, 2018
    Posts:
    8
    Setting the AudioSource of the Microphone to loop = true as well seems to fix the problem on top of the solution above.