-
Notifications
You must be signed in to change notification settings - Fork 0
/
luyin.php
93 lines (91 loc) · 4.28 KB
/
luyin.php
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset = "utf-8"/>
<title>Chat by Web Sockets</title>
<script type="text/javascript" src="js/jquery.min.js"> </script>
<script type="text/javascript" src="js/recorder.js"> </script>
<style type='text/css'>
</style>
</head>
<body>
<audio controls autoplay src=""></audio>
<input type="button" id="record" value="Record">
<input type="button" id="export" value="Export">
<div id="message"></div>
</body>
<script type='text/javascript'>
var onFail = function(e) {
console.log('Rejected!', e);
};
var onSuccess = function(s) {
window.AudioContext = window.AudioContext||window.webkitAudioContext;
var context = new AudioContext();
var mediaStreamSource = context.createMediaStreamSource(s);
rec = new Recorder(mediaStreamSource);
rec.record();
// audio loopback
// mediaStreamSource.connect(context.destination);
}
var navigatorMedia = null;
window.URL = URL || window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
var rec;
var audio = document.querySelector('audio');
function startRecording() {
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, onSuccess, onFail);
} else {
console.log('navigator.getUserMedia not present');
}
}
startRecording();
//--------------------
$('#record').click(function() {
rec.record();
// var dd = ws.send("start");
$("#message").text("Click export to stop recording");
// export a wav every second, so we can send it using websockets
// intervalKey = setInterval(function() {
// }, 3000);
});
$('#export').click(function() {
// first send the stop command
rec.stop();
rec.exportWAV(function(blob) {
// rec.clear();
// ws.send(blob);
console.log(blob);
audio.src = URL.createObjectURL(blob);
console.log(audio.duration);
});
// clearInterval(intervalKey);
// ws.send("analyze");
$("#message").text("");
});
var ws = new WebSocket("ws://127.0.0.1:7272");
ws.onopen = function () {
console.log("Openened connection to websocket");
};
ws.onclose = function (){
console.log("Close connection to websocket");
}
// ws.onmessage = function(e) {
// audio.src = URL.createObjectURL(e.data);
// }
</script>
</html>