forked from cgvr/DeltaVR
improve text recognition reliability, unsubscribe from Whisper events when not wanted anymore
This commit is contained in:
Binary file not shown.
@@ -14,8 +14,6 @@ public class MicrophoneStand : MonoBehaviour
|
|||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
fmodWhisperBridge.OnWhisperResultProcessed += OnWhisperResult;
|
|
||||||
|
|
||||||
microphoneOffStatus.SetActive(true);
|
microphoneOffStatus.SetActive(true);
|
||||||
microphoneOnStatus.SetActive(false);
|
microphoneOnStatus.SetActive(false);
|
||||||
}
|
}
|
||||||
@@ -33,6 +31,9 @@ public class MicrophoneStand : MonoBehaviour
|
|||||||
|
|
||||||
if (controller != null || other.gameObject.tag == "Player Head")
|
if (controller != null || other.gameObject.tag == "Player Head")
|
||||||
{
|
{
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentUpdated += OnWhisperResult;
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentFinished += OnWhisperResult;
|
||||||
|
|
||||||
microphoneOffStatus.SetActive(false);
|
microphoneOffStatus.SetActive(false);
|
||||||
microphoneOnStatus.SetActive(true);
|
microphoneOnStatus.SetActive(true);
|
||||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
||||||
@@ -49,6 +50,9 @@ public class MicrophoneStand : MonoBehaviour
|
|||||||
KbmController controller = other.GetComponent<KbmController>();
|
KbmController controller = other.GetComponent<KbmController>();
|
||||||
if (controller != null | other.gameObject.tag == "Player Head")
|
if (controller != null | other.gameObject.tag == "Player Head")
|
||||||
{
|
{
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnWhisperResult;
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentFinished -= OnWhisperResult;
|
||||||
|
|
||||||
microphoneOffStatus.SetActive(true);
|
microphoneOffStatus.SetActive(true);
|
||||||
microphoneOnStatus.SetActive(false);
|
microphoneOnStatus.SetActive(false);
|
||||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
||||||
@@ -62,6 +66,10 @@ public class MicrophoneStand : MonoBehaviour
|
|||||||
|
|
||||||
private void OnWhisperResult(string result)
|
private void OnWhisperResult(string result)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(result) || result.Equals("BLANK_AUDIO"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
outputText.text = result;
|
outputText.text = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,11 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
public bool playLoopback = true;
|
public bool playLoopback = true;
|
||||||
[Range(0f, 2f)] public float loopbackVolume = 1.0f;
|
[Range(0f, 2f)] public float loopbackVolume = 1.0f;
|
||||||
|
|
||||||
public delegate void OnWhisperResultProcessedDelegate(string result);
|
public delegate void OnWhisperSegmentUpdatedDelegate(string result);
|
||||||
public event OnWhisperResultProcessedDelegate OnWhisperResultProcessed;
|
public event OnWhisperSegmentUpdatedDelegate OnWhisperSegmentUpdated;
|
||||||
|
|
||||||
|
public delegate void OnWhisperSegmentFinishedDelegate(string result);
|
||||||
|
public event OnWhisperSegmentFinishedDelegate OnWhisperSegmentFinished;
|
||||||
|
|
||||||
// FMOD
|
// FMOD
|
||||||
private FMOD.System _core;
|
private FMOD.System _core;
|
||||||
@@ -113,7 +116,12 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
};
|
};
|
||||||
_stream.OnSegmentUpdated += (seg) =>
|
_stream.OnSegmentUpdated += (seg) =>
|
||||||
{
|
{
|
||||||
OnWhisperResultProcessed?.Invoke(seg.Result);
|
OnWhisperSegmentUpdated?.Invoke(seg.Result);
|
||||||
|
//UnityEngine.Debug.Log($"[Whisper] Seg updated: {seg.Result}");
|
||||||
|
};
|
||||||
|
_stream.OnSegmentFinished += (seg) =>
|
||||||
|
{
|
||||||
|
OnWhisperSegmentFinished?.Invoke(seg.Result);
|
||||||
//UnityEngine.Debug.Log($"[Whisper] Seg finished: {seg.Result}");
|
//UnityEngine.Debug.Log($"[Whisper] Seg finished: {seg.Result}");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ public class CafeWaiterNPC : NPCController
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
fmodWhisperBridge.OnWhisperResultProcessed += ProcessPlayerSpeech;
|
|
||||||
|
|
||||||
notepadOriginalRotation = notepadTransform.localRotation.eulerAngles;
|
notepadOriginalRotation = notepadTransform.localRotation.eulerAngles;
|
||||||
notepadFlippedRotation = notepadOriginalRotation + new Vector3(0, 180, 0);
|
notepadFlippedRotation = notepadOriginalRotation + new Vector3(0, 180, 0);
|
||||||
}
|
}
|
||||||
@@ -33,12 +31,17 @@ public class CafeWaiterNPC : NPCController
|
|||||||
protected override void OnPlayerApproach()
|
protected override void OnPlayerApproach()
|
||||||
{
|
{
|
||||||
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
|
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
|
||||||
|
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdate;
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentFinished += ProcessPlayerSpeech;
|
||||||
fmodWhisperBridge.ActivateRecording();
|
fmodWhisperBridge.ActivateRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPlayerLeave()
|
protected override void OnPlayerLeave()
|
||||||
{
|
{
|
||||||
//AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject);
|
//AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject);
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdate;
|
||||||
|
fmodWhisperBridge.OnWhisperSegmentFinished -= ProcessPlayerSpeech;
|
||||||
fmodWhisperBridge.DeactivateRecording();
|
fmodWhisperBridge.DeactivateRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,4 +70,13 @@ public class CafeWaiterNPC : NPCController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPlayerSpeechUpdate(string playerText)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(playerText) || playerText.Equals("BLANK_AUDIO"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
notepadText.text = playerText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user