| 28 | } |
| 29 | |
| 30 | void validate_word(const runtime::WordTimestamp & word, int64_t previous_start) { |
| 31 | if (word.word.empty()) { |
| 32 | throw std::runtime_error("subtitle formatter received an empty word"); |
| 33 | } |
| 34 | if (word.word.find('\n') != std::string::npos || word.word.find('\r') != std::string::npos) { |
| 35 | throw std::runtime_error("subtitle formatter received a word containing a newline"); |
| 36 | } |
| 37 | if (word.span.start_sample < 0 || word.span.end_sample < 0) { |
| 38 | throw std::runtime_error("subtitle formatter received a negative timestamp"); |
| 39 | } |
| 40 | if (word.span.end_sample < word.span.start_sample) { |
| 41 | throw std::runtime_error("subtitle formatter received an invalid timestamp span"); |
| 42 | } |
| 43 | if (word.span.start_sample < previous_start) { |
| 44 | throw std::runtime_error("subtitle formatter requires sorted word timestamps"); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | int64_t seconds_to_samples(double seconds, int sample_rate) { |
| 49 | return static_cast<int64_t>(std::llround(seconds * static_cast<double>(sample_rate))); |
no test coverage detected