@@ -42,7 +42,8 @@ VadIterator::VadIterator(const std::string &model_path, int sample_rate,
42
42
state(2 * 1 * 128 , 0 .0f ), sr(1 , sample_rate) {
43
43
44
44
this ->input_node_dims [0 ] = 1 ;
45
- this ->input_node_dims [1 ] = window_size_samples;
45
+ this ->input_node_dims [1 ] = this ->window_size_samples ;
46
+ this ->input .reserve (context_size + this ->window_size_samples );
46
47
47
48
try {
48
49
this ->init_onnx_model (model_path);
@@ -78,9 +79,9 @@ void VadIterator::reset_states() {
78
79
Timestamp VadIterator::predict (const std::vector<float > &data) {
79
80
// Pre-fill input with context
80
81
this ->input .clear ();
81
- this ->input .reserve (context. size () + data. size ());
82
- this ->input . insert (input. end (), context. begin (), context.end ());
83
- this ->input .insert (input.end (), data.begin (), data.end ());
82
+ this ->input .insert ( this -> input . end (), this -> context . begin (),
83
+ this ->context .end ());
84
+ this ->input .insert (this -> input .end (), data.begin (), data.end ());
84
85
85
86
// Create input tensors
86
87
Ort::Value input_tensor = Ort::Value::CreateTensor<float >(
@@ -132,8 +133,9 @@ Timestamp VadIterator::predict(const std::vector<float> &data) {
132
133
this ->triggered = true ;
133
134
return Timestamp (start_timestwamp, -1 , speech_prob);
134
135
}
136
+ }
135
137
136
- } else if (speech_prob < this ->threshold - 0.15 && this ->triggered ) {
138
+ if (speech_prob < this ->threshold - 0.15 && this ->triggered ) {
137
139
if (this ->temp_end == 0 ) {
138
140
this ->temp_end = this ->current_sample ;
139
141
}
0 commit comments