Spaces:
Running
Running
s1w
commited on
Commit
•
30aff40
1
Parent(s):
d839ffd
fix: remove unused resources
Browse files- static/js/index_demo.js +0 -374
- static/js/recorder.mp3.min.js +0 -0
- static/js/waveview.js +0 -6
static/js/index_demo.js
DELETED
@@ -1,374 +0,0 @@
|
|
1 |
-
window.HELP_IMPROVE_VIDEOJS = false;
|
2 |
-
|
3 |
-
// var INTERP_BASE = "./static/interpolation/stacked";
|
4 |
-
var NUM_INTERP_FRAMES = 240;
|
5 |
-
|
6 |
-
var interp_images = [];
|
7 |
-
// function preloadInterpolationImages() {
|
8 |
-
// for (var i = 0; i < NUM_INTERP_FRAMES; i++) {
|
9 |
-
// var path = INTERP_BASE + '/' + String(i).padStart(6, '0') + '.jpg';
|
10 |
-
// interp_images[i] = new Image();
|
11 |
-
// interp_images[i].src = path;
|
12 |
-
// }
|
13 |
-
// }
|
14 |
-
|
15 |
-
// function setInterpolationImage(i) {
|
16 |
-
// var image = interp_images[i];
|
17 |
-
// image.ondragstart = function() { return false; };
|
18 |
-
// image.oncontextmenu = function() { return false; };
|
19 |
-
// $('#interpolation-image-wrapper').empty().append(image);
|
20 |
-
// }
|
21 |
-
|
22 |
-
|
23 |
-
$(document).ready(function() {
|
24 |
-
// Check for click events on the navbar burger icon
|
25 |
-
$(".navbar-burger").click(function() {
|
26 |
-
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
|
27 |
-
$(".navbar-burger").toggleClass("is-active");
|
28 |
-
$(".navbar-menu").toggleClass("is-active");
|
29 |
-
|
30 |
-
});
|
31 |
-
|
32 |
-
var options = {
|
33 |
-
slidesToScroll: 1,
|
34 |
-
slidesToShow: 3,
|
35 |
-
loop: true,
|
36 |
-
infinite: true,
|
37 |
-
autoplay: false,
|
38 |
-
autoplaySpeed: 3000,
|
39 |
-
}
|
40 |
-
|
41 |
-
// Initialize all div with carousel class
|
42 |
-
var carousels = bulmaCarousel.attach('.carousel', options);
|
43 |
-
|
44 |
-
// Loop on each carousel initialized
|
45 |
-
for(var i = 0; i < carousels.length; i++) {
|
46 |
-
// Add listener to event
|
47 |
-
carousels[i].on('before:show', state => {
|
48 |
-
console.log(state);
|
49 |
-
});
|
50 |
-
}
|
51 |
-
|
52 |
-
// Access to bulmaCarousel instance of an element
|
53 |
-
var element = document.querySelector('#my-element');
|
54 |
-
if (element && element.bulmaCarousel) {
|
55 |
-
// bulmaCarousel instance is available as element.bulmaCarousel
|
56 |
-
element.bulmaCarousel.on('before-show', function(state) {
|
57 |
-
console.log(state);
|
58 |
-
});
|
59 |
-
}
|
60 |
-
|
61 |
-
/*var player = document.getElementById('interpolation-video');
|
62 |
-
player.addEventListener('loadedmetadata', function() {
|
63 |
-
$('#interpolation-slider').on('input', function(event) {
|
64 |
-
console.log(this.value, player.duration);
|
65 |
-
player.currentTime = player.duration / 100 * this.value;
|
66 |
-
})
|
67 |
-
}, false);*/
|
68 |
-
// preloadInterpolationImages();
|
69 |
-
|
70 |
-
// $('#interpolation-slider').on('input', function(event) {
|
71 |
-
// setInterpolationImage(this.value);
|
72 |
-
// });
|
73 |
-
// setInterpolationImage(0);
|
74 |
-
// $('#interpolation-slider').prop('max', NUM_INTERP_FRAMES - 1);
|
75 |
-
|
76 |
-
bulmaSlider.attach();
|
77 |
-
|
78 |
-
})
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
// 全局初始化
|
85 |
-
// connect ws
|
86 |
-
var ws = null;
|
87 |
-
var recorder = null;
|
88 |
-
var isRecording = false;
|
89 |
-
var vc_enabled = location.search.split('vc=')[1] == '1' ? true : false;
|
90 |
-
var text = ''
|
91 |
-
var audio_base64 = null;
|
92 |
-
Recorder.CLog = function(){} //update
|
93 |
-
var wave = Recorder.WaveView({elem:"#waveform"}); //创建wave对象,写这里面浏览器妥妥的;
|
94 |
-
const audioPlayer = document.getElementById('audioPlayer');
|
95 |
-
const waveformDiv = document.getElementById('waveform');
|
96 |
-
const resultsDiv = document.getElementById('results');
|
97 |
-
const llasaLoading = document.getElementById('llasaLoading');
|
98 |
-
const container = document.getElementById('llasa');
|
99 |
-
|
100 |
-
// sent text element
|
101 |
-
function createSentMessageElement(message) {
|
102 |
-
const sentDiv = document.createElement('div');
|
103 |
-
sentDiv.id = 'sent';
|
104 |
-
sentDiv.setAttribute('class', 'd-flex flex-row justify-content-end mb-2 pt-1 text-start');
|
105 |
-
|
106 |
-
const sentMessageP = document.createElement('p');
|
107 |
-
sentMessageP.setAttribute('class', 'sent-message small p-2 me-2 mb-1 text-white rounded-3 bg-primary');
|
108 |
-
sentMessageP.textContent = message['value'];
|
109 |
-
sentMessageP.id = message['cid']
|
110 |
-
|
111 |
-
const imageDiv = document.createElement('div');
|
112 |
-
const senderImage = document.createElement('img');
|
113 |
-
senderImage.setAttribute('src', './images/user.png');
|
114 |
-
senderImage.setAttribute('class', 'rounded-4');
|
115 |
-
senderImage.setAttribute('alt', 'avatar 1');
|
116 |
-
senderImage.setAttribute('height', '30');
|
117 |
-
senderImage.setAttribute('width', '30');
|
118 |
-
imageDiv.appendChild(senderImage);
|
119 |
-
|
120 |
-
sentDiv.appendChild(sentMessageP);
|
121 |
-
sentDiv.appendChild(imageDiv);
|
122 |
-
|
123 |
-
return sentDiv;
|
124 |
-
}
|
125 |
-
|
126 |
-
// Function to add a new sent message to the DOM
|
127 |
-
function addSentMessageToDOM(message) {
|
128 |
-
const sentDiv = createSentMessageElement(message);
|
129 |
-
resultsDiv.appendChild(sentDiv);
|
130 |
-
}
|
131 |
-
|
132 |
-
function createRecieveMessageElement(message) {
|
133 |
-
const responseDiv = document.createElement("div");
|
134 |
-
responseDiv.id = "response";
|
135 |
-
responseDiv.classList.add("d-flex", "flex-row", "justify-content-start", "pt-2", "mb-2");
|
136 |
-
|
137 |
-
const imageDiv = document.createElement('div')
|
138 |
-
const avatarImg = document.createElement("img");
|
139 |
-
avatarImg.src = "../../images/gpt.png";
|
140 |
-
avatarImg.classList.add("rounded-4");
|
141 |
-
avatarImg.alt = "avatar 1";
|
142 |
-
avatarImg.height = 30;
|
143 |
-
avatarImg.width = 30;
|
144 |
-
imageDiv.appendChild(avatarImg)
|
145 |
-
responseDiv.appendChild(imageDiv);
|
146 |
-
|
147 |
-
const responseMessageP = document.createElement("p");
|
148 |
-
responseMessageP.id = message['cid'];
|
149 |
-
responseMessageP.classList.add("small", "p-2", "ms-2", "mb-1", "rounded-3");
|
150 |
-
responseMessageP.style.backgroundColor = "#f5f6f7";
|
151 |
-
responseMessageP.innerText = message['value'];
|
152 |
-
responseDiv.appendChild(responseMessageP);
|
153 |
-
|
154 |
-
return responseDiv;
|
155 |
-
}
|
156 |
-
|
157 |
-
// Function to add a new recieve message to the DOM
|
158 |
-
function addRecieveMessageToDOM(message) {
|
159 |
-
const reciDiv = createRecieveMessageElement(message);
|
160 |
-
resultsDiv.appendChild(reciDiv);
|
161 |
-
resultsDiv.scrollTo(0, resultsDiv.scrollHeight);
|
162 |
-
}
|
163 |
-
|
164 |
-
function createSentAudioMessageElement(message) {
|
165 |
-
const sentDiv = document.createElement('div');
|
166 |
-
sentDiv.id = 'sent';
|
167 |
-
sentDiv.className = 'd-flex flex-row justify-content-end mb-2 pt-1 text-start';
|
168 |
-
|
169 |
-
const audio = document.createElement('audio');
|
170 |
-
audio.controls = true;
|
171 |
-
audio.id = message['cid'];
|
172 |
-
audio.className = 'sent-message p-2 me-2 bg-primagry';
|
173 |
-
// audio.style.width = '200px';
|
174 |
-
|
175 |
-
const sourceElement = document.createElement('source');
|
176 |
-
sourceElement.src = message['value'];
|
177 |
-
// sourceElement.type = 'audio/ogg';
|
178 |
-
|
179 |
-
const unsupportedText = document.createTextNode('Your browser does not support the audio element.');
|
180 |
-
|
181 |
-
audio.appendChild(sourceElement);
|
182 |
-
audio.appendChild(unsupportedText);
|
183 |
-
|
184 |
-
const imageDiv = document.createElement('div')
|
185 |
-
const image = document.createElement('img');
|
186 |
-
image.src = '../../images/user.png';
|
187 |
-
image.id = 'sender-image';
|
188 |
-
image.className = 'rounded-4';
|
189 |
-
image.alt = 'avatar 1';
|
190 |
-
image.height = 30;
|
191 |
-
image.width = 30;
|
192 |
-
imageDiv.appendChild(image);
|
193 |
-
|
194 |
-
sentDiv.appendChild(audio);
|
195 |
-
sentDiv.appendChild(imageDiv);
|
196 |
-
|
197 |
-
return sentDiv;
|
198 |
-
}
|
199 |
-
|
200 |
-
// Function to add a new audio sent message to the DOM
|
201 |
-
function addAudioSentMessageToDOM(message) {
|
202 |
-
const sentDiv = createSentAudioMessageElement(message);
|
203 |
-
resultsDiv.appendChild(sentDiv);
|
204 |
-
resultsDiv.scrollTo(0, resultsDiv.scrollHeight);
|
205 |
-
}
|
206 |
-
|
207 |
-
// stream update response
|
208 |
-
function updateResponse(cID, answer) {
|
209 |
-
const responseP = document.getElementById("a_text_" + cID);
|
210 |
-
responseP.innerText = answer;
|
211 |
-
}
|
212 |
-
|
213 |
-
// connect ws
|
214 |
-
window.onload = async () => {
|
215 |
-
await connect();
|
216 |
-
}
|
217 |
-
|
218 |
-
async function connect() {
|
219 |
-
// url = ((window.location.protocol === "https:") ? "wss://" : "ws://") + window.location.host + "/api";
|
220 |
-
url = "wss://alm.linksoul.ai/api";
|
221 |
-
ws = new WebSocket(url);
|
222 |
-
ws.onopen = function (e) {
|
223 |
-
console.log('握手成功');
|
224 |
-
if (ws.readyState == 1) { //ws进入连接状态,则每隔500毫秒发送一包数据
|
225 |
-
console.log('连接状态成功');
|
226 |
-
// resultsDiv.style.display = '';
|
227 |
-
// llasaLoading.style.display = 'none';
|
228 |
-
container.style.opacity = 1;
|
229 |
-
llasaLoading.style.display = 'none';
|
230 |
-
}
|
231 |
-
};
|
232 |
-
|
233 |
-
ws.onmessage = function (e) {
|
234 |
-
console.log(e['data'])
|
235 |
-
var response = JSON.parse(e['data']);
|
236 |
-
if(response["action"] == "qa"){
|
237 |
-
// nothing to do
|
238 |
-
if(response['msg'] == 'ok') {
|
239 |
-
console.log(response["data"])
|
240 |
-
updateResponse(response['data']['cid'], response['data']['answer'])
|
241 |
-
}else{
|
242 |
-
console.log(response['msg']);
|
243 |
-
}
|
244 |
-
}
|
245 |
-
}
|
246 |
-
ws.onerror = function (err) {
|
247 |
-
console.info('ws error: '+err)
|
248 |
-
}
|
249 |
-
|
250 |
-
ws.onclose=function(e){
|
251 |
-
console.info('ws close: '+e);
|
252 |
-
};
|
253 |
-
}
|
254 |
-
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
|
255 |
-
const submitTextButton = document.getElementById('send_button');
|
256 |
-
submitTextButton.onclick = async () => {
|
257 |
-
await sendMessage();
|
258 |
-
}
|
259 |
-
async function sendMessage() {
|
260 |
-
if(ws == null || ws.readyState != 1) {
|
261 |
-
// alert('服务未连接,请刷新页面');
|
262 |
-
// return;
|
263 |
-
await connect();
|
264 |
-
await sleep(800);
|
265 |
-
}
|
266 |
-
var userTextDiv = document.getElementById('user-text');
|
267 |
-
text = userTextDiv.value
|
268 |
-
userTextDiv.value = ''
|
269 |
-
console.log('user input text', text);
|
270 |
-
console.log('user input audio', audio_base64);
|
271 |
-
if (text.length == 0 && audio_base64 == null) return;
|
272 |
-
var cid = crypto.randomUUID();
|
273 |
-
if (text.length > 0) {
|
274 |
-
addSentMessageToDOM({
|
275 |
-
'cid': "q_text_" + cid,
|
276 |
-
'from': 'human',
|
277 |
-
'value': text,
|
278 |
-
'type': 'text'
|
279 |
-
});
|
280 |
-
}
|
281 |
-
if (audio_base64 != null) {
|
282 |
-
addAudioSentMessageToDOM({
|
283 |
-
'cid': "q_audio_" + cid,
|
284 |
-
'from': 'human',
|
285 |
-
'value': audio_base64,
|
286 |
-
'type': 'audio'
|
287 |
-
});
|
288 |
-
}
|
289 |
-
|
290 |
-
ws.send(JSON.stringify({"action": "qa", "data":{"cid": cid, "text": text, "audio": audio_base64, "vc_enabled": vc_enabled}}));
|
291 |
-
|
292 |
-
addRecieveMessageToDOM({
|
293 |
-
'cid': "a_text_" + cid,
|
294 |
-
'from': 'gpt',
|
295 |
-
'value': '',
|
296 |
-
'type': 'text'
|
297 |
-
})
|
298 |
-
if (text != '') {
|
299 |
-
text = '';
|
300 |
-
}
|
301 |
-
if (audio_base64 != null) {
|
302 |
-
audio_base64 = null;
|
303 |
-
// 清空缓存区
|
304 |
-
audioPlayer.src = '';
|
305 |
-
audioPlayer.style.display = 'none';
|
306 |
-
}
|
307 |
-
}
|
308 |
-
|
309 |
-
function blobToDataURI(blob, callback) {
|
310 |
-
var reader = new FileReader();
|
311 |
-
reader.onload = function (e) {
|
312 |
-
callback(e.target.result);
|
313 |
-
}
|
314 |
-
reader.readAsDataURL(blob);
|
315 |
-
}
|
316 |
-
|
317 |
-
const resetButton = document.getElementById('delete_button');
|
318 |
-
resetButton.onclick = () => {
|
319 |
-
clear();
|
320 |
-
resultsDiv.innerHTML = '';
|
321 |
-
audioPlayer.src = '';
|
322 |
-
audioPlayer.style.display = 'none';
|
323 |
-
waveformDiv.style.display = 'none';
|
324 |
-
}
|
325 |
-
function clear() {//update
|
326 |
-
ws.send(JSON.stringify({"action": "clear"}));
|
327 |
-
}
|
328 |
-
|
329 |
-
const recordButton = document.getElementById('start_button');
|
330 |
-
recordButton.onclick = () => {
|
331 |
-
record_audio();
|
332 |
-
|
333 |
-
}
|
334 |
-
|
335 |
-
function record_audio() {//update
|
336 |
-
if (!isRecording) {
|
337 |
-
recorder = Recorder({type:"mp3", sampleRate:44100, bitRate:128, onProcess:function(buffers,powerLevel,bufferDuration,bufferSampleRate,newBufferIdx,asyncEnd){
|
338 |
-
wave&&wave.input(buffers[buffers.length-1],powerLevel,bufferSampleRate);
|
339 |
-
}});
|
340 |
-
recorder.open(function(){
|
341 |
-
isRecording = true;
|
342 |
-
recorder.start();
|
343 |
-
audioPlayer.style.display = 'none';
|
344 |
-
waveformDiv.style.display = '';
|
345 |
-
recordButton.style.filter = "invert(18%) sepia(66%) saturate(5808%) hue-rotate(338deg) brightness(91%) contrast(125%)";
|
346 |
-
},function(msg,isUserNotAllow){
|
347 |
-
alert("请允许浏览器获取麦克风录音权限");
|
348 |
-
console.log((isUserNotAllow?"UserNotAllow, ":"")+"无法录音:"+msg);
|
349 |
-
});
|
350 |
-
}else {
|
351 |
-
isRecording = false;
|
352 |
-
recorder.stop(function(blob, duration){
|
353 |
-
audioPlayer.style.display = '';
|
354 |
-
waveformDiv.style.display = 'none';
|
355 |
-
blobToDataURI(blob, function(audio_base64_data){
|
356 |
-
audio_base64 = audio_base64_data;
|
357 |
-
// document.getElementById('audioPlayer').src = URL.createObjectURL(blob);
|
358 |
-
recorder.close();
|
359 |
-
recorder=null;
|
360 |
-
// 移动 audio 到暂存区
|
361 |
-
audioPlayer.src = audio_base64;
|
362 |
-
// sendMessage();
|
363 |
-
});
|
364 |
-
},function(msg){
|
365 |
-
alert("录音失败");
|
366 |
-
console.log("录音失败:"+msg);
|
367 |
-
recorder.close();
|
368 |
-
recorder=null;
|
369 |
-
});
|
370 |
-
recordButton.style.filter = null;
|
371 |
-
}
|
372 |
-
}
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static/js/recorder.mp3.min.js
DELETED
The diff for this file is too large to render.
See raw diff
|
|
static/js/waveview.js
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
录音
|
3 |
-
https://github.com/xiangyuecn/Recorder
|
4 |
-
src: extensions/waveview.js
|
5 |
-
*/
|
6 |
-
!function(){var e=function(e){return new t(e)},g="WaveView",t=function(e){var t=this,a={scale:2,speed:9,phase:21.8,fps:20,keep:!0,lineWidth:3,linear1:[0,"rgba(150,96,238,1)",.2,"rgba(170,79,249,1)",1,"rgba(53,199,253,1)"],linear2:[0,"rgba(209,130,255,0.6)",1,"rgba(53,199,255,0.6)"],linearBg:[0,"rgba(255,255,255,0.2)",1,"rgba(54,197,252,0.2)"]};for(var i in e)a[i]=e[i];t.set=e=a;var r=e.elem;r&&("string"==typeof r?r=document.querySelector(r):r.length&&(r=r[0])),r&&(e.width=r.offsetWidth,e.height=r.offsetHeight);var n=e.scale,h=e.width*n,o=e.height*n;if(!h||!o)throw new Error(g+"无宽高");var l=t.elem=document.createElement("div"),s=["","transform-origin:0 0;","transform:scale("+1/n+");"];l.innerHTML='<div style="width:'+e.width+"px;height:"+e.height+'px;overflow:hidden"><div style="width:'+h+"px;height:"+o+"px;"+s.join("-webkit-")+s.join("-ms-")+s.join("-moz-")+s.join("")+'"><canvas/></div></div>';var c=t.canvas=l.querySelector("canvas"),d=t.ctx=c.getContext("2d");c.width=h,c.height=o,t.linear1=t.genLinear(d,h,e.linear1),t.linear2=t.genLinear(d,h,e.linear2),t.linearBg=t.genLinear(d,o,e.linearBg,!0),r&&(r.innerHTML="",r.appendChild(l)),t._phase=0};t.prototype=e.prototype={genLinear:function(e,t,a,i){for(var r=e.createLinearGradient(0,0,i?0:t,i?t:0),n=0;n<a.length;)r.addColorStop(a[n++],a[n++]);return r},genPath:function(e,t,a){for(var i=[],r=this.set,n=r.scale,h=r.width*n,o=r.height*n/2,l=0;l<h;l+=n){var s=(1+Math.cos(Math.PI+l/h*2*Math.PI))/2*o*t*Math.sin(2*Math.PI*(l/h)*e+a)+o;i.push(s)}return i},input:function(e,t,a){var i=this;i.sampleRate=a,i.pcmData=e,i.pcmPos=0,i.inputTime=Date.now(),i.schedule()},schedule:function(){var e=this,t=e.set,a=Math.floor(1e3/t.fps);e.timer||(e.timer=setInterval(function(){e.schedule()},a));var i=Date.now();if(!(i-(e.drawTime||0)<a)){e.drawTime=i;for(var r=e.sampleRate/t.fps,n=e.pcmData,h=e.pcmPos,o=Math.max(0,Math.min(r,n.length-h)),l=0,s=0;s<o;s++,h++)l+=Math.abs(n[h]);e.pcmPos=h,!o&&t.keep||e.draw(Recorder.PowerLevel(l,o)),!o&&1300<i-e.inputTime&&(clearInterval(e.timer),e.timer=0)}},draw:function(e){var t=this,a=t.set,i=t.ctx,r=a.scale,n=a.width*r,h=a.height*r,o=a.speed/a.fps,l=t._phase-=o,s=l+o*a.phase,c=e/100,d=t.genPath(2,c,l),g=t.genPath(1.8,c,s);i.clearRect(0,0,n,h),i.beginPath();for(var p=0,f=0;f<n;p++,f+=r)0==f?i.moveTo(f,d[p]):i.lineTo(f,d[p]);p--;for(f=n-1;0<=f;p--,f-=r)i.lineTo(f,g[p]);i.closePath(),i.fillStyle=t.linearBg,i.fill(),t.drawPath(g,t.linear2),t.drawPath(d,t.linear1)},drawPath:function(e,t){var a=this.set,i=this.ctx,r=a.scale,n=a.width*r;i.beginPath();for(var h=0,o=0;o<n;h++,o+=r)0==o?i.moveTo(o,e[h]):i.lineTo(o,e[h]);i.lineWidth=a.lineWidth*r,i.strokeStyle=t,i.stroke()}},Recorder[g]=e}();
|
|
|
|
|
|
|
|
|
|
|
|
|
|