예제 #1
0
    private void Start()
    {
        bookNoise   = false;
        typeOfInput = MicInputType.noone;


        isSpeaking = false;
        if (SpeakingInd != null)
        {
            SpeakingInd.SetActive(false);
        }
    }
예제 #2
0
    void Update()
    {
        if (typeOfInput != MicInputType.noone)
        {
            if (!Microphone.IsRecording(deviceName))
            {
                OnEnable();
            }
            time        += Time.deltaTime;
            current_time = (int)time;
            if (typeOfInput == MicInputType.speechDetection)
            {
                speakingScore = DetectionOfSpeech();
                if (speakingScore != 0)
                {
                    lastSpeakingPointsTime = current_time;
                }
                if (lastSpeakingPointsTime + 1 <= current_time)
                {
                    isSpeaking = false;
                    if (SpeakingInd != null)
                    {
                        SpeakingInd.SetActive(false);
                    }
                }
            }
            else if (typeOfInput == MicInputType.peakDetection)
            {
                if (!initDet)
                {
                    InitDetect();
                }

                if (peakArrayDisplayTime + 1f <= time)
                {
                    DisplayLoudness();
                    peakArrayDisplayTime = time;
                }
                float MaxPeak = PeakDetection();
                if (sampleTime + 0.1f <= time)
                {
                    if (MaxPeak >= detectionLevel)
                    {
                        peakArray[pointer] = MaxPeak;
                        pointer++;
                        pointer   %= 9;
                        sampleTime = time;
                    }
                }
                if (MaxPeak >= minSilencingVolume || bookNoise)
                {
                    Noise.shoutedLoudEnough = true;
                    typeOfInput             = MicInputType.noone;
                    Detector.SetActive(false);
                    initDet = false;
                }
                if (bookNoise)
                {
                    initDet = false;
                }
            }
        }
    }