bool ProcessRecordedClip() //todo why return a bool? why return anything? maybe exceptions much! { float[] samples = new float[recordedData.samples * recordedData.channels]; recordedData.GetData(samples, 0); int i = 0; float samplesSum = 0; while (i < samples.Length) { samplesSum += Math.Abs(samples[i]); ++i; } float sensitivityThreshold = (Microphone.GetPosition(null) - previousFrameSamplesLenght) * micSensitivity * sensitivityFactor; if ((samplesSum - previousFrameSoundData) > sensitivityThreshold) { var highLowSoundthresholdData = (Microphone.GetPosition(null) - previousFrameSamplesLenght) * highLowSoundThreshold * sensitivityFactor; if ((samplesSum - previousFrameSoundData) > highLowSoundthresholdData) { voiceStrenght = VoiceStrenght.HighVoice; } else { voiceStrenght = VoiceStrenght.LowVoice; } } else { voiceStrenght = VoiceStrenght.NoVoice; } previousFrameSoundData = samplesSum; return(true); }
// Use this for initialization void Start() { voiceStrenght = VoiceStrenght.NoVoice; inputDispatcher = new PlayerInputDispatcher(); if (Microphone.devices.Length <= 0) { throw new NotSupportedException(); } else { micConnected = true; //Get the default microphone recording capabilities Microphone.GetDeviceCaps(null, out minFreq, out maxFreq); //According to the documentation, if minFreq and maxFreq are zero, the microphone supports any frequency... if (minFreq == 0 && maxFreq == 0) { maxFreq = 44100; } //Start recording ListenForFixedTime(); } }