Suite Events

A few events have been integrated into portions of the SALSA LipSync Suite where it makes sense to provide a decoupled configuration of the Suite with your custom code.

Event Subscription

The events have been implemented as C# events and require the developer to subscribe and un-subscribe as necessary. Typically, subscription occurs in a wake-up action such as: Awake(), Start(), or (perhaps more preferably) OnEnable().

private void OnEnable()
{
    EventController.AnimationStarting += OnAnimationStarting;
}

Likewise, it is important to unsubscribe to subscribed events to prevent system errors. This is typically performed in the OnDisable() component action.

private void OnDisable()
{
    EventController.AnimationStarting -= OnAnimationStarting;
}

NOTE: There are two template files in the Examples > Scripts folder (SALSA_Template_EventControllerSubscriber, SALSA_Template_SalsaEventSubscriber) that demonstrate how the events can be used. The demo boxhead scene also implements the SALSA events template, writing to the console when SALSA starts/stops SALSAing.
The SALSA event template component simply needs to be dropped on an object and linked to a SALSA component -- this simple template will then write to the console as the SALSA processing state changes. The EventController event template operates similarly -- add the component to any game object. To configure it, simply enter the EventIdentifier string that matches the controller configuration. It will subscribe to the EventController events and filter delegate processing according to the identifier string.

Available Events

There are currently two event sets to subscribe to, one in the Salsa class and the other in the EventController class. Details for each of the events are as follows:

SALSA Events

Two events have been implemented for SALSA and these emit the status of whether or not SALSA has started "talking" (Salsa.IsSALSAing == true) or has stopped "talking" (Salsa.IsSALSAing == false). The difference between using the event notifications and the Salsa.IsSALSAing property is the decoupled state and active notification. Subscribing to either event receives a passive notification of the "talking" state of SALSA, whereas with the Salsa.IsSALSAing property, active polling of the property is required to obtain the current state, but not when the state started. See the included sample template (SALSA_Template_SalsaEventSubscriber) for an implementation example. Simply drop this script component on any object and link a SALSA instance to it.

NOTE: The sensitivity of the SALSA processing events is controlled via the same mechanism as the Salsa.IsSALSAing property. To adjust the sensitivity of the silence measurement, increase the threshold to give SALSA more time to wait for non-silence and reduce the threshold to increase sensitivity. The lowest usable value for the Silence Threshold is 1, equating to one UpdateDelay cycle.
events salsa sensitivity

SALSA Started Salsaing (Talking)

event Salsa.StartedSalsaing

This event will fire when Salsa no longer detects silence from audio analysis (internally calculated or externally provided). This event is immediate upon the first detection of a viseme being triggered. It will only be fired once while Salsa is Salsaing and will not be fired again until non-silences is detected again after Salsa has stopped Salsaing.

SALSA Stopped Salsaing

event Salsa.StoppedSalsaing

The Salsa.StoppedSalsaing event fires when the appropriate threshold of silence has been reached. The sensitivity of StoppedSalsaing is adjusted using the same mechanism as the Salsa.IsSALSAing property. This event will only fire once and will not be fired again until silence is detected again after Salsa has started Salsaing.

SALSA Viseme Triggered

event Salsa.VisemeTriggered

The Salsa.VisemeTriggered event fires after audio analysis occurs and trigger parsing has determined the correct trigger value to use. Please see the SALSA API documentation for the TriggeredIndex property. The triggered index is available in the event arguments as SalsaNotificationArgs.eventTrigger. See the code snippet below for an example use.

using CrazyMinnow.SALSA;
using UnityEngine;

public class SALSA_Template_SalsaVisemeTriggerEventSubscriber : MonoBehaviour
{
    // Link the required SALSA instance for identification in the event callback.
    [SerializeField] private Salsa salsaInstance;

    private void OnEnable()
    {
        // subscribe to the event
        Salsa.VisemeTriggered += SalsaOnVisemeTriggered;
    }

    private void OnDisable()
    {
        // unsubscribe from the event
        Salsa.VisemeTriggered -= SalsaOnVisemeTriggered;
    }

    private void SalsaOnVisemeTriggered(object sender, Salsa.SalsaNotificationArgs e)
    {
        // compare the event instance with the linked SALSA instance.
        if (e.salsaInstance == salsaInstance)
        {
            // do something...
            Debug.Log("Viseme triggered: " + e.visemeTrigger);
        }
    }
}

EventController Events

The EventController is a new Suite animation controller type, which fires events at the start and finish of each animation timing cycle (ON/OFF). The events correspond to the ON animation 'starting' and 'finishing' and are followed by the OFF animation 'starting' and 'finishing'. There are no events for the HOLD cycle since the HOLD cycle begins immediately as the ON cycle finishes and ends immediately as the OFF cycle begins. The events are designated as follows (please also refer to the following diagram):

animation cycle diagram

Animation in the 'ON' Direction

event EventController.AnimationStarting

When an animation is registered to turn ON with the QueueProcessor, it officially begins the ON cycle and this is where the AnimationStarting event fires. Refer to #1 in the above diagram.

event EventController.AnimationON

Once an animation has reached its max extent and animation ON time, it is considered 'ON' and either is removed from the Queue (if it is a OneWay handler) or begins the wait for the HOLD timing. This is the point where the AnimationON event fires. This event may also be fired if an ON animation is interrupted by an OFF registration. Refer to #2 in the above diagram.

Animation in the 'OFF' Direction

event EventController.AnimationEnding

An animation begins its OFF phase in one of two situations. 1) The HOLD timing expires, or 2) A OneWay handled animation is registered to turn OFF with the QueueProcessor. When either of these two possibilities occur, the AnimationEnding event is fired. Refer to #3 in the above diagram.

event EventController.AnimationOFF

Once an animation completes its transition to the min extent, the AnimationOFF event fires. This event may also be fired if an OFF animation is interrupted with an ON registration. Refer to #4 in the above diagram.

For more information on animation timings, please see Notes On Animation Timings.