1
0
forked from cgvr/DeltaVR

replaced demo boxes with microphone stand and buttons, in archery range

This commit is contained in:
2026-01-10 17:00:45 +02:00
parent 46b1c7e1de
commit ce75a1f343
39 changed files with 2631 additions and 141 deletions

View File

@@ -0,0 +1,87 @@
using TMPro;
using UnityEngine;
using Whisper;
using Whisper.Utils;
public class MicrophoneStand : MonoBehaviour
{
public WhisperManager whisper;
public MicrophoneRecord microphoneRecord;
public string microphoneDevice;
public TextMeshProUGUI outputText;
private WhisperStream stream;
private string textOutput;
public GameObject microphoneOffStatus;
public GameObject microphoneOnStatus;
// Start is called before the first frame update
async void Start()
{
Debug.Log("Mic devices: " + string.Join(", ", Microphone.devices));
Debug.Log("Using mic device: " + microphoneDevice);
microphoneRecord.SelectedMicDevice = microphoneDevice;
// This causes about 1 sec long freeze, has to be done once at the start of the game
microphoneRecord.StartRecord();
stream = await whisper.CreateStream(microphoneRecord);
stream.OnResultUpdated += OnWhisperResult;
microphoneOffStatus.SetActive(true);
microphoneOnStatus.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider other)
{
KbmController controller = other.GetComponent<KbmController>();
Debug.Log("Mic stand collided with object " + other.gameObject.name);
if (controller != null || other.gameObject.tag == "Player Head")
{
microphoneOffStatus.SetActive(false);
microphoneOnStatus.SetActive(true);
stream.StartStream();
Debug.Log("Whisper stream started.");
}
}
private void OnTriggerExit(Collider other)
{
KbmController controller = other.GetComponent<KbmController>();
if (controller != null | other.gameObject.tag == "Player Head")
{
microphoneOffStatus.SetActive(true);
microphoneOnStatus.SetActive(false);
stream.StopStream();
textOutput = outputText.text;
}
}
private void OnWhisperResult(string result)
{
Debug.Log("Whisper result processed: " + result);
outputText.text = result;
}
private void OnDestroy()
{
microphoneRecord.StopRecord();
Destroy(gameObject);
}
public string GetTextOutput()
{
return textOutput;
}
}