-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.html
114 lines (90 loc) · 3.19 KB
/
upload.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Constellations of Sounds - UPLOAD</title>
<style>
body {
padding: 0;
margin: 0;
background-color: #000;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.1.slim.min.js" integrity="sha256-w8CvhFs7iHNVUtnSP0YKEg00p9Ih13rlL9zGqvLdePA=" crossorigin="anonymous"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-storage.js"></script>
<script src="js/p5.min.js"></script>
<script src="js/p5.sound.min.js"></script>
<script src="js/storage.js"></script>
<script>
</script>
</head>
<body>
<div style="text-align: center; padding-top:50px;" >
<button id="record" style="display: inline-block; margin-bottom: 50px; width:200px; height: 200px ">START RECORDING</button> <br/>
<button id="upload_file" style="display: inline-block; margin-bottom: 50px; width:200px; height: 100 ">UPLOAD FILE</button> <br/>
<button id="upload" style="display: inline-block;margin-bottom: 50px; width:200px; height: 100px;" disabled>UPLOAD</button><br/>
<button id="map" style="display: inline-block; width:200px; height: 50px;">GO TO MAP</button>
</div>
</body>
<script>
var recorder, mic, soundFile;
var isRecording = false;
function setup() {
mic = new p5.AudioIn();
mic.start()
// create a sound recorder
recorder = new p5.SoundRecorder();
// connect the mic to the recorder
recorder.setInput(mic);
soundFile = new p5.SoundFile();
}
document.getElementById('record').onclick = function(){
userStartAudio();
if (isRecording) {
document.getElementById('record').innerHTML = "START RECORDING";
isRecording = false;
// stop recordding
recorder.stop();
document.getElementById("upload").disabled = false;
} else {
document.getElementById('record').innerHTML = "STOP RECORDING";
isRecording = true;
// start recordimg
recorder.record(soundFile);
}
}
document.getElementById('upload_file').onclick = function(){
readFile(files);
}
document.getElementById('upload').onclick = function(){
if (soundFile) {
uploadRecord(soundFile.getBlob());
soundFile = true;
document.getElementById("upload").disabled = true;
}
}
document.getElementById('map').onclick = function(){
window.location = "/";
}
function readFile(files) {
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(files[0]);
fileReader.onload = function(e) {
playAudioFile(e.target.result);
console.log(("Filename: '" + files[0].name + "'"), ( "(" + ((Math.floor(files[0].size/1024/1024*100))/100) + " MB)" ));
}
}
function playAudioFile(file) {
var context = new window.AudioContext();
context.decodeAudioData(file, function(buffer) {
var source = context.createBufferSource();
source.buffer = buffer;
source.loop = false;
source.connect(context.destination);
source.start(0);
});
}
</script>
</html>