public void DetectThreshold(int durationSec = 3) { GCSpeechRecognition.Instance.StartCoroutine(_mediaManager.OneTimeRecord(durationSec, (samples) => { float accum = 0f; for (int i = 0; i < samples.Length; i++) { accum += Mathf.Abs(samples[i]); } _threshold = System.Math.Round(accum / (float)samples.Length, 6) * 5; _speechRecognitionManager.CurrentConfig.voiceDetectionThreshold = _threshold; })); }
public void DetectThreshold(int durationSec = 3) { GCSpeechRecognition.Instance.StartCoroutine(_mediaManager.OneTimeRecord(durationSec, (clip) => { float[] samples = new float[clip.samples]; if (clip.GetData(samples, 0)) { float accum = 0f; for (int i = 0; i < samples.Length; i++) { accum += Mathf.Abs(samples[i]); } _threshold = System.Math.Round(accum / (float)samples.Length, 6) * 5; _speechRecognitionManager.CurrentConfig.voiceDetectionThreshold = _threshold; } if (clip != null) { MonoBehaviour.Destroy(clip); } })); }