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

Function speak_rules

src/speech.rs:102–130  ·  view source on GitHub ↗

Speak the MathML If 'nav_node_id' is not an empty string, then the element with that id will have [[...]] around it

(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, mathml: Element, nav_node_id: &str)

Source from the content-addressed store, hash-verified

100/// Speak the MathML
101/// If 'nav_node_id' is not an empty string, then the element with that id will have [[...]] around it
102fn speak_rules(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, mathml: Element, nav_node_id: &str) -> Result<String> {
103 SpeechRules::update()?;
104 rules.with(|rules| {
105 rules.borrow_mut().read_files()?;
106 let rules = rules.borrow();
107 // debug!("speak_rules:\n{}", mml_to_string(&mathml));
108 let new_package = Package::new();
109 let mut rules_with_context = SpeechRulesWithContext::new(&rules, new_package.as_document(), nav_node_id);
110 let mut speech_string = rules_with_context.match_pattern::<String>(mathml)
111 .chain_err(|| "Pattern match/replacement failure!")?;
112 if !nav_node_id.is_empty() {
113 // See https://github.com/NSoiffer/MathCAT/issues/174 for why we can just start the speech at the nav node
114 if let Some(start) = speech_string.find("[[") {
115 match speech_string[start+2..].find("]]") {
116 None => bail!("Internal error: looking for '[[...]]' during navigation -- only found '[[' in '{}'", speech_string),
117 Some(end) => speech_string = speech_string[start+2..start+2+end].to_string(),
118 }
119 } else {
120 bail!(NAV_NODE_SPEECH_NOT_FOUND);
121 }
122 }
123 return Ok( rules.pref_manager.borrow().get_tts()
124 .merge_pauses(remove_optional_indicators(
125 &speech_string.replace(CONCAT_STRING, "")
126 .replace(CONCAT_INDICATOR, "")
127 )
128 .trim()) );
129 })
130}
131
132
133/// Converts its argument to a string that can be used in a debugging message.

Callers 2

speak_mathmlFunction · 0.85
overview_mathmlFunction · 0.85

Calls 6

read_filesMethod · 0.80
is_emptyMethod · 0.80
merge_pausesMethod · 0.80
get_ttsMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected