Placeholder-Software / Dissonance

Unity Voice Chat Asset
70 stars 5 forks source link

Push To Talk activation mode bug #139

Closed flashmandv closed 5 years ago

flashmandv commented 5 years ago

I just bough latest dissonance version from Unity store and tried it for Steam P2P. I managed to get it working, however VoiceBroadcastTrigger -> Activation mode -> Push To Talk does not work as expected.

I defined input axis and key F and when I press the F - it is OK, recording starts..However when I release the F key - the recording does NOT stop.

Any help is welcome. Thanks

martindevans commented 5 years ago

Can you reproduce this in the demo scene (either the SteamP2P demo scene, or any other network demo scene)? Do other activation modes (e.g. voice activated) work as expected?

If you have a look in Assets/Plugins/Dissonance/VoiceBroadcastTrigger.cs can you try putting the following debug logs (starting around line 288):

//Decide if we need to change state
var current = IsTransmitting;
var next = ShouldActivate(IsUserActivated());

//Apply state if changed
if (current != next)
{
    if (current)
    {
             Debug.Log("Stopping..."); // <------------------------------- Add this

            //Begin fade out (if it's not already fading to zero)
            if (Math.Abs(_activationFader.EndVolume) > float.Epsilon)
            {
                Debug.Log("fading..."); // <------------------------------- Add this
                _activationFader.FadeTo(0, (float)_activationFaderSettings.FadeOut.TotalSeconds);
            }

            //Stop transmitting once fade out is complete
            if (CurrentFaderVolume <= float.Epsilon)
            {
                Debug.Log("Stopped."); // <------------------------------- Add this
                CloseChannel();
            }
    }
    else
    {
        //Start transmitting
        OpenChannel();
    }

When you release the PTT key you should see this sequence:

flashmandv commented 5 years ago

Hello,

I haven't had chance to try this code yet. At the time I made simple workaround by checking KeyDown myself and GetComponent().enabled = isKeyDown; I'll try the demo scene too (hopefully today). Thanks

martindevans commented 5 years ago

Enabling/Disabling the broadcast trigger does work. If you're curious why this isn't a good long term solution it's because the trigger doesn't just cut off voice, it applies a soft fade out when the activation ends (e.g. user releases PTT key). Disabling the component simply slams the connection closed without the fade.

flashmandv commented 5 years ago

Thank you @martindevans I just added the debug lines and I noticed that it works OK. This time the recording stopped as it should. It is very strange why It did not worked for me before. Now everything is fine.

Maybe some other buggy code I had around this implementation affected it. Strange.


Anyway, one side question I want to ask: As I'm integrating Steam P2P withmy own server and Dissonance, I needed a way to see which player was talking to display loudspeaker icon.

I register handlers for: OnPlayerStoppedSpeaking and OnPlayerStartedSpeaking However I need to find the player by its CSteamID. I wanted to set DissonanceComms.LocalPlayerName for each player to be its CSteamID. It failed as I could not set it before DissonanceComms.Start() method is called. I made a workaround by modifying DissonanceComms, line 359 to be LocalPlayerName = SteamUser.GetSteamID().ToString();// guid;

Can you recommend any better way of doing this without modifying DissonanceComms class? I want to keep it upgrade-able from AssetStore (and not have it modified by me).

Lastly, I wonder how to get an event when I'm recording and sending voice (to display the loudspeaker icon for me as well).

Thank you! Great job making Dissonance!

martindevans commented 5 years ago

Now everything is fine.

I'll close this issue then, don't hesitate to re-open it if the problem re-occurs :)

It failed as I could not set it before DissonanceComms.Start() method is called.

I would set DissonanceComms to disabled in the editor, then have an initialisation script which does:

var comms = GetComponent<DissonanceComms>();
comms.LocalPlayerName = SteamUser.GetSteamID().ToString();
comms.enabled = true;

That way you should avoid the error.

I wonder how to get an event when I'm recording and sending voice

Try getting the player object for yourself and using those events:

var me = comms.FindPlayer(comms.LocalPlayerName);
me.OnStartedSpeaking += StartedEventHandler;
me.OnStoppedSpeaking += StoppedEventHandler;

More generally if you want to find out information about any specific player start with FindPlayer and that will probably have the information you need.

flashmandv commented 5 years ago

Thank you @martindevans It all works great. Cheers

Adjuvant commented 5 years ago

I'm having this issue in the editor (2019.1), with Forge Networking. Put in debugging code from previous comment:

//Apply state if changed
if (current != next)
{
    if (current)
    {
             Debug.Log("Stopping..."); // <------------------------------- Add this

            //Begin fade out (if it's not already fading to zero)
            if (Math.Abs(_activationFader.EndVolume) > float.Epsilon)
            {
                Debug.Log("fading..."); // <------------------------------- Add this
                _activationFader.FadeTo(0, (float)_activationFaderSettings.FadeOut.TotalSeconds);
            }

            //Stop transmitting once fade out is complete
            if (CurrentFaderVolume <= float.Epsilon)
            {
                Debug.Log("Stopped."); // <------------------------------- Add this
                CloseChannel();
            }
    }
    else
    {
        //Start transmitting
        OpenChannel();
    }

When you release the PTT key you should see this sequence:

  • Stopping...
  • fading...
  • \<half second delay>
  • Stopped.

Specifically, when pressing the PTT key the stream starts fine, but the debug statements do not show after releasing the PTT key. The debug statements only show when I click out of the Game context to the editor tabs or another windows app.

I've already been having to start the Comms object in disabled mode, I want human readable names for joining up datasets, so need to set the name manually then enable the comms object. Also I use multiple mics for the app, so need to set the dissonance ones manually on scene load. I use push to talk on the server to communicate to players in VR ( who use voice activation).

comms.enabled = false;
comms.LocalPlayerName = Globals.DissonanceName;
comms.MicrophoneName = AppSetting.Instance.dissonanceMic;

if(NetworkManager.Instance && NetworkManager.Instance.IsServer) 
{
            var bt = GetComponent<VoiceBroadcastTrigger>();
            bt.InputName = "PTT";
            bt.Mode = Dissonance.CommActivationMode.PushToTalk;
}        
comms.enabled = true;

My current hack is to use a negative key button in the input axis, but i still have to repeatedly mash that key to get it to switch off. Server runs at a stable 70FPS, so I don't think is missing key presses.

All the best, Tom

martindevans commented 5 years ago

The debug statements only show when I click out of the Game context to the editor tabs or another windows app.

Just to check I've understood this correctly:

Can you reproduce this behaviour in the demo scene at all? A simple reproduction would really help me work out the issue.

My current hack is to use a negative key button in the input axis

Assuming your PTT axis is set up to be 0 when not pressed this shouldn't have any effect. The code to check the button is:

Input.GetAxis(InputName) > 0.5f

So once the PTT button is released that (should be) false. Could you try logging the value of GetAxis every frame and seeing if it's somehow getting "stuck" at the wrong value?

martindevans commented 5 years ago

To make it easier for me to keep track of things (to make sure I don't lose this issue!), I've moved this to a fresh issue: https://github.com/Placeholder-Software/Dissonance/issues/158

Adjuvant commented 5 years ago

Sorry Martin, this one was me. The PTT Axis "gravity" was set to zero, so press was just an accumulator. System works fine. Thanks for the prompt response, really helped resolve my issue!

martindevans commented 5 years ago

Excellent, glad we got that one fixed quickly :)

Adjuvant commented 5 years ago

Me too, first batch of user testing is tomorrow 8-/