Spaces:
Running
Running
Andrew S
commited on
stream.wasm : fix invalid memory access when no segments (#1902)
Browse filesNo 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 |
-
|
| 107 |
-
const char * text = whisper_full_get_segment_text(ctx,
|
| 108 |
|
| 109 |
-
const int64_t t0 = whisper_full_get_segment_t0(ctx,
|
| 110 |
-
const int64_t t1 = whisper_full_get_segment_t1(ctx,
|
| 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 |
|