Photon Voice - Stop listening

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.

Photon Voice - Stop listening

ShuinDev
2021-07-31 22:46:13

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
2021-08-09 14:42:19

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.

ShuinDev
2021-08-16 06:03:24

Just to confirm how do I stop listening?

JohnTube
2021-08-16 09:28:52

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();
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;  
        }

stalinfcc96
2022-12-01 16:52:37

@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.

vadim
2022-12-02 13:46:39

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.

bn_adc
2023-07-29 06:30:44

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?

Back to top