From: Andrew S Date: Mon, 26 Feb 2024 08:12:35 +0000 (-0600) Subject: stream.wasm : fix invalid memory access when no segments (#1902) X-Git-Tag: upstream/1.7.4~952 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=0d8fd8483ae26f1318a989dbc800d4f47f46f890;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp stream.wasm : fix invalid memory access when no segments (#1902) No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker. --- diff --git a/examples/stream.wasm/emscripten.cpp b/examples/stream.wasm/emscripten.cpp index 71acffba..43e71bf2 100644 --- a/examples/stream.wasm/emscripten.cpp +++ b/examples/stream.wasm/emscripten.cpp @@ -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);