boolemancer commited on
Commit
1813d16
·
unverified ·
1 Parent(s): 398871a

whisper : only trim if split_on_word is true (#476)

Browse files
Files changed (1) hide show
  1. whisper.cpp +8 -4
whisper.cpp CHANGED
@@ -3014,8 +3014,7 @@ static inline void trim(std::string &s) {
3014
  static inline bool should_split_on_word(const char * txt, bool split_on_word) {
3015
  if (!split_on_word) return true;
3016
 
3017
- std::string s = txt;
3018
- return s.substr(0, 1) == " ";
3019
  }
3020
 
3021
  // wrap the last segment to max_len characters
@@ -3039,7 +3038,10 @@ static int whisper_wrap_segment(struct whisper_context & ctx, int max_len, bool
3039
 
3040
  if (acc + cur > max_len && i > 0 && should_split_on_word(txt, split_on_word)) {
3041
  // split here
3042
- trim(text);
 
 
 
3043
  ctx.result_all.back().text = std::move(text);
3044
  ctx.result_all.back().t1 = token.t0;
3045
  ctx.result_all.back().tokens.resize(i);
@@ -3067,7 +3069,9 @@ static int whisper_wrap_segment(struct whisper_context & ctx, int max_len, bool
3067
  }
3068
  }
3069
 
3070
- trim(text);
 
 
3071
  ctx.result_all.back().text = std::move(text);
3072
 
3073
  return res;
 
3014
  static inline bool should_split_on_word(const char * txt, bool split_on_word) {
3015
  if (!split_on_word) return true;
3016
 
3017
+ return txt[0] == ' ';
 
3018
  }
3019
 
3020
  // wrap the last segment to max_len characters
 
3038
 
3039
  if (acc + cur > max_len && i > 0 && should_split_on_word(txt, split_on_word)) {
3040
  // split here
3041
+ if (split_on_word) {
3042
+ trim(text);
3043
+ }
3044
+
3045
  ctx.result_all.back().text = std::move(text);
3046
  ctx.result_all.back().t1 = token.t0;
3047
  ctx.result_all.back().tokens.resize(i);
 
3069
  }
3070
  }
3071
 
3072
+ if (split_on_word) {
3073
+ trim(text);
3074
+ }
3075
  ctx.result_all.back().text = std::move(text);
3076
 
3077
  return res;