Skip to content

Commit

Permalink
whisper : only trim if split_on_word is true (ggerganov#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
boolemancer authored Feb 8, 2023
1 parent ab1916f commit 4dd7119
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,8 +3014,7 @@ static inline void trim(std::string &s) {
static inline bool should_split_on_word(const char * txt, bool split_on_word) {
if (!split_on_word) return true;

std::string s = txt;
return s.substr(0, 1) == " ";
return txt[0] == ' ';
}

// wrap the last segment to max_len characters
Expand All @@ -3039,7 +3038,10 @@ static int whisper_wrap_segment(struct whisper_context & ctx, int max_len, bool

if (acc + cur > max_len && i > 0 && should_split_on_word(txt, split_on_word)) {
// split here
trim(text);
if (split_on_word) {
trim(text);
}

ctx.result_all.back().text = std::move(text);
ctx.result_all.back().t1 = token.t0;
ctx.result_all.back().tokens.resize(i);
Expand Down Expand Up @@ -3067,7 +3069,9 @@ static int whisper_wrap_segment(struct whisper_context & ctx, int max_len, bool
}
}

trim(text);
if (split_on_word) {
trim(text);
}
ctx.result_all.back().text = std::move(text);

return res;
Expand Down

0 comments on commit 4dd7119

Please sign in to comment.