mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 02:01:22 +01:00
refactor(es modules): dissolve general.js
This commit is contained in:
parent
9206f46c42
commit
2e4d142cf7
90 changed files with 802 additions and 749 deletions
22
src/scripts/speaker.ts
Normal file
22
src/scripts/speaker.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue