From 0c91cab5c6651975222c1cb09976d581840efeac Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Sat, 5 Sep 2020 15:02:35 +0200 Subject: [PATCH] Made it so that in `OpenSeeVRMDriver` audio input is automatically reinitialized if no more audio data is received for three seconds after originally receiving audio input. --- Examples/OpenSeeVRMDriver.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Examples/OpenSeeVRMDriver.cs b/Examples/OpenSeeVRMDriver.cs index 2c8bbe4..8af78d0 100644 --- a/Examples/OpenSeeVRMDriver.cs +++ b/Examples/OpenSeeVRMDriver.cs @@ -209,6 +209,8 @@ public class OpenSeeVRMDriver : MonoBehaviour { private int browInterpolationCount = 0; private int browInterpolationState = 0; private BlendShapeKey[] browClips; + + private float lastAudioTime = -1f; private Dictionary catsData = null; void InitCatsData() { @@ -1195,6 +1197,7 @@ public class OpenSeeVRMDriver : MonoBehaviour { public void InitializeLipSync() { active = false; + lastAudioTime = -1f; if (catsData == null) InitCatsData(); if (!isCanned && clip != null) @@ -1313,6 +1316,9 @@ public class OpenSeeVRMDriver : MonoBehaviour { } } audioVolume /= buffer.Length; + + if (audioVolume > 0f) + lastAudioTime = Time.time; int totalLen = partialPos + buffer.Length; int bufferPos = 0; @@ -1371,6 +1377,10 @@ public class OpenSeeVRMDriver : MonoBehaviour { } void ReadAudio() { + if (lastAudioTime >= 0f && Time.time > lastAudioTime + 3f && lipSync) { + Debug.Log("Audio device might have disappeared, reinitializing lip sync."); + InitializeLipSync(); + } if (clip == null) return; if (OVRLipSync.IsInitialized() != OVRLipSync.Result.Success) {