| 388 | } |
| 389 | |
| 390 | double punctuation_bonus_seconds(const std::string & text) { |
| 391 | double bonus = 0.0; |
| 392 | for (size_t i = 0; i < text.size(); ++i) { |
| 393 | const char ch = text[i]; |
| 394 | if (ch == '.' && i + 2 < text.size() && text[i + 1] == '.' && text[i + 2] == '.') { |
| 395 | bonus += 1.0; |
| 396 | i += 2; |
| 397 | } else if (ch == ',' || ch == ';' || ch == ':') { |
| 398 | bonus += 0.20; |
| 399 | } else if (ch == '.' || ch == '!' || ch == '?') { |
| 400 | bonus += 0.40; |
| 401 | } else if (ch == '-' && i + 1 < text.size() && text[i + 1] == '-') { |
| 402 | bonus += 0.12; |
| 403 | ++i; |
| 404 | } |
| 405 | } |
| 406 | if (!text.empty()) { |
| 407 | const char last = text.back(); |
| 408 | if ((last == '.' || last == '!' || last == '?') && bonus >= 0.40) { |
| 409 | bonus -= 0.40; |
| 410 | } |
| 411 | } |
| 412 | return std::min(10.0, bonus); |
| 413 | } |
| 414 | |
| 415 | double length_penalty(const std::string & text, const std::vector<int32_t> & tokens, const std::string & language) { |
| 416 | const double duration_sec = static_cast<double>(tokens.size()) / kBestOfNTokenRateHz; |
no test coverage detected