Search Unity

Audio Microphone Audio is Silent

Discussion in 'Audio & Video' started by Lanre, Dec 1, 2019.

  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,970
    Hi all.

    For some reason Unity's Microphone API is producing dead silent audio. You can use this script and monitor the VU meter in the editor:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Mic : MonoBehaviour {
    4.  
    5.     void Start () {
    6.         // Create audio source
    7.         var audioSource = gameObject.AddComponent<AudioSource>();
    8.         audioSource.loop = true;
    9.         audioSource.bypassEffects =
    10.         audioSource.bypassListenerEffects = false;
    11.         // Start microphone
    12.         audioSource.clip = Microphone.Start(null, true, 10, AudioSettings.outputSampleRate);
    13.         audioSource.Play();
    14.     }
    15.  
    16.     void OnAudioFilterRead (float[] data, int channels) { } // This will display a VU meter in the editor
    17. }
    Any ideas? Also, I should note that I am the developer of NatMic API which is an alternative for Unity's Microphone API. But I still would like Unity's mic API to work.
     
  2. TimeWalk-org

    TimeWalk-org

    Joined:
    Nov 3, 2014
    Posts:
    38
    If you are on a Mac running OS 10.14 (or above), it is likely that Unity (and Unity Hub) have not been given microphone access permission. In theory, Unity Hub should ask for permission (once), but it does not appear to do this. I am running Unity 2019.3f1 and encountering this issue. Continuing to look for a solution... https://developer.apple.com/documen...tion_for_media_capture_on_macos?language=objc

    See also https://www.reddit.com/r/MacOS/comments/blagtd/mojave_blocking_mic_input_and_not_prompting_to/
     
    Last edited: Dec 3, 2019
    Lanre likes this.
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,970
    I don't think it's a permissions issue. I'm running Unity 2018.3 on macOS 10.14.4. Unity is given microphone permissions and camera permissions. WebCamTexture works. And I just tested with NatMic, my microphone API, and that works too.
     
  4. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    you have to yield until microphone position is > 0 before calling `Play()`
    it's how their API works with some hw+drivers combination
     
    Lanre likes this.
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,970
    Looks like you're right. Thanks!
     
  6. TimeWalk-org

    TimeWalk-org

    Joined:
    Nov 3, 2014
    Posts:
    38
    I was able to fix my "silent microphone" problem by editing the tcc.db system file to add Unity Hub's permissions. For some reason, they were not appearing at all in the "System Preferences/Security & Privacy/Privacy/Microphone" access list.
    To edit tcc.db, I followed these instructions: https://www.reddit.com/r/Ring/comments/ciztw5/ring_macos_app_how_to_make_your_macs_microphone/, but substituted the following line in for Unity Hub (line 10 of the instructions):
    INSERT INTO access VALUES('kTCCServiceMicrophone','com.unity3d.unityhub',0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);
     
    visionnaireMedia and aihodge like this.
  7. Tibor-Udvari

    Tibor-Udvari

    Joined:
    Apr 1, 2015
    Posts:
    14
    I can confirm that the solution by TimeWalk-org works.
     
  8. DeadCastles

    DeadCastles

    Joined:
    Sep 23, 2019
    Posts:
    14
  9. Crazy-Minnow-Studio

    Crazy-Minnow-Studio

    Joined:
    Mar 22, 2014
    Posts:
    1,399
    Also confirmed as the issue and potential resolution. And since this is modifying system resources, everyone must determine their own course of action. Thanks @TimeWalk-org

    Issue exists with Unity Hub v2.3.0 with Catalina 10.15.3.
     
    Last edited: Apr 16, 2020
    Lanre likes this.
  10. robertslr

    robertslr

    Joined:
    Sep 24, 2015
    Posts:
    11
    I can confirm I was able to workaround this issue following the below steps.
    I'm using Mac OS Mojave 10.14.5.
    Unity 2019.02.0f1 , Unity Hub 2.3.0.

    Link : https://issuetracker.unity3d.com/is...-crashes-on-privacy-violation?page=2#comments (LAUNZONE 30, 2020 04:10)

    Comment:

    Hey everyone, I know that this is not ideal and unity or apple should come up with a better solution eventually but here is what works for me and is pretty sure to work for everyone that can't add microphone or camera permission to unity hub. It is kind of weird and you have to disable SIP (system integrity protection) for a couple of minutes to do it, so maybe read up on that first if you are worried (I was not).

    1) Disable SIP: Go into recovery mode (hold CMD+R when you restart your Mac) Don't be afraid, we are not doing anything crazy.

    2) After that open Terminal (it should be accessible from one of the Menus at the Top) Type in "csrutil disable" and hit enter. Then reboot your Mac normally.

    3) Open Terminal and type in: "sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db" and hit enter

    4) For microphone access, type in: "INSERT INTO access VALUES('kTCCServiceMicrophone','com.unity3d.unityhub',0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);" and hit enter

    For camera, type in: "INSERT INTO access VALUES('kTCCServiceCamera','com.unity3d.unityhub',0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);" and hit enter

    6) check in your SystemPreferences/Security&Privacy > unity hub should now show up in both mic and cam

    7) reboot in recovery mode again (CMD+R), open terminal again, type in: "csrutil enable" and hit enter, to enable SIP again

    8) reboot normally and enjoy!

    That's it! I hope it works for you. Don't forget the step 7, I think it is important for Security.
     
  11. Luzzo

    Luzzo

    Joined:
    Jan 25, 2020
    Posts:
    2
    Is Unity working to fix this at all? The solution above works beautifully but...

    This is a problem with MacOS apps exported from Unity as well. And I cannot ask the people who download my app to do this if they are on MacOS, it simply does not work.

    Any thoughts?
     
    MikeM1970 and ROBYER1 like this.
  12. Crazy-Minnow-Studio

    Crazy-Minnow-Studio

    Joined:
    Mar 22, 2014
    Posts:
    1,399
    I saw in the latest Hub release notes https://unity3d.com/hub/whats-new

    New Fixes

    * For Mac Catalina OS, Hub permissions are now passed for camera and other Unity Editor related features

    Don't know if that addressed the issue for the Editor and mic or not. Haven't tested it.
     
  13. Visible_Sounds

    Visible_Sounds

    Joined:
    Feb 5, 2019
    Posts:
    2
    Having the exact same issue on Windows.
     
    SassyPantsy and skooter500 like this.
  14. sbethge

    sbethge

    Joined:
    Mar 20, 2019
    Posts:
    16
    Doesn't seem like it was fixed, just had to still do it manually with 2.3.2 / Unity 2019.3.14f1.
    Also in case it's useful for someone, permissions for Unity Editor instead of Hub can be set like this.

    INSERT INTO access VALUES('kTCCServiceMicrophone','com.unity3d.UnityEditor5.x',0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);
     
    Last edited: May 28, 2020
  15. rkbodyandsoul

    rkbodyandsoul

    Joined:
    Jun 3, 2020
    Posts:
    1
    I resoved my issue with above code.
     
  16. HorizonsStudio

    HorizonsStudio

    Joined:
    May 29, 2018
    Posts:
    6
    I've still been finding this issue to be the case with Unity 2020.3.1f1, both when building from Cloud Build or locally from a Mac.

    I've also been finding slightly different behaviour across Mac OS versions. On Catalina and Big Sur, I'm finding that our built application does appear in the Camera and 'Files and Folders' sections of the Security & Privacy System Preferences, with the permission already granted (i.e. the box is ticked), but the App fails to initiate the camera or be able to access the file system.

    The solution I've found here is to
    1. 'uncheck' the box i.e. revoke the permission
    2. open and close the App
    3. 'check' the box
    That seems to fix things for Catalina and Big Sur users.

    Unfortunately for Mojave users, the App doesn't appear in the lists to begin with, so I'm going to attempt the fixes listed above.
     
  17. UnityXizor21

    UnityXizor21

    Joined:
    Jan 14, 2021
    Posts:
    36
    Has this process changed for M1 Apple hardware?

    I am not having success with Step 10.

    My Hardware / Software:

    Apple MacBook Air M1
    Unity 2021.3.3f1

    Failure occurs for me at Step 10 when entering into Terminal:
    INSERT INTO access VALUES('kTCCServiceMicrophone','com.unity3d.unityhub',0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,1541440109);

    I receive the following error from Terminal:
    Error: in prepare, table access has 13 columns but 12 values were supplied (1) sqlite>

    Is there a solution?
     
  18. denny_pep

    denny_pep

    Joined:
    May 18, 2023
    Posts:
    2
    Old thread, but having this issue on Windows now... microphone (via Focusrite audio interface) is recognized by the system, and in Ableton, and Unity sees it as an input, but no sound seems to be read. Anyone got any solutions?
     
  19. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    407
    Is it set as your default recording device in you sound configuration? I'm using a Focusrite too (Scarlett 2i2) and I have no problem recording audio in Unity.