using TMPro; using UnityEngine; public class MicrophoneStand : MonoBehaviour { public TextMeshProUGUI outputText; public GameObject microphoneOffStatus; public GameObject microphoneOnStatus; public FMODWhisperBridge fmodWhisperBridge; public delegate void OnPlayerFinishedSpeakingDelegate(); public event OnPlayerFinishedSpeakingDelegate OnPlayerFinishedSpeaking; // Start is called before the first frame update void Start() { microphoneOffStatus.SetActive(true); microphoneOnStatus.SetActive(false); } // Update is called once per frame void Update() { } public void OnPlayerApproach() { fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdated; fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished; microphoneOffStatus.SetActive(false); microphoneOnStatus.SetActive(true); AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject); fmodWhisperBridge.ActivateRecording(); } public void OnPlayerLeave() { fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdated; fmodWhisperBridge.OnWhisperSegmentFinished -= OnPlayerSpeechFinished; microphoneOffStatus.SetActive(true); microphoneOnStatus.SetActive(false); AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject); fmodWhisperBridge.DeactivateRecording(); } private void OnPlayerSpeechUpdated(string text) { outputText.text = text; OnPlayerFinishedSpeaking?.Invoke(); } private void OnPlayerSpeechFinished(string playerText) { OnPlayerFinishedSpeaking?.Invoke(); } public string GetTextOutput() { return outputText.text; } }