Detect when user is talking with VoiceDetection

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.

Detect when user is talking with VoiceDetection

BFX
2020-04-10 12:51:35

I've activated VoiceDetection and regulated the threshold accordingly. It works well, I can clearly hear my voice being transmitted when talking and transmission being put on hold during silence. However, I need to fire some events connected to when the user is talking and I'm not able to do so.

These are my current Recorder settings --> https://ibb.co/K6wHLmg

And this is the code I'm using to detect when the user is talking:

public class VoiceEvents : MonoBehaviour  
{  
    Recorder recorder;  
    PhotonVoiceView voiceView;

    // Start is called before the first frame update  
    void Start()  
    {  
        // Audio is not transmitted by default  
        recorder = GetComponent<Recorder>();  
        voiceView = GetComponent<PhotonVoiceView>();  
        // recorder.TransmitEnabled = false;  
    }

    // Update is called once per frame  
    void Update()  
    {

        if (recorder.TransmitEnabled) {  
            Debug.Log("Talking");  
        } else {  
            Debug.Log("Silence");  
        }  
    }  
}

My log is showing "Talking" all the time even during silence.

My Stack:

- Unity3D 2019.3  
- Oculus Quest  
- PUN2 Free - 2.17.1  
- Photon Voice FREE 1.23

Comments

JohnTube
2020-04-12 09:16:00

Hi @BFX,

Make sure Photon Voice version is correct!
It should be 2.15 and not 1.23.

You could use Recorder.VoiceDetector.Detected or Recorder.VoiceDetector.OnDetected.
Or Recorder.IsCurrentlyTransmitting.

By the way, you could get the Recorder in use from PhotonVoiceView.RecorderInUse.

BFX
2020-04-15 19:27:04

Thanks a lot. We updated it and using Recorder.IsCurrentlyTransmitting. Now it's working well.

Back to top