Andrew S commited on
Commit
3273767
·
unverified ·
1 Parent(s): b92d757

stream.wasm : fix invalid memory access when no segments (#1902)

Browse files

No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.

examples/stream.wasm/emscripten.cpp CHANGED
@@ -103,11 +103,11 @@ void stream_main(size_t index) {
103
 
104
  {
105
  const int n_segments = whisper_full_n_segments(ctx);
106
- for (int i = n_segments - 1; i < n_segments; ++i) {
107
- const char * text = whisper_full_get_segment_text(ctx, i);
108
 
109
- const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
110
- const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
111
 
112
  printf("transcribed: %s\n", text);
113
 
 
103
 
104
  {
105
  const int n_segments = whisper_full_n_segments(ctx);
106
+ if (n_segments > 0) {
107
+ const char * text = whisper_full_get_segment_text(ctx, n_segments - 1);
108
 
109
+ const int64_t t0 = whisper_full_get_segment_t0(ctx, n_segments - 1);
110
+ const int64_t t1 = whisper_full_get_segment_t1(ctx, n_segments - 1);
111
 
112
  printf("transcribed: %s\n", text);
113