Search Unity

Audio How to switch microphones?

Discussion in 'Audio & Video' started by xyc1993, Mar 19, 2018.

  1. xyc1993

    xyc1993

    Joined:
    Dec 10, 2017
    Posts:
    2
    Hi! So I have several microphones connected to my PC and I would like to be able to switch between them. Unity detects those several devices but only uses the default Windows recording device no matter what. What should I do? Here's my switching method:


    Code (CSharp):
    1. void SwitchMicrophone(int microphoneID)
    2. {
    3. audioSource.Stop();
    4. Microphone.End(microphoneName);
    5.  
    6. microphoneName = Microphone.devices[microphoneID].ToString();
    7.  
    8. Microphone.GetDeviceCaps(microphoneName, out minFreq, out maxFreq);
    9.  
    10. audioSource.clip = Microphone.Start(microphoneName, true, 1, micFrequency);
    11. while (!(Microphone.GetPosition(microphoneName) > 0)) { }
    12. audioSource.Play();
    13. }