| 352 | |
| 353 | std::string detect_best_of_n_language(const std::string & text) { |
| 354 | const auto codepoints = utf8_codepoints(text, "MioTTS best_of_n text"); |
| 355 | int64_t total = 0; |
| 356 | int64_t ja_count = 0; |
| 357 | int64_t en_count = 0; |
| 358 | for (const uint32_t cp : codepoints) { |
| 359 | if (cp == ' ' || cp == '\n' || cp == '\r' || cp == '\t') { |
| 360 | continue; |
| 361 | } |
| 362 | ++total; |
| 363 | if (is_japanese_codepoint(cp)) { |
| 364 | ++ja_count; |
| 365 | } |
| 366 | if (cp <= 0x7FU && is_ascii_alpha(static_cast<unsigned char>(cp))) { |
| 367 | ++en_count; |
| 368 | } |
| 369 | } |
| 370 | if (total == 0) { |
| 371 | return "auto"; |
| 372 | } |
| 373 | if (static_cast<double>(ja_count) / static_cast<double>(total) >= 0.2) { |
| 374 | return "ja"; |
no test coverage detected