Skip to content

Commit

Permalink
stream.wasm : fix invalid memory access when no segments (ggerganov#1902
Browse files Browse the repository at this point in the history
)

No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
  • Loading branch information
Andrews54757 authored and iThalay committed Sep 23, 2024
1 parent 8d70755 commit 305cc63
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/stream.wasm/emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ void stream_main(size_t index) {

{
const int n_segments = whisper_full_n_segments(ctx);
for (int i = n_segments - 1; i < n_segments; ++i) {
const char * text = whisper_full_get_segment_text(ctx, i);
if (n_segments > 0) {
const char * text = whisper_full_get_segment_text(ctx, n_segments - 1);

const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
const int64_t t0 = whisper_full_get_segment_t0(ctx, n_segments - 1);
const int64_t t1 = whisper_full_get_segment_t1(ctx, n_segments - 1);

printf("transcribed: %s\n", text);

Expand Down

0 comments on commit 305cc63

Please sign in to comment.