(values: &Yaml)
| 142 | |
| 143 | impl 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)] |
no test coverage detected