mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 07:03:14 -04:00
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.
22 lines
644 B
Rust
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);
|
|
}
|
|
}
|
|
}
|
|
}
|