bolar_2 backup
This commit is contained in:
54
host_tests/voice_activity_detector_test.cc
Normal file
54
host_tests/voice_activity_detector_test.cc
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "audio/voice_activity_detector.h"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace borla;
|
||||
|
||||
void TestHysteresis()
|
||||
{
|
||||
VoiceActivityDetector detector(
|
||||
VoiceActivityConfig{500, 2, 3});
|
||||
std::array<int16_t, 960> loud{};
|
||||
std::array<int16_t, 960> quiet{};
|
||||
loud.fill(1000);
|
||||
|
||||
assert(detector.Process(loud.data(), loud.size()) ==
|
||||
VoiceActivityResult::kSilence);
|
||||
assert(detector.Process(loud.data(), loud.size()) ==
|
||||
VoiceActivityResult::kSpeechStarted);
|
||||
assert(detector.speech_active());
|
||||
assert(detector.Process(quiet.data(), quiet.size()) ==
|
||||
VoiceActivityResult::kSpeech);
|
||||
assert(detector.Process(quiet.data(), quiet.size()) ==
|
||||
VoiceActivityResult::kSpeech);
|
||||
assert(detector.Process(quiet.data(), quiet.size()) ==
|
||||
VoiceActivityResult::kSpeechEnded);
|
||||
assert(!detector.speech_active());
|
||||
}
|
||||
|
||||
void TestNoiseDoesNotStartSpeech()
|
||||
{
|
||||
VoiceActivityDetector detector(
|
||||
VoiceActivityConfig{500, 2, 3});
|
||||
std::array<int16_t, 960> noise{};
|
||||
noise.fill(300);
|
||||
for (int index = 0; index < 20; ++index) {
|
||||
assert(detector.Process(noise.data(), noise.size()) ==
|
||||
VoiceActivityResult::kSilence);
|
||||
}
|
||||
assert(detector.LastRms() == 300);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
TestHysteresis();
|
||||
TestNoiseDoesNotStartSpeech();
|
||||
std::cout << "voice activity detector tests passed\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user