mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
22 lines
658 B
TypeScript
22 lines
658 B
TypeScript
import {getInputNumber} from "utils/nodeUtils";
|
|
|
|
export function assignSpeakerBehavior() {
|
|
Array.from(document.getElementsByClassName("speaker")).forEach($speaker => {
|
|
const $sibling = $speaker.previousElementSibling;
|
|
$speaker.addEventListener("click", () => {
|
|
if ($sibling instanceof HTMLInputElement) {
|
|
speak($sibling.value);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function speak(str: string) {
|
|
const speaker = new SpeechSynthesisUtterance(str);
|
|
const voices = speechSynthesis.getVoices();
|
|
if (voices.length) {
|
|
const voiceId = getInputNumber("speakerVoice");
|
|
speaker.voice = voices[voiceId];
|
|
}
|
|
speechSynthesis.speak(speaker);
|
|
}
|