Skip to content

Commit d99e235

Browse files
committed
minor fixes
1 parent d49c721 commit d99e235

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

whisper_ros/src/silero_vad/silero_vad_node.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ void SileroVadNode::audio_callback(
189189

190190
// Add audio if listening
191191
if (this->listening) {
192-
for (auto d : data) {
193-
this->data.push_back(d);
194-
}
192+
this->data.insert(this->data.end(), data.begin(), data.end());
195193
}
196194

197195
// Check if speech ends

whisper_ros/src/silero_vad/vad_iterator.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ VadIterator::VadIterator(const std::string &model_path, int sample_rate,
4242
state(2 * 1 * 128, 0.0f), sr(1, sample_rate) {
4343

4444
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);
4647

4748
try {
4849
this->init_onnx_model(model_path);
@@ -78,9 +79,9 @@ void VadIterator::reset_states() {
7879
Timestamp VadIterator::predict(const std::vector<float> &data) {
7980
// Pre-fill input with context
8081
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());
8485

8586
// Create input tensors
8687
Ort::Value input_tensor = Ort::Value::CreateTensor<float>(
@@ -132,8 +133,9 @@ Timestamp VadIterator::predict(const std::vector<float> &data) {
132133
this->triggered = true;
133134
return Timestamp(start_timestwamp, -1, speech_prob);
134135
}
136+
}
135137

136-
} else if (speech_prob < this->threshold - 0.15 && this->triggered) {
138+
if (speech_prob < this->threshold - 0.15 && this->triggered) {
137139
if (this->temp_end == 0) {
138140
this->temp_end = this->current_sample;
139141
}

0 commit comments

Comments
 (0)