1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00
Files
egui/crates/eframe/src/web/screen_reader.rs
Emil Ernerfeldt a1f3c71b7f Remove dependency on tts (#3651)
We were using [`tts`](https://github.com/ndarilek/tts-rs) for the
web-only screen reader. This was overkill, to say the least. It is now
replaced with ten lines of `web-sys` calls.
2023-11-28 10:46:18 +01:00

22 lines
644 B
Rust

/// Speak the given text out loud.
pub fn speak(text: &str) {
if text.is_empty() {
return;
}
if let Some(window) = web_sys::window() {
log::debug!("Speaking {text:?}");
if let Ok(speech_synthesis) = window.speech_synthesis() {
speech_synthesis.cancel(); // interrupt previous speech, if any
if let Ok(utterance) = web_sys::SpeechSynthesisUtterance::new_with_text(text) {
utterance.set_rate(1.0);
utterance.set_pitch(1.0);
utterance.set_volume(1.0);
speech_synthesis.speak(&utterance);
}
}
}
}