示例#1
0
        public void TestEnabled() {
            var vad = new VoiceActivityDetector(SAMPLE_RATE);
            vad.Enabled = false;

            var inputStream = ReadFileFromResource("speech.raw");

            speechEnd = false;
            speechBegin = false;

            vad.SpeechBegin += () => {speechBegin = true; };
            vad.SpeechEnd += () => {speechEnd = true; };

            ProcessStream(vad, inputStream);

            Assert.IsTrue(speechBegin);
            Assert.IsFalse(speechEnd);
        }
示例#2
0
        public void TestSpeechDetect(){
            var vad = new VoiceActivityDetector(SAMPLE_RATE);

            var inputStream = ReadFileFromResource("speech.raw");

            speechEnd = false;
            speechBegin = false;
            speechNotDetected = false;

            vad.SpeechBegin += () => {speechBegin = true; };
            vad.SpeechEnd += () => {speechEnd = true; };
            vad.SpeechNotDetected += () => {speechNotDetected = true; };

            ProcessStream(vad, inputStream);

            Assert.IsTrue(speechBegin);
            Assert.IsTrue(speechEnd);
            Assert.IsFalse(speechNotDetected);

            Assert.IsTrue(vad.SpeechBeginTime > 800 && vad.SpeechBeginTime < 950, "vad.SpeechBeginTime " + vad.SpeechBeginTime);
            Assert.IsTrue(vad.SpeechEndTime > 2400 && vad.SpeechEndTime < 2900, "vad.SpeechEndTime " + vad.SpeechEndTime);
        }
示例#3
0
        static void ProcessStream(VoiceActivityDetector vad, Stream inputStream)
        {
            var bufferSize = 3000 + new Random().Next(200);
            var buffer = new byte[bufferSize];
            int bytesRead = 0;
            bytesRead = inputStream.Read(buffer, 0, bufferSize);
            while (bytesRead > 0)
            {
                vad.ProcessBufferEx(buffer, bytesRead);

                bufferSize = 3000 + new Random().Next(200);
                buffer = new byte[bufferSize];
                bytesRead = inputStream.Read(buffer, 0, bufferSize);
            }
        }