speak.mjs - <short description TODO> Copyright (C) 2022 Strudel contributors - see https://codeberg.org/uzu/strudel/src/branch/main/packages/core/speak.mjs This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
7import { register } from './index.mjs';
console.log('voices', allVoices);
19function triggerSpeech(words, lang, voice) { 20 synth.cancel(); 21 const utterance = new SpeechSynthesisUtterance(words); 22 utterance.lang = lang; 23 allVoices = synth.getVoices(); 24 const voices = allVoices.filter((v) => v.lang.includes(lang)); 25 if (typeof voice === 'number') { 26 utterance.voice = voices[voice % voices.length]; 27 } else if (typeof voice === 'string') { 28 utterance.voice = voices.find((voice) => voice.name === voice); 29 } 30 // console.log(utterance.voice?.name, utterance.voice?.lang); 31 speechSynthesis.speak(utterance); 32}