Add speech synthesis

This commit is contained in:
2023-08-30 18:40:34 +03:00
parent 43eff8bda2
commit e8071493f8
2 changed files with 39 additions and 0 deletions

View File

@ -1287,6 +1287,24 @@ export class UserAPI {
abs = Math.abs;
// =============================================================
// Speed synthesis
// =============================================================
speak = (text: string, index: number): void => {
/*
* Speaks the given text using the browser's speech synthesis API.
* @param text - The text to speak
* @param index - The index of the voice to use
*/
const synth = window.speechSynthesis;
synth.cancel();
const utterance = new SpeechSynthesisUtterance(text);
utterance.voice = speechSynthesis.getVoices()[index];
synth.speak(utterance);
}
// =============================================================
// Trivial functions
// =============================================================