File size: 1,694 Bytes
1f9c6da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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();
});