-
Notifications
You must be signed in to change notification settings - Fork 112
/
02speechbox.html
84 lines (75 loc) · 1.99 KB
/
02speechbox.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.5/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.5/addons/p5.dom.js"></script>
<script src="../lib/p5.speech.js"></script>
<script>
var myVoice = new p5.Speech(); // new P5.Speech object
var menuLoaded = 0;
var label, input, checkbox, speakbutton, vslider, rslider, pslider; // UI
function setup()
{
// input dialog:
input = createInput("testing one two three!!!");
input.style("width", 400);
input.position(20, 65);
// checkbox:
checkbox = createInput(0, 1, 0);
checkbox.attribute("type", "checkbox");
checkbox.style("width", "15px");
checkbox.style("height", "15px");
checkbox.position(100, 100);
// button:
speakbutton = createButton('Speak');
speakbutton.position(20, 100);
speakbutton.mousePressed(doSpeak);
// sliders:
vslider = createSlider(0., 100., 100.);
vslider.position(20, 140);
vslider.mouseReleased(setVolume);
rslider = createSlider(10., 200., 100.);
rslider.position(20, 160);
rslider.mouseReleased(setRate);
pslider = createSlider(1., 200., 100.);
pslider.position(20, 180);
pslider.mouseReleased(setPitch);
// labels:
label = createDiv("say something:");
label.position(20, 40);
label = createDiv("interrupt?");
label.position(125, 100);
label = createDiv("volume");
label.position(160, 140);
label = createDiv("rate");
label.position(160, 160);
label = createDiv("pitch");
label.position(160, 180);
// say hello:
myVoice.speak(input.value());
}
function setVolume()
{
myVoice.setVolume(vslider.value()/100.);
}
function setRate()
{
myVoice.setRate(rslider.value()/100.);
}
function setPitch()
{
myVoice.setPitch(pslider.value()/100.);
}
function draw()
{
// why draw when you can click?
}
function doSpeak()
{
myVoice.interrupt = checkbox.elt.checked;
myVoice.speak(input.value()); // debug printer for voice options
}
</script>
</head>
<body>
</body>
</html>