Change microphone device using script

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Voice.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Change microphone device using script

GarvGoel_77
2020-06-15 09:14:02

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
2020-06-15 12:05:03

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.

<s>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);
</s>

GarvGoel_77
2020-06-18 05:34:44

Thank you !!!

GarvGoel_77
2020-06-18 05:36:58

Starting microphone failed: "Error initializing output device. " (60)............I am getting this error.Can you help me with this error

JohnTube
2020-06-19 14:16:25

See my post here.

GarvGoel_77
2020-07-24 10:56:37

@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
2020-07-27 13:33:11

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.

Back to top