Small VAD improvements
* RAII * Slightly fewer false positives
This commit is contained in:
parent
faa3f2b4bb
commit
f275267ac7
|
@ -6,6 +6,7 @@
|
||||||
#include <boost/range/adaptor/transformed.hpp>
|
#include <boost/range/adaptor/transformed.hpp>
|
||||||
#include <webrtc/common_audio/vad/include/webrtc_vad.h>
|
#include <webrtc/common_audio/vad/include/webrtc_vad.h>
|
||||||
#include "processing.h"
|
#include "processing.h"
|
||||||
|
#include <gsl_util.h>
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using boost::adaptors::transformed;
|
using boost::adaptors::transformed;
|
||||||
|
@ -19,10 +20,12 @@ BoundedTimeline<void> detectVoiceActivity(std::unique_ptr<AudioStream> audioStre
|
||||||
VadInst* vadHandle = WebRtcVad_Create();
|
VadInst* vadHandle = WebRtcVad_Create();
|
||||||
if (!vadHandle) throw runtime_error("Error creating WebRTC VAD handle.");
|
if (!vadHandle) throw runtime_error("Error creating WebRTC VAD handle.");
|
||||||
|
|
||||||
|
auto freeHandle = gsl::finally([&]() { WebRtcVad_Free(vadHandle); });
|
||||||
|
|
||||||
int error = WebRtcVad_Init(vadHandle);
|
int error = WebRtcVad_Init(vadHandle);
|
||||||
if (error) throw runtime_error("Error initializing WebRTC VAD handle.");
|
if (error) throw runtime_error("Error initializing WebRTC VAD handle.");
|
||||||
|
|
||||||
const int aggressiveness = 1; // 0..3. The higher, the more is cut off.
|
const int aggressiveness = 2; // 0..3. The higher, the more is cut off.
|
||||||
error = WebRtcVad_set_mode(vadHandle, aggressiveness);
|
error = WebRtcVad_set_mode(vadHandle, aggressiveness);
|
||||||
if (error) throw runtime_error("Error setting WebRTC VAD aggressiveness.");
|
if (error) throw runtime_error("Error setting WebRTC VAD aggressiveness.");
|
||||||
|
|
||||||
|
@ -39,8 +42,6 @@ BoundedTimeline<void> detectVoiceActivity(std::unique_ptr<AudioStream> audioStre
|
||||||
const size_t bufferCapacity = audioStream->getSampleRate() / 100;
|
const size_t bufferCapacity = audioStream->getSampleRate() / 100;
|
||||||
process16bitAudioStream(*audioStream.get(), processBuffer, bufferCapacity, progressSink);
|
process16bitAudioStream(*audioStream.get(), processBuffer, bufferCapacity, progressSink);
|
||||||
|
|
||||||
WebRtcVad_Free(vadHandle);
|
|
||||||
|
|
||||||
// Fill small gaps in activity
|
// Fill small gaps in activity
|
||||||
const centiseconds maxGap(5);
|
const centiseconds maxGap(5);
|
||||||
for (const auto& pair : getPairs(activity)) {
|
for (const auto& pair : getPairs(activity)) {
|
||||||
|
|
Loading…
Reference in New Issue