Change microphone device using script

Options
Recorder.UnityMicrophoneDevice. .......please help how to change microphone device using script at runtime with Recorder.UnityMicrophoneDevice....... I am not able to write a code....

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2020
    Options
    Hi @GarvGoel_77,

    to set default Unity mic (which is default so not needed unless it has been changed already before and want to revert to default), both lines do the same thing:
    recorder.UnityMicrophoneDevice = null;
    recorder.UnityMicrophoneDevice = Microphone.devices[0];
    
    otherwise:
    recorder.UnityMicrophoneDevice = Microphone.devices[unityMicrophoneDeviceIndex];
    

    EDIT: UPDATE: issue mentioned below FIXED in Photon Voice 2.18.
    there is an issue with the custom Recorder editor currently (the value you explicitly set in recorder.UnityMicrophoneDevice will be reverted to whatever is set in editor), in "Assets\Photon\PhotonVoice\Code\Editor\RecorderEditor.cs", replace:


    this.unityMicrophoneDeviceIndex = EditorGUILayout.Popup("Microphone Device", this.unityMicrophoneDeviceIndex, Microphone.devices);
    
    with
    if (this.unityMicrophoneDeviceIndex >= 0 && this.unityMicrophoneDeviceIndex < Microphone.devices.Length && 
                                            !Recorder.CompareUnityMicNames(Microphone.devices[this.unityMicrophoneDeviceIndex], this.recorder.UnityMicrophoneDevice) || !Recorder.IsDefaultUnityMic(this.recorder.UnityMicrophoneDevice))
                                        {
                                            int newIndex = Array.IndexOf(Microphone.devices, this.recorder.UnityMicrophoneDevice);
                                            if (newIndex >= 0)
                                            {
                                                this.unityMicrophoneDeviceIndex = newIndex;
                                            }
                                        }
                                        this.unityMicrophoneDeviceIndex = EditorGUILayout.Popup("Microphone Device", this.unityMicrophoneDeviceIndex, Microphone.devices);
    
  • GarvGoel_77
    Options
    Thank you !!!
  • GarvGoel_77
    Options
    Starting microphone failed: "Error initializing output device. " (60)............I am getting this error.Can you help me with this error
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    See my post here.
  • GarvGoel_77
    Options
    JohnTube wrote: »
    Hi @GarvGoel_77,

    to set default Unity mic (which is default so not needed unless it has been changed already before and want to revert to default), both lines do the same thing:
    recorder.UnityMicrophoneDevice = null;
    recorder.UnityMicrophoneDevice = Microphone.devices[0];
    
    otherwise:
    recorder.UnityMicrophoneDevice = Microphone.devices[unityMicrophoneDeviceIndex];
    

    there is an issue with the custom Recorder editor currently (the value you explicitly set in recorder.UnityMicrophoneDevice will be reverted to whatever is set in editor), in "Assets\Photon\PhotonVoice\Code\Editor\RecorderEditor.cs", replace:
    this.unityMicrophoneDeviceIndex = EditorGUILayout.Popup("Microphone Device", this.unityMicrophoneDeviceIndex, Microphone.devices);
    
    with
    if (this.unityMicrophoneDeviceIndex >= 0 && this.unityMicrophoneDeviceIndex < Microphone.devices.Length && 
                                            !Recorder.CompareUnityMicNames(Microphone.devices[this.unityMicrophoneDeviceIndex], this.recorder.UnityMicrophoneDevice) || !Recorder.IsDefaultUnityMic(this.recorder.UnityMicrophoneDevice))
                                        {
                                            int newIndex = Array.IndexOf(Microphone.devices, this.recorder.UnityMicrophoneDevice);
                                            if (newIndex >= 0)
                                            {
                                                this.unityMicrophoneDeviceIndex = newIndex;
                                            }
                                        }
                                        this.unityMicrophoneDeviceIndex = EditorGUILayout.Popup("Microphone Device", this.unityMicrophoneDeviceIndex, Microphone.devices);
    



    Same problem is with the photon part of the recorder, the scrollview doesnot update when we change the microphone device from the script.
    Can you please give me code for that also??...Please!
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @GarvGoel_77,

    I don't understand what you need or what you want?

    What does a ScrollView have anything to do here?

    What is the expected behaviour and actual behaviour?

    Why do you need to change the microphone in the first place, maybe just use default one.