-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvad.cc
44 lines (33 loc) · 865 Bytes
/
vad.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Created on 2017-06-03
// Author: Binbin Zhang
#include "vad.h"
#include "stdio.h"
#include "stdlib.h"
Vad::Vad(int mode): mode_(mode) {
if (WebRtcVad_Create(&handle_) < 0) {
printf("Create webrtc vad handle error\n");
exit(-1);
}
WebRtcVad_Init(handle_);
WebRtcVad_set_mode(handle_, mode_);
}
Vad::~Vad() {
WebRtcVad_Free(handle_);
}
void Vad::SetMode(int mode) {
mode_ = mode;
WebRtcVad_set_mode(handle_, mode_);
}
bool Vad::IsSpeech(const int16_t *data, int num_samples, int fs) {
int ret = WebRtcVad_Process(handle_, fs, data, num_samples);
switch (ret) {
case 0:
return false;
case 1:
return true;
default:
printf("WebRtcVad_Process error, check sample rate or frame length\n");
exit(-1);
return false;
}
}