Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ inline constexpr auto kPaddedWindowSize = std::bit_ceil(kWindowSize); // 512
inline constexpr size_t kModelInputMin = 100;
inline constexpr size_t kModelInputMax = 1000;
inline constexpr auto kSpeechThreshold = 0.6f;
inline constexpr size_t kMinSpeechDuration = 25; // 250 ms
inline constexpr size_t kMinSilenceDuration = 10; // 100 ms
inline constexpr size_t kSpeechPad = 3; // 30 ms
inline constexpr size_t kMinSpeechDurationMs = 250;
inline constexpr size_t kMinSilenceDurationMs = 100;
inline constexpr size_t kSpeechPadMs = 30;
inline constexpr size_t kStreamBufferMaxSize = 10 * kSampleRate; // 10s
inline constexpr size_t kStreamBufferMinReserve =
1 * kSampleRate; // 1s of audio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ VoiceActivityDetection::postprocess(const std::vector<float> &scores,
if (score >= threshold) {
if (potentialStart == -1) {
potentialStart = i;
} else if (i - potentialStart >= kMinSpeechDuration) {
} else if (i - potentialStart >= kMinSpeechDurationMs / kHopLengthMs) {
triggered = true;
startSegment = potentialStart;
potentialStart = -1;
Expand All @@ -221,7 +221,7 @@ VoiceActivityDetection::postprocess(const std::vector<float> &scores,
if (score < threshold) {
if (potentialEnd == -1) {
potentialEnd = i;
} else if (i - potentialEnd >= kMinSilenceDuration) {
} else if (i - potentialEnd >= kMinSilenceDurationMs / kHopLengthMs) {
triggered = false;
endSegment = potentialEnd;
speechSegments.emplace_back(startSegment, endSegment);
Expand All @@ -237,11 +237,12 @@ VoiceActivityDetection::postprocess(const std::vector<float> &scores,
speechSegments.emplace_back(startSegment, endSegment);
}

constexpr size_t kSpeechPadHops = kSpeechPadMs / kHopLengthMs;
for (auto &[start, end] : speechSegments) {
// std::max(start-kSpeedchPad, 0) might be underflow that is why we use ?
// std::max(start-kSpeechPadHops, 0) might be underflow that is why we use ?
// operator.
start = (start > kSpeechPad ? start - kSpeechPad : 0) * kHopLength;
end = std::min(end + kSpeechPad, scores.size()) * kHopLength;
start = (start > kSpeechPadHops ? start - kSpeechPadHops : 0) * kHopLength;
end = std::min(end + kSpeechPadHops, scores.size()) * kHopLength;
}

// Merge tightly placed segments according to the max allowed gap parameter.
Expand Down
Loading