forked from DainisGorbunovs/SongID
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
166 lines (145 loc) · 5.17 KB
/
index.html
File metadata and controls
166 lines (145 loc) · 5.17 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="img/logo.png">
<title>SongID</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
<script src="//cdn.webrtc-experiment.com/RecordRTC.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function outputFunction(artist, title){
window.location.href = "#result";
$("#artist").text(artist);
$("#song").text(title);
$("#title").text("Done");
$.get('/search/' + encodeURIComponent(artist + ' ' + title), function(data){
$('#youtube').attr('src', 'https://www.youtube.com/embed/' +data.videoId);
console.log(data.videoId);
});
}
</script>
<script>
// Make getUserMedia work for any browser
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
// In this session, record only audio
var session = {
audio: true,
video: false
};
// Establish a stream and record
var recordRTC = null;
var audioStream = null;
function initializeRecorder() {
$("#brand-logo")[0].textContent = "Recording";
navigator.getUserMedia(session, function (stream) {
audioStream = stream;
recordRTC = RecordRTC(stream, {
recorderType: StereoAudioRecorder // optionally force WebAudio API to record audio
});
recordRTC.startRecording();
}, function (error) {
console.log(error);
});
}
function stopRecorder() {
$("#brand-logo")[0].textContent = "Stopped";
audioStream.stop();
audioStream = null;
recordRTC.stopRecording(function (audioURL) {
console.log(audioURL);
var formData = new FormData();
formData.append('audio', recordRTC.getBlob());
$.ajax({
type: 'POST',
url: 'identify',
data: formData,
contentType: false,
cache: false,
processData: false
}).done(function(data) {
var artist = data.matches[0].metadata.artist || '';
var title = data.matches[0].metadata.title || '';
outputFunction(artist, title);
});
});
}
</script>
<script>
// Record button
$(document).ready(function () {
var recording = false;
$("#brand-logo")[0].addEventListener("click", function () {
recording = !recording; // change state
if (recording === true) {
initializeRecorder();
setTimeout(function() {
if (recording === true) {
stopRecorder();
}
}, 10000);
} else {
stopRecorder();
}
});
});
</script>
<h1 id="title">Start. Record. Discover.</h1>
<div class="header">
<img src="img/logo.png" id="brand-logo">
</div>
<a id="cancel" href="index.html">Cancel</a>
<div id="result" class="overlay">
<div class="popup">
<h2 style="text-align: center;">Result</h2>
<a class="close" href="#">×</a>
<div class="content">
<h1 id="artist"></h1>
<h2 id="song"></h2>
<iframe id="youtube" width="420" height="315"
src="">
</iframe>
</div>
</div>
<script type="text/javascript">
function setTitle(title){
$("#title").text(title);
console.log(title);
};
$("#brand-logo").hover(function(){
if($("#title").text() == "Start. Record. Discover.")
$("#title").text("Start");
});
$("#brand-logo").click(function(){
title = $("#title").text();
if(title == "Start"){
setTitle("Listening...");
setTimeout(function() {
setTitle("Processing...");
}, 10000);
rotateAnimation("brand-logo", 10);
}
else if(title == "Listening..."){
rotateAnimation("brand-logo", 10000000000000000);
console.log("Hola");
};
});
</script>
<script type="text/javascript">
var degrees = 0;
var looper;
function rotateAnimation(id,speed){
var elem = document.getElementById(id);
elem.style.WebkitTransform = "rotate("+degrees+"deg)";
looper = setTimeout('rotateAnimation(\''+id+'\','+speed+')',speed);
degrees++;
if(degrees > 359){
degrees = 1;
}
}
</script>
</body>
</html>