-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
95 lines (87 loc) · 2.52 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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Audio Recorder Test</title>
<style type="text/css">
ul { list-style: none; }
#recordingslist audio { display: block; margin-bottom: 10px; }
</style>
<script src="MicrophoneSource.js"></script>
<script src="MP3Encoder.js"></script>
<script src="Resampler.js"></script>
<script src="Recorder.js"></script>
</head>
<body>
<h1>Record to MP3 Test</h1>
<button id="init">initialize</button>
<button id="start" disabled>record</button>
<button id="stop" disabled="">stop</button>
<h2>Recordings</h2>
<ul id="reclist"></ul>
<h2>Log</h2>
<pre id="log"></pre>
<script>
MP3Encoder.LAME_URI = "http://localhost/Lyrebird.js/libmp3lame.js";
var recorder,
init = document.getElementById('init'),
start = document.getElementById('start'),
stop = document.getElementById('stop'),
log = document.getElementById('log'),
reclist = document.getElementById('reclist');
function __log(e, data) {
log.innerHTML += "\n" + e + " " + (data || '');
}
start.addEventListener('click',function(){
start.disabled = true;
stop.disabled = false;
recorder.record();
__log('Started recording.');
},false);
stop.addEventListener('click',function(){
stop.disabled = true;
start.disabled = false;
recorder.pause();
recorder.finish().then(download);
__log('Stopped recording.');
},false);
init.addEventListener('click',function(){
var sourcep = (new MicrophoneSource({bufferSize:4096}));
init.disabled = true;
sourcep.then(function(source){
var encoder = new MP3Encoder({
//samplerate: source.samplerate,
channels: source.channels
});
__log('Microphone initialised.');
__log('Encoder initialised.');
return (new AudioRecorder(source,encoder)).then(function(r){
__log('Recorder initialised.');
recorder = r;
recorder.on('data',function(data){
console.log("Finished",recorder.finished,"of",recorder.queued);
});
start.disabled = false;
});
}).then(void 0,function(err){
init.disabled = false;
__log(err.message || err);
console.log(err.message);
console.log(err.stack);
});
},false);
function download(blob){
var li, link, name;
__log("Done converting to Mp3");
name = 'audio_recording_' + new Date().getTime() + '.mp3';
link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = name;
link.innerHTML = name;
li = document.createElement('li');
li.appendChild(link);
reclist.appendChild(li);
}
</script>
</body>
</html>