forked from Acedio/animalese.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
62 lines (54 loc) · 2.08 KB
/
index.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
<html>
<head>
<title>animalese.js Demo</title>
</head>
<script src="riffwave.js"></script>
<script src="Blob.js"></script>
<script src="FileSaver.min.js"></script>
<script src="animalese.js"></script>
<script>
function dataURItoBlob(dataURI) {
// convert base64/URLEncoded data component to raw binary data held in a string
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to a typed array
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia], {type:mimeString});
}
var synth = new Animalese('animalese.wav', function() {
document.getElementById("preview").disabled = false;
document.getElementById("download").disabled = false;
});
function generateWav() {
return synth.Animalese(document.getElementById("text").value,
document.getElementById("shorten").checked,
document.getElementById("pitch").value).dataURI;
}
function preview() {
var audio = new Audio();
audio.src = generateWav();
audio.play();
}
function download() {
var wave = generateWav();
saveAs(dataURItoBlob(wave), "animalese.wav");
}
</script>
<body>
<h2>animalese.js Demo</h2>
<p>More information and the source at <a href="https://github.com/Acedio/animalese.js">https://github.com/Acedio/animalese.js</a>.</p>
<textarea id="text" rows"4" cols="50">Testing out animalese.js. Did it work?</textarea><br/>
<label>Shorten words<input id="shorten" type="checkbox"/></label><br/>
<label>Grump<input id="pitch" type="range" min="0.2" max="2.0" value="1.0" step="0.1"/>Isabelle</label><br/>
<button id="preview" type="button" disabled="true" onclick="preview()">Preview!</button>
<button id="download" type="button" disabled="false" onclick="download()">Download!</button>
</body>
</html>