Search Unity

Bug Audiosource (microphone) stops working after 10 seconds but it's set to last 1h

Discussion in 'Audio & Video' started by Nachtcode, Sep 28, 2022.

  1. Nachtcode

    Nachtcode

    Joined:
    Sep 26, 2022
    Posts:
    1
    Hello everyone reading this, i am currently having an issue with my code. I am working on a game, where you control the character with the loudness of your voice. After working on it for a while i got everything to work fine on my pc. But when i sent it to two friends to test it, on one computer the microphone didn't even react and on the other one it worked fine for like 10-20 seconds and then stopped working again (both laptops with just the built in microphone). Has anyone else had this issue?
    This is the code i use for the microphone
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         InvokeRepeating("MicToAudioClip", 0, 3600);
    4.      
    5.     }
    Code (CSharp):
    1.     void MicToAudioClip()
    2.     {
    3.             audioSource = GetComponent<AudioSource>();
    4.             audioSource.clip = Microphone.Start(Microphone.devices[0], true, 3600, AudioSettings.outputSampleRate);
    5.             audioSource.Play();
    6.     }
    Does anyone have an idea what could have gone wrong?