From 4f7028ff0f577f8c67714f706fb9c780cfe4d78d Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 25 Oct 2019 14:05:29 -0700 Subject: [PATCH] DEV-2575: Automatically lower raised hand if talking --- .../simplifiedEmote/simplifiedEmote.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js b/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js index d7d6279e10..7ebbce4f58 100644 --- a/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js +++ b/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js @@ -217,6 +217,37 @@ function targetPointInterpolate() { } } + +function maybeClearInputAudioLevelsInterval() { + if (checkInputAudioLevelsInterval) { + Script.clearInterval(checkInputAudioLevelsInterval); + checkInputAudioLevelsInterval = false; + currentNumTimesAboveThreshold = 0; + } +} + + +var currentNumTimesAboveThreshold = 0; +var checkInputAudioLevelsInterval; +// The values below are determined empirically and may require tweaking over time if users +// notice false-positives or false-negatives. +var CHECK_INPUT_AUDIO_LEVELS_INTERVAL_MS = 200; +var AUDIO_INPUT_THRESHOLD = 130; +var NUM_REQUIRED_LEVELS_ABOVE_AUDIO_INPUT_THRESHOLD = 4; +function checkInputLevelsCallback() { + if (MyAvatar.audioLoudness > AUDIO_INPUT_THRESHOLD) { + currentNumTimesAboveThreshold++; + } else { + currentNumTimesAboveThreshold = 0; + } + + if (currentNumTimesAboveThreshold >= NUM_REQUIRED_LEVELS_ABOVE_AUDIO_INPUT_THRESHOLD) { + endReactionWrapper("raiseHand"); + currentNumTimesAboveThreshold = 0; + } +} + + function beginReactionWrapper(reaction) { maybeDeleteRemoteIndicatorTimeout(); @@ -246,6 +277,10 @@ function beginReactionWrapper(reaction) { Script.update.connect(targetPointInterpolate); targetPointInterpolateConnected = true; } + break; + case ("raiseHand"): + checkInputAudioLevelsInterval = Script.setInterval(checkInputLevelsCallback, CHECK_INPUT_AUDIO_LEVELS_INTERVAL_MS); + break; } } @@ -371,6 +406,9 @@ function endReactionWrapper(reaction) { maybeClearReticleUpdateLimiterTimeout(); deleteOldReticles(); break; + case ("raiseHand"): + maybeClearInputAudioLevelsInterval(); + break; } } @@ -648,6 +686,7 @@ function unload() { maybeClearClapSoundInterval(); maybeClearReticleUpdateLimiterTimeout(); maybeDeleteRemoteIndicatorTimeout(); + maybeClearInputAudioLevelsInterval(); Window.minimizedChanged.disconnect(onWindowMinimizedChanged); HMD.displayModeChanged.disconnect(onDisplayModeChanged);