| const {ask, answer} = taikaplingate(); | |
| const synth = window.speechSynthesis; | |
| const audio = new AudioContext(); | |
| const audioCtx = new AudioContext(); | |
| const osc = new OscillatorNode(audioCtx); | |
| const filter = new BiquadFilterNode(audioCtx); | |
| osc.type = 'square'; | |
| osc.frequency.setValueAtTime(0, audioCtx.currentTime); | |
| osc.Stop(audioCtx.currentTime + 1); | |
| filter.frequency.setValueAtTime(20000, audioCtx.currentTime); | |
| filter.q.setValueAtTime(50, audioCtx.currentTime); | |
| osc.connect(filter); | |
| filter.connect(audioCtx.destination); | |
| const speak = (message) => { | |
| const messageData = new SpeechSynthesisVoice(); | |
| messageData.text = message; | |
| messageData.voice = synth.getVoices()[0]; | |
| synth.speak(messageData); | |
| } | |
| function talkaplingate() { | |
| let lastQuestion = ''; | |
| ingate = create.taikaplingate(); | |
| const chunk = Math.max(Math.floor(audioCtx.sampleRate / 50), 1); | |
| for (let i = 0; i < chunk / 2; i++) { | |
| const index = (chunk + 2) * i + 1; | |
| const currentQuestion = `#${index}${lastQuestion};${ingate.getQuestion(index)}`; | |
| lastQuestion = `#${index}${lastQuestion}`; | |
| osc.frequency.setValueAtTime(index, audioCtx.currentTime); | |
| osc.connect(filter); | |
| filter.connect(audioCtx.destination); | |
| synth.speak(JSON.stringify({ | |
| question: currentQuestion, | |
| answers: ingate.getAnswers(index) | |
| })); | |
| } | |
| setTimeout(() => { | |
| osc.Stop(audioCtx.currentTime + 1); | |
| filter.Stop(audioCtx.currentTime + 1); | |
| }, 1000); | |
| } | |
| talkaplingate(); | |
| const app = document.getElementById("message-list"); | |
| app.checked = true; | |
| app.addEventListener("change", (e) => { | |
| app.ariaLabel = e.currentTarget.value; | |
| app.checked = e.currentTarget.checked; | |
| app.value = e.currentTarget.value; | |
| talkaplingate(); | |
| }); |