Skip to content

Commit b0b2f9b

Browse files
committed
vad : use std::vector for segments in whisper_vad_timestamps_from_probs
1 parent 7625ba1 commit b0b2f9b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/whisper.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5388,10 +5388,11 @@ struct whisper_vad_timestamps * whisper_vad_timestamps_from_probs(
53885388
WHISPER_LOG_INFO("%s: Final speech segments after filtering: %d\n", __func__, (int) speeches.size());
53895389

53905390
// Allocate final segments
5391-
struct whisper_vad_segment * segments = NULL;
5391+
std::vector<whisper_vad_segment> segments;
53925392
if (speeches.size() > 0) {
5393-
segments = (struct whisper_vad_segment *) malloc(speeches.size() * sizeof(struct whisper_vad_segment));
5394-
if (!segments) {
5393+
try {
5394+
segments.resize(speeches.size());
5395+
} catch (const std::bad_alloc &) {
53955396
WHISPER_LOG_ERROR("%s: failed to allocate memory for final segments\n", __func__);
53965397
return nullptr;
53975398
}
@@ -5446,7 +5447,7 @@ struct whisper_vad_timestamps * whisper_vad_timestamps_from_probs(
54465447
return nullptr;
54475448
}
54485449
timestamps->n_segments = (int) speeches.size();
5449-
timestamps->segments.assign(segments, segments + timestamps->n_segments);
5450+
timestamps->segments = std::move(segments);
54505451
return timestamps;
54515452
}
54525453

0 commit comments

Comments
 (0)