mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-04-15 23:08:21 +02:00
whisper : only trim if split_on_word is true (#476)
This commit is contained in:
parent
ab1916fc59
commit
4dd7119deb
12
whisper.cpp
12
whisper.cpp
@ -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) {
|
static inline bool should_split_on_word(const char * txt, bool split_on_word) {
|
||||||
if (!split_on_word) return true;
|
if (!split_on_word) return true;
|
||||||
|
|
||||||
std::string s = txt;
|
return txt[0] == ' ';
|
||||||
return s.substr(0, 1) == " ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap the last segment to max_len characters
|
// 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
|
|||||||
|
|
||||||
if (acc + cur > max_len && i > 0 && should_split_on_word(txt, split_on_word)) {
|
if (acc + cur > max_len && i > 0 && should_split_on_word(txt, split_on_word)) {
|
||||||
// split here
|
// split here
|
||||||
trim(text);
|
if (split_on_word) {
|
||||||
|
trim(text);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.result_all.back().text = std::move(text);
|
ctx.result_all.back().text = std::move(text);
|
||||||
ctx.result_all.back().t1 = token.t0;
|
ctx.result_all.back().t1 = token.t0;
|
||||||
ctx.result_all.back().tokens.resize(i);
|
ctx.result_all.back().tokens.resize(i);
|
||||||
@ -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);
|
ctx.result_all.back().text = std::move(text);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user