MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / validate_word

Function validate_word

src/framework/text/subtitle.cpp:30–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30void 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
48int64_t seconds_to_samples(double seconds, int sample_rate) {
49 return static_cast<int64_t>(std::llround(seconds * static_cast<double>(sample_rate)));

Callers 1

build_subtitle_blocksFunction · 0.85

Calls 2

emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected