@@ -480,9 +480,11 @@ let do_search (args : search_params) =
480480 |> get_valid_audio_files_loud
481481 |> List. filter ignore_cached_files
482482 in
483+
484+ (if (List. length audiofiles_to_transcribe > 0 ) then begin
485+ transcribe_files audiofiles_to_transcribe;
486+ end );
483487
484- transcribe_files audiofiles_to_transcribe;
485-
486488 let search_transcript (orig_search : string ) (audio_file : string ) =
487489 let file = get_transcript audio_file in
488490 let str_to_search = read_whole_file file in
@@ -491,12 +493,10 @@ let do_search (args : search_params) =
491493 |> String. trim
492494 in
493495
494-
495496 (* LOAD TIMESTAMPS INTO HASHTABLE *)
496-
497497 let tbl = get_byte_to_timestamp_table audio_file in
498498
499- (* FIND ALL THE MATCHES AND PUT IN RESULT LIST *)
499+ (* FIND ALL THE MATCHES AND PUT IN RESULT LIST *)
500500 (* Str.search_forward/backward has side effect: *)
501501 (* The next call to Str.matched_string will return the matched string *)
502502 let last_match_reached = ref false in
@@ -521,7 +521,7 @@ let do_search (args : search_params) =
521521 (* Iterate backwards until words_after + 1 spaces are found *)
522522 let spaces_prior = ref 0 in
523523 let spaces_after = ref 0 in
524- while ((! endpos < (String. length str_to_search))
524+ while ((! endpos < (( String. length str_to_search) - 1 ))
525525 && (! spaces_after < (after + 1 ))) do
526526 endpos := ! endpos + 1 ;
527527 if str_to_search.[! endpos] = ' ' then begin
@@ -534,13 +534,13 @@ let do_search (args : search_params) =
534534 && (! spaces_prior < (before + 1 ))) do
535535 startpos := ! startpos - 1 ;
536536 if str_to_search.[! startpos] = ' ' then begin
537- spaces_prior := ! spaces_prior + 1 ;
537+ spaces_prior := ! spaces_prior + 1 ;
538538 end
539539 done ;
540540
541541 (* Make sure that the starting position is always
542542 not a space, to index into the timestamps *)
543- if str_to_search.[! startpos] = ' ' then begin
543+ if (( ! startpos > 0 ) && ( str_to_search.[! startpos] = ' ' )) then begin
544544 startpos := ! startpos + 1 ;
545545 end ;
546546
0 commit comments