MCPcopy Create free account
hub / github.com/daisy/MathCAT / compute_auto_pause

Method compute_auto_pause

src/tts.rs:589–628  ·  view source on GitHub ↗

Compute the length of the pause to use. The computation is based on the length of the speech strings (after removing tagging). There is a bias towards pausing more _after_ longer strings.

(&self, prefs: &PreferenceManager, before: &str, after: &str)

Source from the content-addressed store, hash-verified

587 /// The computation is based on the length of the speech strings (after removing tagging).
588 /// There is a bias towards pausing more _after_ longer strings.
589 pub fn compute_auto_pause(&self, prefs: &PreferenceManager, before: &str, after: &str) -> String {
590 lazy_static! {
591 static ref REMOVE_XML: Regex = Regex::new(r"<.+?>").unwrap(); // punctuation ending with a '.'
592 }
593 let before_len;
594 let after_len;
595 match self {
596 TTS::SSML | TTS::SAPI5 => {
597 before_len = REMOVE_XML.replace_all(before, "").len();
598 after_len = REMOVE_XML.replace_all(after, "").len();
599 },
600 _ => {
601 before_len = before.len();
602 after_len = after.len();
603 },
604 }
605
606 // pause values are not cut in stone
607 // the calculation bias to 'previous' is based on MathPlayer which used '30 * #-of-descendants-on-left
608 // I think I did this as a sort of "take a breath" after saying something long although one might want to do that
609 // before speaking something long.
610 if after_len < 3 {
611 // hack to prevent pausing before "of" in exprs like "the fourth power of secant, of x"
612 // if it should pause anywhere, it should be after the "of"
613 return "".to_string();
614 }
615 let pause = std::cmp::min(3000, ((2 * before_len + after_len)/48) * 128);
616 // create a TTSCommandRule so we reuse code
617 let command = TTSCommandRule::new(
618 TTSCommand::Pause,
619 TTSCommandValue::Number(pause as f64),
620 ReplacementArray::build_empty(),
621 );
622 return match self {
623 TTS::None => self.get_string_none(&command, prefs, true),
624 TTS::SSML => self.get_string_ssml(&command, prefs, true),
625 TTS::SAPI5 => self.get_string_sapi5(&command, prefs, true),
626 };
627
628 }
629
630 /// Take the longest of the pauses
631 ///

Callers 1

replace_array_stringMethod · 0.80

Calls 4

lenMethod · 0.80
get_string_noneMethod · 0.80
get_string_ssmlMethod · 0.80
get_string_sapi5Method · 0.80

Tested by

no test coverage detected