forked from cgvr/DeltaVR
NPC doesnt process player speech when its too soon after last processing
This commit is contained in:
@@ -16,10 +16,12 @@ public class CafeWaiterNPC : NPCController
|
||||
// 1 - waiting for player to answer "is this correct?"
|
||||
// 2 - bringing food
|
||||
private int state;
|
||||
private float lastPlayerVoiceUpdateTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
state = 0;
|
||||
lastPlayerVoiceUpdateTime = Time.time;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -33,7 +35,7 @@ public class CafeWaiterNPC : NPCController
|
||||
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
|
||||
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdate;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += ProcessPlayerSpeech;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
}
|
||||
|
||||
@@ -41,12 +43,25 @@ public class CafeWaiterNPC : NPCController
|
||||
{
|
||||
//AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject);
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdate;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished -= ProcessPlayerSpeech;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished -= OnPlayerSpeechFinished;
|
||||
fmodWhisperBridge.DeactivateRecording();
|
||||
}
|
||||
|
||||
private void ProcessPlayerSpeech(string playerText)
|
||||
private void OnPlayerSpeechFinished(string playerText)
|
||||
{
|
||||
if (Time.time < lastPlayerVoiceUpdateTime + 0.5f)
|
||||
{
|
||||
Debug.Log("voiceline: player said '" + playerText + "' but not enough time passed");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(playerText) || playerText.Contains("BLANK_AUDIO"))
|
||||
{
|
||||
Debug.Log("player speech event but result empty");
|
||||
return;
|
||||
}
|
||||
lastPlayerVoiceUpdateTime = Time.time;
|
||||
Debug.Log("state = " + state.ToString() + ", voiceline: player text: " + playerText);
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
// Show transcription and ask whether it is correct
|
||||
@@ -73,7 +88,7 @@ public class CafeWaiterNPC : NPCController
|
||||
|
||||
private void OnPlayerSpeechUpdate(string playerText)
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerText) || playerText.Equals("BLANK_AUDIO"))
|
||||
if (string.IsNullOrEmpty(playerText) || playerText.Contains("BLANK_AUDIO"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user