Photon Voice - Stop listening

According to the docs of Photon Voice you just have to set Recorder.TransmitEnabled to true or false in order to mute or use it for push-to-talk. But it seems it will also stop to listen. Question is how do I disable talking but still listening or vice-versa?

Comments

  • Hi @ShuinDev,

    Thank you for choosing Photon and sorry for the delay (I was on vacation).

    Recorder.TransmitEnabled does not have any effect on incoming audio: it does not stop listening.
    It only disables transmitting audio.
  • Just to confirm how do I stop listening?
  • JohnTube
    JohnTube mod
    edited August 16
    Hi @ShuinDev,

    If you are asking about how to mute:

    We rely on Unity's AudioSource component for audio playback, so to mute you need to set the volume to 0: audioSource.volume = 0f; or audioSource.mute = true,
    In Photon Voice we use an AudioSource per Speaker, so you can get the AudioSource from the Speaker:
    AudioSource audioSource = speaker.GetComponent<AudioSource>();
    We use a Speaker per incoming remote voice stream.
    If you use PUN integration, you can get Speaker from PhotonVoiceView:
    Speaker speaker = photonVoiceView.SpeakerInUse;
    you may need to check if photonVoiceView.IsSpeaker first.

    If you want to mute a specific player and know the PhotonView for the voice object:
    bool MutePlayer(Player player, PhotonView photonView){
        if (player != null && photonView){
          if (player == photonView.Owner){
            PhotonVoiceView photonVoiceView = photonView.GetComponent<PhotonVoiceView>();
            if (photonVoiceView && photonVoiceView.IsSpeaker){
              AudioSource audioSource = photonVoiceView.SpeakerInUse.GetComponent<AudioSource>();
              audioSource.mute = true;
              //audioSource.volume = 0f;
              return true;
            }
          }
        }
        return false;
    }
    
    If you want to mute a specific player and don't know which PhotonVoiceView or PhotonView:
    public bool ToggleMutePlayer(Player player, bool mute){
                if (player != null)
                {
                    int actorNr = player.ActorNumber;
                    for(int viewId = actorNr * PhotonNetwork.MAX_VIEW_IDS + 1; viewId < (actorNr + 1) * PhotonNetwork.MAX_VIEW_IDS; viewId++)
                    {
                        PhotonView photonView = PhotonView.Find(viewId);
                        if (photonView /*&& (photonView.OwnerActorNr == actorNr || photonView.ControllerActorNr == actorNr)*/)
                        {
                            PhotonVoiceView photonVoiceView = photonView.GetComponent<PhotonVoiceView>();
                            if (photonVoiceView && photonVoiceView.IsSpeaker){
                                AudioSource audioSource = photonVoiceView.SpeakerInUse.GetComponent<AudioSource>();
                                audioSource.mute = mute;
                            }
                        }
                    }
                }
                return false;
            }