Skip to content

Commit f99263e

Browse files
committed
Run vad_simple on entire pcmf32, not on the last step
1 parent 0a84581 commit f99263e

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

examples/stream/stream.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int main(int argc, char ** argv) {
362362
audio.next(pcmf32);
363363
}
364364

365-
const int n_samples_buf = pcmf32.size();
365+
int n_samples_buf = pcmf32.size();
366366

367367
if (params.save_audio && n_samples_buf > 0) {
368368
wavWriter.write(pcmf32.data(), n_samples_buf);
@@ -390,25 +390,19 @@ int main(int argc, char ** argv) {
390390
is_interim = false;
391391
bool is_aborted = true;
392392

393+
n_samples_buf = std::min(n_samples_len, n_samples_old + n_samples_new);
394+
pcmf32.resize(n_samples_buf);
395+
copy(pcmf32_deque.end() - n_samples_buf, pcmf32_deque.end(), pcmf32.begin());
396+
393397
if (!use_vad){
394398
n_samples_old += n_samples_new;
395399
n_samples_new = 0;
396-
pcmf32.resize(n_samples_old);
397-
copy(pcmf32_deque.end() - n_samples_old, pcmf32_deque.end(), pcmf32.begin());
398400

399401
t_last = t_now;
400402
} else {
401-
const auto n_samples = std::min(n_samples_len, n_samples_old + n_samples_new);
402-
403-
is_aborted = (n_samples > n_samples_len);
404-
if (is_running && !is_aborted) {
405-
pcmf32.resize(n_samples_step);
406-
copy(pcmf32_deque.end() - n_samples_step, pcmf32_deque.end(), pcmf32.begin());
407-
}
403+
is_aborted = (n_samples_buf > n_samples_len);
408404

409405
if (!is_running || is_aborted || ::vad_simple(pcmf32, WHISPER_SAMPLE_RATE, std::min(1000, abs(params.step_ms) / 2), params.vad_thold, params.freq_thold, false)) {
410-
pcmf32.resize(n_samples);
411-
copy(pcmf32_deque.end() - n_samples, pcmf32_deque.end(), pcmf32.begin());
412406
n_samples_new = 0;
413407
n_samples_old = 0;
414408

0 commit comments

Comments
 (0)