eframe/web/screen_reader.rs
1/// Speak the given text out loud.
2pub fn speak(text: &str) {
3 if text.is_empty() {
4 return;
5 }
6
7 if let Some(window) = web_sys::window() {
8 log::debug!("Speaking {text:?}");
9
10 if let Ok(speech_synthesis) = window.speech_synthesis() {
11 speech_synthesis.cancel(); // interrupt previous speech, if any
12
13 if let Ok(utterance) = web_sys::SpeechSynthesisUtterance::new_with_text(text) {
14 utterance.set_rate(1.0);
15 utterance.set_pitch(1.0);
16 utterance.set_volume(1.0);
17 speech_synthesis.speak(&utterance);
18 }
19 }
20 }
21}