iOS audio cutting out...

I'm experiencing an issue where after connecting to voice on an iOS device, all of the audio within unity cuts out and doesn't come back (even after disconnecting from voice). Things that I've tried are:
  • Using both unity microphone and photon microphone
  • Adding the WebRtcAudioDsp component to the recorder game object
  • Adding the IOSAudioForceToSpeaker component to the recorder game object

I have tested on other platforms (windows and android) and haven't experienced any problems. This is only happening on device and not in editor. I'm using v2.21 on Unity 2019.4.10f1.

Thanks.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @BrendanGMG,

    Thank you for choosing Photon!
    all of the audio within unity cuts out and doesn't come back (even after disconnecting from voice)
    you mean even audio not related to Photon Voice like background music or sound effects?
    Does this happen with the demo scenes we have in the package imported in a new fresh clean empty project?
    Did you try a different Unity version?
    What iOS (device/model and OS version) did you reproduce this on?

    Maybe you are muting sounds somehow or pausing audio in Unity?
    even after disconnecting from voice
    Do you still have Recorder components? destroy, disable (Recorder.RecordOnlyWhenEnabled = true) or stop recording (Recorder.IsRecording = false, Recorder.StopRecording) and see if it fixes things.
    Otherwise (keep Recorder(s)) but try Recorder.RestartRecording(true) or Recorder.ResetLocalAudio().
    Things that I've tried are:
    • Using both unity microphone and photon microphone
    • Adding the WebRtcAudioDsp component to the recorder game object
    • Adding the IOSAudioForceToSpeaker component to the recorder game object
    Thanks for trying these but let's keep it simple:
    - Let's try with Unity microphone type first THEN switch to Photon microphone type.
    - No need to add WebRtcAudioDsp (it's unrelated)
    - No need to use IOSAudioForceToSpeaker, it will probably be removed from the package as this workaround is now supported in full by Unity for Unity microphone type and by native plugin for Photon microphone type.
  • @JohnTube Thanks. I think I've figured it out.

    The solution was:
    • Use Photon microphone
    • Don't add the WebRtcAudioDsp component
    • Don't add the IOSAudioForceToSpeaker component
    • Add the following code after generating the Recorder component:
    var iosoptions = new Photon.Voice.IOS.AudioSessionCategoryOption[]
    {
    	Photon.Voice.IOS.AudioSessionCategoryOption.DefaultToSpeaker,
    	Photon.Voice.IOS.AudioSessionCategoryOption.AllowBluetooth
    };
    recorder.SetIosAudioSessionParameters(Photon.Voice.IOS.AudioSessionCategory.PlayAndRecord, Photon.Voice.IOS.AudioSessionMode.VoiceChat, iosoptions);
    
  • @JohnTube I'm having another issue now with IOS. After setting up photon voice, all of the game's audio goes quiet and it doesn't reset to it's normal volume, even after disconnecting from photon completely. I tried undoing what I did above by calling this:
    var iosoptions = new Photon.Voice.IOS.AudioSessionCategoryOption[]
    {
    	Photon.Voice.IOS.AudioSessionCategoryOption.DefaultToSpeaker,
    	Photon.Voice.IOS.AudioSessionCategoryOption.AllowBluetooth
    };
    _voiceConnection.PrimaryRecorder.SetIosAudioSessionParameters(Photon.Voice.IOS.AudioSessionCategory.PlayAndRecord, Photon.Voice.IOS.AudioSessionMode.Default, iosoptions);
    

    I'm not sure if these are the default values or not, but it doesn't make a difference. Any ideas what would cause this to happen?
  • I've also noticed that the orange dot (indicating the mic is on) stays on after PhotonVoiceConnection.Disconnect(). Here's the logs when disconnecting:
    2:12:27 PM LOG: [NetworkConnection_stag_CustomLobby.Recorder] 2020-10-20T03:12:27:Changing iOS
    audioSessionParameters = category = PlayAndRecord, mode = Default, options = [DefaultToSpeaker,
    AllowBluetooth]
    Photon.Voice.Unity.Recorder:SetIosAudioSessionParameters(AudioSessionCategory, AudioSessionMode,
    AudioSessionCategoryOption[])
    NetworkConnection:DisconnectVoice()
    NetworkConnection:OnDestroy()
    
    2:12:27 PM LOG: [NetworkConnection_stag_CustomLobby.PhotonVoiceNetwork] 2020-10-20T03:12:27:
    RemoteVoiceRemoved channel 0 player 5 voice #1 userData ebxjfLyuzH
    Photon.Voice.Unity.<>c__DisplayClass85_0:b__0()
    System.Action:Invoke()
    Photon.Voice.RemoteVoice:removeAndDispose()
    Photon.Voice.VoiceClient:clearRemoteVoicesInChannel(Int32)
    Photon.Voice.LoadBalancingTransport:onStateChangeVoiceClient(ClientState, ClientState)
    System.Action`2:Invoke(T1, T2)
    Photon.Realtime.LoadBalancingClient:Disconnect(DisconnectCause)
    NetworkConnection:DisconnectVoice()
    NetworkConnection:OnDestroy()
    
    2:12:27 PM LOG: [PV] Remote voices for channel 0 cleared
    Photon.Voice.VoiceClient:clearRemoteVoicesInChannel(Int32)
    Photon.Voice.LoadBalancingTransport:onStateChangeVoiceClient(ClientState, ClientState)
    System.Action`2:Invoke(T1, T2)
    Photon.Realtime.LoadBalancingClient:Disconnect(DisconnectCause)
    NetworkConnection:DisconnectVoice()
    NetworkConnection:OnDestroy()
    
    2:12:27 PM LOG: [PV] Local AudioOpus v#1 ch#0 removed
    Photon.Voice.Unity.Recorder:RemoveVoice(Boolean)
    
    2:12:27 PM LOG: [PV] Local AudioOpus v#1 ch#0 removed
    Photon.Voice.Unity.Recorder:RemoveVoice(Boolean)
    
    2:12:27 PM LOG: [PV] Local AudioOpus v#1 ch#0 removed
    Photon.Voice.Unity.Recorder:RemoveVoice(Boolean)
    
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @BrendanGMG,

    the default value is the Game preset:
    private IOS.AudioSessionParameters audioSessionParameters = IOS.AudioSessionParametersPresets.Game;
    

    which is defined as follows:
    public static AudioSessionParameters Game = new AudioSessionParameters()
            {
                Category = AudioSessionCategory.PlayAndRecord,
                Mode = AudioSessionMode.Default,
                CategoryOptions = new AudioSessionCategoryOption[] { AudioSessionCategoryOption.DefaultToSpeaker, AudioSessionCategoryOption.AllowBluetooth }
            };
    

    no need to call Recorder:SetIosAudioSessionParameters when disconnecting.
    no need to reset to default values, the values you set, either work for your use case or not.
    I'm experiencing an issue where after connecting to voice on an iOS device, all of the audio within unity cuts out and doesn't come back (even after disconnecting from voice).
    After setting up photon voice, all of the game's audio goes quiet and it doesn't reset to it's normal volume
    Looks like we're back to square one, to the initial problem.
    I think you need to call Recorder.StopRecording() or Recorder.IsRecording = false and not only Disconnect.
    I've also noticed that the orange dot (indicating the mic is on) stays on after PhotonVoiceConnection.Disconnect().
    Recording is independent from connection as it just makes use of the microphone even offline.
    Try calling Recorder.StopRecording() manually.
    if you have more than one Recorder component, stop recording from them all or destroy them all to force this.
    2:12:27 PM LOG: [PV] Local AudioOpus v#1 ch#0 removed
    Photon.Voice.Unity.Recorder:RemoveVoice(Boolean)
    

    why is this repeated 3 times?
    RemoteVoiceRemoved channel 0 player 5 voice #1 userData ebxjfLyuzH
    out of curiosity, do you make use of UserData somehow or is "ebxjfLyuzH" just a random dummy string you used for testing?