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

  • JohnTube
    JohnTube ✭✭✭✭✭
    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 ✭✭✭✭✭
    edited August 2021
    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;
            }
    
  • @JohnTube Hi, thanks for all, one question, How do I make it so that when I silence a player, the others don't hear it either, thank you very much.

  • Hi,

    You can do it in player's client. Since Photon Voice version 2.50, either set Recorder.TransmitEnabled to false to temporary pause the transmission or set Recorder.RecordingEnabled to false to stop the stream and audio capture.

    To transmit audio, you need both properties set to true.

  • How to stop transmitting the game sound to the recorder?

    I exactly need the functionality that is already been present in the sample project

    (Asset Name - Photon Voice 2

    Scene Name - DemoVoicePun-Scene)


    I tried to use the same in the fusion project but still the game sound(background music) is getting transmitted to other users. So what are the procedures that I should be taking care to avoid as such?