private Gesture transformGesture(KeyFramedGesture gesture, float duration, float intensity) { List <Frame> frames = new List <Frame>(); for (int i = 0; i < gesture.keyFrameTimes.Count; i++) { Dictionary <string, dynamic> parameters = new Dictionary <string, dynamic>(); foreach (var kfParam in gesture.frames) { if (i > 0) { //Check if the previous keyframe was the same. If so there is no need to add the parameter. if (kfParam.keyFrameValues[i - 1] == kfParam.keyFrameValues[i]) { continue; } } parameters.Add(kfParam.param.ToString(), kfParam.keyFrameValues[i] * intensity); } frames.Add(new Frame(true, new List <float> { gesture.keyFrameTimes[i] * duration }, parameters)); } Gesture transformedGesture = new Gesture(gesture.name, frames); return(transformedGesture); }
/// <summary> ///Sends a text speech event to the synthesizer, adds an utterance to the speech queue and blocks the current thread until the speech is over /// </summary> /// <param name="text"> The text to speak </param> public void SayBlock(string toSay, KeyFramedGesture mood = null, Dictionary <string, string> keyValuePairs = null) { Say(toSay, mood, keyValuePairs); while (inMiddleOfSpeaking) { Thread.Sleep(50); } }
public void ChangeParameter(PARAMS parameter, float duration, float intensity, int priority = 0) { // Duration and priority will be set to one KeyFramedGesture changeParam = new KeyFramedGesture("Change " + parameter.ToString(), new List <float> { 1 }, new List <keyFramedPARAM> { new keyFramedPARAM(parameter, new List <float> { 1 }) }); //Call the gesture with the right duration and intensity Gesture(changeParam, priority, duration, intensity); }
/// <summary> ///Sends a text speech event to the synthesizer and adds an utterance to the speech queue /// </summary> public void Say(string text, KeyFramedGesture mood = null, Dictionary <string, string> keyValuePairs = null) { if (inMiddleOfSpeaking) { SayQueue.Enqueue(new Tuple <string, KeyFramedGesture, Dictionary <string, string> >(text, mood, keyValuePairs)); } else { if (mood != null) { Gesture(mood); CurrentMood = mood.name; } else { CurrentMood = null; } //midtextaction are divided by | if there is such separator we should process them var midTextActions = text.Split('|'); if (midTextActions.Count() > 1) { if (keyValuePairs != null) { text = replaceVariables(text, keyValuePairs); } FillMidTextActions(text); text = Regex.Replace(text, @"\|.*?\|", String.Empty); Say(text); SentSayEvent?.Invoke(text); } else { Say(text); SentSayEvent?.Invoke(text); } } }
public void SayDialogAct(string dialogAct, Dictionary <string, string> keyValuePairs = null) { Behavior behaviorToSay = dialogActs?.getRandomBehavior(dialogAct); if (behaviorToSay == null) { return; } KeyFramedGesture mood = null; if (GESTURES.customGestures.ContainsKey(behaviorToSay.emotion)) { mood = GESTURES.customGestures[behaviorToSay.emotion]; } if (behaviorToSay.customEvent != "") { CustomEvent?.Invoke(behaviorToSay.customEvent); } Say(behaviorToSay.text, mood, keyValuePairs); }
internal void GestureCustom(KeyFramedGesture gesture, int priority = 0, float duration = 0, float intensity = 0) { SendEvent(new ActionEvents.PerformCustomGesture(transformGesture(gesture, duration, intensity), priority)); }
/// <summary> /// Makes the agent perform a specific gesture. /// </summary> /// <param name="gesture"> The name of the gesture </param> public void Gesture(KeyFramedGesture gesture, int priority = 0, float duration = 1, float intensity = 1) { GestureCustom(gesture, priority, duration, intensity); }