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

Method build

src/tts.rs:144–183  ·  view source on GitHub ↗
(values: &Yaml)

Source from the content-addressed store, hash-verified

142
143impl Pronounce {
144 fn build(values: &Yaml) -> Result<Pronounce> {
145 use crate::speech::{as_str_checked, yaml_to_type};
146 use crate::pretty_print::yaml_to_string;
147
148 let mut text = "";
149 let mut ipa = "";
150 let mut sapi5 = "";
151 let mut eloquence = "";
152 // values should be an array with potential values for Pronounce
153 let values = values.as_vec().ok_or_else(||
154 format!("'pronounce' value '{}' is not an array", yaml_to_type(values)))?;
155 for key_value in values {
156 let key_value_hash = key_value.as_hash().ok_or_else(||
157 format!("pronounce value '{}' is not key/value pair", yaml_to_string(key_value, 0)))?;
158 if key_value_hash.len() != 1 {
159 bail!("pronounce value {:?} is not a single key/value pair", key_value_hash);
160 }
161
162 for (key, value) in key_value_hash {
163 match as_str_checked(key)? {
164 "text" => text = as_str_checked(value)?,
165 "ipa" => ipa = as_str_checked(value)?,
166 "sapi5" => sapi5 = as_str_checked(value)?,
167 "eloquence" => eloquence = as_str_checked(value)?,
168 _ => bail!("unknown pronounce type: {} with value {}", yaml_to_string(key, 0), yaml_to_string(value, 0)),
169 }
170 }
171 }
172 if text.is_empty() {
173 bail!("'text' key/value is required for 'pronounce' -- it is used is the speech engine is unknown.")
174 }
175 return Ok( Pronounce{
176 text: text.to_string(),
177 ipa: ipa.to_string(),
178 sapi5: sapi5.to_string(),
179 eloquence: eloquence.to_string()
180 } );
181
182
183 }
184}
185/// TTSCommands are either numbers (f64 because of YAML) or strings
186#[derive(Debug, Clone)]

Callers 1

context_get_variableFunction · 0.45

Calls 5

as_str_checkedFunction · 0.85
yaml_to_stringFunction · 0.85
PronounceClass · 0.85
lenMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected