-
Notifications
You must be signed in to change notification settings - Fork 1k
/
index.html
1430 lines (1281 loc) · 49.5 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="shortcut icon" type="image/png" href="../assets/icon.png">
<title reclang="PZM5">RecordApp测试</title>
<script>
var PageLM="2024-09-09 21:58";
(function(){
console.log("【温馨提示】本页面用于测试RecordApp的主要功能,代码难看臃肿,不建议阅读本页面源码;如果想要快速入门,请参考app-support-sample/QuickStart.html页面。 "
+"[Reminder] This page is used to test the main functions of RecordApp. The code is ugly and bloated. It is not recommended to read the source code of this page; if you want to get started quickly, please refer to the app-support-sample/QuickStart.html page.");
//加载核心库,其他类型支持库在下面根据用户点击选择加载,刷新页面可以恢复选择的类型
var srcC="src/recorder-core.js",distC="dist/recorder-core.js";
var initJss=[srcC];
var tei=window.TypeEngineImports={//不同类型编码器需要加载的js文件
mp3:{src:[srcC,"src/engine/mp3.js","src/engine/mp3-engine.js",0,"src/engine/wav.js"]
,dist:["recorder.mp3.min.js",0,"src/engine/wav.js"]}
,wav:{src:[srcC,"src/engine/wav.js"]
,dist:["recorder.wav.min.js"]}
,pcm:{src:[srcC,"src/engine/pcm.js",0,"src/engine/wav.js"]
,dist:[distC,"dist/engine/pcm.js",0,"src/engine/wav.js"]}
,amr:{src:[srcC,"src/engine/beta-amr.js","src/engine/beta-amr-engine.js",0,"src/engine/wav.js"]
,dist:[distC,"dist/engine/beta-amr.js",0,"src/engine/wav.js"]}
,ogg:{src:[srcC,"src/engine/beta-ogg.js","src/engine/beta-ogg-engine.js"]
,dist:[distC,"dist/engine/beta-ogg.js"]}
,g711a:{},g711u:{}
,webm:{name:"webm(beta)",sort:99,
src:[srcC,"src/engine/beta-webm.js"]
,dist:[distC,"dist/engine/beta-webm.js"]}
};
tei.g711a.src=tei.g711u.src=[srcC,"src/engine/g711x.js",0,"src/engine/wav.js"];
tei.g711a.dist=tei.g711u.dist=[distC,"dist/engine/g711x.js",0,"src/engine/wav.js"];
window.Import_RecJs_Set={};//刷新页面,加载选中的类型js
if(/recImport=([^?#&]+)/.test(location.href)){
try{
var o=JSON.parse(decodeURIComponent(RegExp.$1));
var te=tei[o.type]||{},jss=te[o.minJs?"dist":"src"];
if(!jss)throw "unknown type="+o.type;
Import_RecJs_Set=o; initJss=jss;
console.log("recImport init", o, jss);
}catch(e){
console.error("recImport init error",e);
}
}
for(var i=0;i<initJss.length;i++){
if(initJss[i]){
document.write('<scr'+'ipt src="../'+initJss[i]+'"></scr'+'ipt>');
}
}
})()</script>
</head>
<body>
<div class="main">
<!--加载RecordApp-->
<script src="../src/app-support/app.js"></script>
<!--加载Native支持文件,用于在Android、iOS App中调用原生录音-->
<script src="../src/app-support/app-native-support.js"></script>
<!--加载Native测试配置文件(实现Hybrid App的JsBridge调用)-->
<script src="./native-config.js"></script>
<!--加载可选扩展库-->
<script src="../src/extensions/waveview.js"></script>
<script src="../src/extensions/wavesurfer.view.js"></script>
<script src="../src/extensions/lib.fft.js"></script>
<script src="../src/extensions/frequency.histogram.view.js"></script>
<script src="../src/extensions/create-audio.nmn2pcm.js"></script>
<script src="../src/extensions/dtmf.encode.js"></script>
<script src="../src/extensions/dtmf.decode.js"></script>
<!--加载PlayBuffer-->
<script src="../assets/runtime-codes/fragment.playbuffer.js"></script>
<style>
body{
word-wrap: break-word;
word-break: break-all;
background:#f5f5f5 center top no-repeat;
background-size: auto 680px;
}
pre{
white-space:pre-wrap;
}
label,label *{
cursor: pointer;
}
label:hover{
color:#06c;
}
a{
text-decoration: none;
color:#06c;
}
a:hover{
color:#f00;
}
.main{
max-width:700px;
margin:0 auto;
padding-bottom:80px
}
.mainBox{
margin-top:12px;
padding: 12px;
border-radius: 6px;
background: #fff;
--border: 1px solid #f60;
box-shadow: 2px 2px 3px #aaa;
}
.btns button,.mainBtn{
display: inline-block;
cursor: pointer;
border: none;
border-radius: 3px;
background: #f60;
color:#fff;
padding: 0 15px;
margin:3px 20px 3px 0;
line-height: 36px;
height: 36px;
overflow: hidden;
vertical-align: middle;
}
.btns button:active,.mainBtn:active{
background: #f00;
}
.recwaveChoice{
cursor: pointer;
display:inline-block;
vertical-align: bottom;
border-right:1px solid #ccc;
background:#ddd;
line-height:28px;
font-size:12px;
color:#666;
padding:0 5px;
}
.recwaveChoice:first-child{
border-radius: 99px 0 0 99px;
}
.recwaveChoice:last-child{
border-radius: 0 99px 99px 0;
border-right:none;
}
.recwaveChoice.slc,.recwaveChoice:hover{
background:#f60;
color:#fff;
}
.lb{
display:inline-block;
vertical-align: middle;
background:#00940e;
color:#fff;
font-size:14px;
padding:2px 8px;
border-radius: 99px;
}
.pd{
padding:0 0 6px 0;
}
</style>
<script>
//兼容环境
function RandomKey(){
return "randomkey"+(RandomKey.idx++);
};
RandomKey.idx=0;
//乐此不疲,古董浏览器,仅保证基本的可执行不代码异常
if(!Date.now)Date.now=function(){return new Date().getTime()};
if(!window.localStorage){window.localStorage={}};
</script>
<script src="../assets/ztest-jquery.min-1.9.1.js"></script>
<script src="../assets/ztest-page-i18n.js"></script>
<div class="i18nBox"></div>
<div class="mainBox">
<style>
.navItem{
display:inline-block;
width:45%;
max-width:300px;
vertical-align: top;
background:#eee;
border-bottom: 5px solid #ccc;
box-shadow: 2px 2px 3px #ddd;
color:#666;
text-decoration:none;
border-radius: 8px;
padding: 0 5px 3px;
}
.navItem.slc{
border-bottom: 5px solid #00940e;
color:#f60;
}
.navItem:hover{
color:#d44;
}
.navTitle{
text-align: center;
font-size:18px;
font-weight: bold;
}
.navItem.slc .navDesc{
color:#00940e;
}
.navDesc{
font-size:12px;
}
</style>
<a class="navItem" style="margin-right:2%;" href="../">
<div class="navTitle">Recorder H5</div>
<div class="navDesc" reclang="a2Uc">Recorder H5使用简单,功能丰富,支持PC、Android、iOS 14.3+</div>
</a>
<a class="navItem slc" href="./">
<div class="navTitle">Recorder App</div>
<div class="navDesc" reclang="ptyK">支持:浏览器WebView(H5)、各种使用js来构建的程序(App、小程序、UniApp、Electron、NodeJs)</div>
</a>
<div style="margin-top:8px;font-size:18px;font-weight:bold;color:#f60">
<span reclang="v1fx">RecordApp:基于Recorder的跨平台录音解决方案</span>
</div>
<div style="padding-left:15px;padding-bottom:12px">
<style>.c_ul{margin:0;list-style-type: square}.c_ul li{margin:5px 0;}</style>
<div reclang="kYvU">- 支持H5页面录音(即本页面支持):</div>
<ul class="c_ul">
<li reclang="Roj2">在浏览器中(含App WebView)默认使用Recorder H5进行录音</li>
<li>
<span reclang="c7mM">在开启了原生支持的App WebView中使用原生录音,App Demo:</span>
<a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_android" target="_blank">Android</a>, <a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_ios" target="_blank">iOS</a>
</li>
</ul>
<div>
<span reclang="up8g">- 支持微信小程序录音,微信小程序Demo:</span>
<a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/miniProgram-wx" target="_blank">miniProgram-wx</a>
</div>
<div>
<span reclang="K3sX">- 支持uni-app录音:H5、Android iOS App、微信小程序,含组件示例:</span>
<a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_UniApp" target="_blank">demo_UniApp</a>
</div>
<div reclang="sjDM">- 支持自行适配到各种js运行环境中录音,比如:Electron、NodeJs、各种小程序</div>
<div reclang="5agh">- 以上环境中均可使用大部分的: 录音格式、实时处理、和可视化等扩展功能</div>
</div>
<div class="pd">
<span class="lb" reclang="lIPR">源码仓库 :</span>
<a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample" target="_blank">GitHub</a>
| <a href="https://gitee.com/xiangyuecn/Recorder/tree/master/app-support-sample" target="_blank">Gitee</a>
<span class="lb" reclang="ZNjk">更多Demo :</span> <a href="../assets/工具-代码运行和静态分发Runtime.html" target="_blank" reclang="Hkoo">Demo列表(可编辑)</a>
| <a href="../assets/demo-vue/recordapp.html" target="_blank">App vue</a>
</div>
<div>
<span class="lb">QuickStart :</span>
<a href="QuickStart.html" target="_blank">/app-support-sample/QuickStart.html</a>
<span style="font-size:12px;color:#999" reclang="paWp">(Copy即用,更适合入门学习)</span>
</div>
</div>
<div class="mainBox">
<div class="pd">
<span class="lb" reclang="5lOo">类型 :</span> <span class="types"></span>
</div>
<div class="pd">
<span class="lb" reclang="dsAF">提示 :</span> <span class="typeTips">-</span>
</div>
<div class="pd">
<span class="lb" reclang="u4jV">比特率 :</span> <input type="text" class="bit" value="16" style="width:60px">
<span reclang="06ha">kbps,越大音质越好</span>
</div>
<div class="pd">
<span class="lb" reclang="4PRA">采样率 :</span> <input type="text" class="sample" value="16000" style="width:60px">
<span reclang="e0ec">hz,越大细节越丰富</span>
</div>
<div>
<span class="lb">AppUseH5 :</span> <label><input type="checkbox" class="alwaysAppUseH5"><span reclang="Wpwv">App里面总是使用Recorder H5录音</span></label>
</div>
</div>
<div class="mainBox">
<div>
<span class="btns">
<button onclick="recreq()" reclang="aoOU">请求权限</button>
<button onclick="recstart()" reclang="3MeL">录制</button>
<button onclick="recstop()" style="margin-right:80px;" reclang="9vcY">停止</button>
</span>
<span style="display: inline-block;">
<button onclick="recstartAndAutoStop()" reclang="6CdW">录制+定时停止</button>
<input value="0" class="autoStopTime" style="width:60px;text-align:right;">ms
</span>
</div>
<div class="pd btns">
<span style="display: inline-block;margin-right: 36px;">
<button onclick="recpause()" reclang="hxxb">暂停</button>
<button onclick="recresume()" reclang="Orkm">继续</button>
<button onclick="recstopX()" reclang="Yna5">停止(仅清理)</button>
</span>
<span style="display: inline-block;">
<button onclick="recPlayLast()" reclang="Wahr">播放</button>
<button onclick="recUploadLast()" reclang="6Rqg">上传</button>
<button onclick="recDownLast()" reclang="gXBH">本地下载</button>
</span>
</div>
<div class="pd recpower">
<div style="height:40px;width:300px;background:#999;position:relative;">
<div class="recpowerx" style="height:40px;background:#0B1;position:absolute;"></div>
<div class="recpowert" style="padding-left:50px; line-height:40px; position: relative;"></div>
</div>
</div>
<div class="pd">
<button onclick="recstop2()" class="batEnc" reclang="wFvj">批量编码</button>
<input type="text" class="bits" value="8 to 96 step 8">
<span reclang="ozCS">kbps 测试音质用的,除比特率外其他参数可调整</span>
</div>
<div class="pd">
<div style="border:1px solid #ccc;display:inline-block"><div style="height:100px;width:300px;" class="recwave"></div></div>
<span style="font-size:0">
<span class="recwaveChoice" key="WaveView">WaveView</span>
<span class="recwaveChoice" key="SurferView">SurferView</span>
<span class="recwaveChoice" key="Histogram1">Histogram1</span>
<span class="recwaveChoice" key="Histogram2">H...2</span>
<span class="recwaveChoice" key="Histogram3">H...3</span>
</span>
</div>
<div class="pd">
<label><input type="checkbox" class="takeoffEncodeChunkSet"><span reclang="Hyuy">接管编码器输出(takeoffEncodeChunk)</span></label>
</div>
<div class="pd">
<label><input type="checkbox" class="useAECSet"><span reclang="Kz8D">尝试启用回声消除(echoCancellation)</span></label>
</div>
<div class="pd">
<label><input type="checkbox" class="realTimeSendSet"><span reclang="zb16">实时语音通话聊天对讲(WebSocket、WebRTC)</span></label>
<div class="realTimeSendView" style="display:none;"></div>
</div>
<div class="">
<label><input type="checkbox" class="asrSet"><span reclang="jCKC">实时语音识别、音频文件转文字,ASR</span></label>
<div class="asrView" style="display:none;"></div>
</div>
</div>
<div class="mainBox">
<audio class="recPlay" controls style="display:none;width:100%"></audio>
<div class="reclog"></div>
<div class="recLastLog" style="position:fixed;z-index:2;width:20vw;min-width:200px;max-height:100px;overflow:auto;right:0;bottom:0;background:#fff;padding:5px 10px;border-radius:6px 0 0 0;box-shadow:-1px -1px 3px #ddd;font-size:13px"></div>
</div>
<div class="mainBox">
<span class="lb" reclang="QFFW">测试App :</span>
iOS Demo App: <a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_ios" reclang="WUY9">下载源码</a> <span reclang="AeNc">自行编译</span>
,Android Demo App: <a href="https://gitee.com/xiangyuecn/Recorder/blob/master/app-support-sample/demo_android/app-debug.apk.zip" reclang="Uf5q">下载APK</a>
(<span reclang="5zSj">40kb,删除.zip后缀,</span><a href="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_android" reclang="G0HC">源码</a>)
<div>
<span class="lb" reclang="zIlH">原生接口 :</span>
<button onclick="callNative_showMemoryUsage()" reclang="dPz1">显示内存占用</button>
<button onclick="callNative_notifyService(1)" reclang="dPz2">显示后台录音保活通知(Android)</button>
<button onclick="callNative_notifyService(0)" reclang="dPz3">关闭通知</button>
<button onclick="callNative_setSpeakerOff(false)" reclang="dPz4">切换成扬声器外放</button>
<button onclick="callNative_setSpeakerOff(true)" reclang="dPz5">切换成听筒播放</button>
<div style="color:#aaa;font-size:13px" reclang="dPz9">原生接口不一定可用,取决于原生app是否已实现对应接口</div>
</div>
</div>
<div class="mainBox">
<div style="color:#0ab;font-size:22px;font-weight:bold">
<span reclang="Pea3">如需录音功能定制开发,网站、App、小程序、前端后端开发等需求,请加QQ群:①群 781036591、②群 748359095、③群 450721519,口令recorder,联系群主(即作者),谢谢~</span>
</div>
</div>
<div class="mainBox">
<span class="lb" reclang="2fWL">音乐播放测试 :</span>
<button onclick="recplay2(this,'rec-4000ms-8kbps-16000hz.wav')">wav</button>
<button onclick="recplay2(this,'rec-4000ms-64kbps-16000hz.mp3')">mp3</button>
<button onclick="recplay2(this,'rec-4000ms-64kbps-16000hz.ogg')">ogg</button>
<button onclick="recplay2(this,'rec-4000ms-64kbps-16000hz.webm')">webm</button>
<button onclick="recplay2(this,'rec-4000ms-12.8kbps-8000hz.amr')">amr</button>
<button onclick="recplay2(this,'nmn5')" reclang="uad6">合成5分钟wav</button>
<span reclang="z9o0">Audio对录音的影响测试</span> (<a href="https://github.com/xiangyuecn/Recorder/issues/34">issues#34</a>) <span reclang="yStv">;低版本iOS Safari如果未开始过录音并且播放了音乐,然后后续录音可能会有问题;再现方法</span> (<a href="assets/ztest_apple_developer_forums_getusermedia.html">test apple developer forums</a>): <span reclang="4yox">刷新页面后首先先播放音乐,然后开始测试录音,会发现波形显示掉帧或者保持直线。另测试浏览器对音频的支持情况。</span>
</div>
<div class="mainBox">
<span class="lb" reclang="fFQq">视频播放测试 :</span>
<button onclick="videoTestPlay('')" reclang="6E53">播放mp4</button>
<script>var videoTestPlay=function(attr){
$('.videoTest').show().html('<video controls '+attr+' webkit-playsinline playsinline x5-video-player-type="h5" '
+'style="width:370px;height:160px">'
+'<source src="../assets/audio/movie-一代宗师-此一时彼一时.mp4.webm" type="video/mp4"/>' //fix safari
+'</'+'video>').find('video')[0].play()
}</script>
<span reclang="ALiC">Video对录音的影响测试</span> (<a href="https://github.com/xiangyuecn/Recorder/issues/84">issues#84</a>) <span reclang="yshJ">;iOS Safari可能出现先播放视频,然后再开始录音,会自动播放视频的声音,但并未再现。</span>
<button onclick="$('.videoTest').show()" reclang="CwnP">显示video</button>
<button onclick="$('.videoTest').hide()" reclang="nFEO">隐藏video</button>
<button onclick="$('.videoTest').html('')" reclang="WXIx">移除video</button>
<button onclick="videoTestPlay(' loop')" reclang="iXZv">循环播放</button>
<button onclick="videoTestPlay(' loop muted')" reclang="2RpC">静音循环播放</button>
<div class="videoTest"></div>
</div>
<div class="mainBox">
<span class="lb" reclang="IClu">浏览器环境情况 :</span>
<pre class="recinfoCode"></pre><textarea class="recinfoCodeTxt" style="display:none">
Platforms:${RecordApp.Current.Key}
IsApp:${isApp}
AudioContext:${"AudioContext" in window}
webkitAudioContext:${"webkitAudioContext" in window}
mediaDevices:${!!navigator.mediaDevices}
mediaDevices.getUserMedia:${!!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)}
navigator.getUserMedia:${!!navigator.getUserMedia}
navigator.webkitGetUserMedia:${!!navigator.webkitGetUserMedia}
AudioContext.scriptProcessor:{{
"createScriptProcessor" in (Recorder.Ctx||{})
|| "createJavaScriptNode" in (Recorder.Ctx||{})
}}
AudioContext.audioWorklet:{{"audioWorklet" in (Recorder.Ctx||{})}}
AudioWorkletNode:${"AudioWorkletNode" in window}
MediaRecorder:${"MediaRecorder" in window}
MediaRecorder.ondataavailable:${"MediaRecorder" in window && "ondataavailable" in MediaRecorder.prototype}
MediaRecorder.WebM.PCM:${"MediaRecorder" in window && MediaRecorder.isTypeSupported("audio/webm; codecs=pcm")}
URL:${location.href.replace(/#.+/g,"")}
UA:${navigator.userAgent}
<span reclang="mt71">RecordApp库修改时间(有可能修改了忘改):</span>${RecordApp.LM}
<span reclang="ySaK">Recorder库修改时间(有可能修改了忘改):</span>${Recorder.LM}
<span reclang="Ls9o">本页面修改时间(有可能修改了忘改):</span>${PageLM}
</textarea>
</div>
<script>
function reclog(s,color){
var now=new Date();
var t=("0"+now.getHours()).substr(-2)
+":"+("0"+now.getMinutes()).substr(-2)
+":"+("0"+now.getSeconds()).substr(-2);
var html='<div style="color:'+(!color?"":color==1?"red":color==2?"#0b1":color)+'">['+t+']'+s+'</div>';
$(".reclog").prepend(html);
$(".recLastLog").html(html.replace(/class\s*=/ig,"clazz="));
};
window.onerror=function(message, url, lineNo, columnNo, error){
//https://www.cnblogs.com/xianyulaodi/p/6201829.html
reclog('【Uncaught Error】'+message+'<pre>'+"at:"+lineNo+":"+columnNo+" url:"+url+"\n"+(error&&error.stack||Html_$T("jwqb::不能获得错误堆栈"))+'</pre>',1);
};
</script>
<script>
function baseSet(){
var alwaysAppUseH5=$(".alwaysAppUseH5")[0].checked;
if(!!RecordApp.alwaysAppUseH5Prev!=alwaysAppUseH5){
reclog(Html_$T("T6A6::AppUseH5选项变更,已重置RecordApp,请先进行权限测试"));
RecordApp.Current=null;
RecordApp.alwaysAppUseH5Prev=alwaysAppUseH5;
};
RecordApp.AlwaysAppUseH5=alwaysAppUseH5;
cancelAutoStop();
};
var reqUseAEC;
function recreq(call){
call||(call=function(msg){
msg&&reclog(msg,1);
});
baseSet();
reclog(Html_$T("LnQj::开始请求授权..."));
reqUseAEC=$(".useAECSet")[0].checked;
if(reqUseAEC){
//这个是Start中的audioTrackSet配置,在h5中必须提前配置,因为h5中RequestPermission会直接打开录音
RecordApp.RequestPermission_H5OpenSet={ audioTrackSet:{ echoCancellation:true,noiseSuppression:true,autoGainControl:true } };
reclog(Html_$T("W5dU::已启用audioTrackSet配置:")+JSON.stringify(RecordApp.RequestPermission_H5OpenSet.audioTrackSet));
};
RecordApp.RequestPermission(function(){
reclog(RecordApp.Current.Key+" "+Html_$T("wnd4::已授权"),2);
call();
},function(err,isUserNotAllow){
call((RecordApp.Current&&RecordApp.Current.Key||"[?]")
+(isUserNotAllow?" UserNotAllow, ":"")
+" "+Html_$T("oFqf::授权失败:")+err);
});
};
var curSet,autoStopTimer;
function recstartAndAutoStop(){
var time=+$(".autoStopTime").val()||0;
if(time<100){
reclog(Html_$T("9ZjY::定时不能小于100ms"),1);
return;
};
recstart(function(msg){
if(msg){
msg&&reclog(msg,1);
return;
};
reclog(Html_$T("7Jp4::定时{1}ms后自动停止录音",0,time));
autoStopTimer=setTimeout(function(){
autoStopTimer=0;
reclog(Html_$T("MHeo::定时时间到,开始自动调用停止..."));
recstop();
},time);
});
};
var cancelAutoStop=function(){
if(autoStopTimer){
reclog(Html_$T("K57T::已取消定时停止"),1);
clearTimeout(autoStopTimer);
autoStopTimer=0;
};
};
function recstart(call){
call||(call=function(msg){
msg&&reclog(msg,1);
});
baseSet();
if(!RecordApp.Current){
call(Html_$T("dejy::需先调用RequestPermission"));
return;
};
if(RecordApp.Current==RecordApp.Platforms.Native){
reclog(Html_$T("Knhl::正在使用Native录音,底层由App原生层提供支持"));
}else{
reclog(Html_$T("mHN7::正在使用H5录音,底层由Recorder直接提供支持"));
};
var type=$("[name=type]:checked").val();
var bit=+$(".bit").val();
var sample=+$(".sample").val();
window.waveStore={};
window.takeoffChunks=[];
var realTimeSendSet=$(".realTimeSendSet")[0].checked;
if(realTimeSendSet&&!RecordApp.Current.CanProcess()){
reclog(Html_$T("GM5h::当前环境{1}不支持实时回调,不能模拟实时编码传输",0,RecordApp.Current.Key),1);
};
var asrSet=$(".asrSet")[0].checked;
if(asrSet&&!RecordApp.Current.CanProcess()){
reclog(Html_$T("Vee6::当前环境{1}不支持实时回调,不能进行实时语音识别",0,RecordApp.Current.Key),1);
};
var takeoffEncodeChunkSet=$(".takeoffEncodeChunkSet")[0].checked;
var set={
type:type
,bitRate:bit
,sampleRate:sample
,audioTrackSet:!reqUseAEC?null:{echoCancellation:true,noiseSuppression:true,autoGainControl:true} //配置回声消除,注意:H5中需要在请求录音权限前进行相同配置RecordApp.RequestPermission_H5OpenSet后此配置才会生效
,onProcess:function(buffers,powerLevel,duration,sampleRate,newBufferIdx){
$(".recpowerx").css("width",powerLevel+"%");
$(".recpowert").text(formatMs(duration,1)+" / "+powerLevel);
processTime=Date.now();
//可视化图形绘制
if(waveStore[recwaveChoiceKey]){
if(waveStore.choice!=recwaveChoiceKey){
waveStore.choice=recwaveChoiceKey;
$(".recwave").html("").append(waveStore[recwaveChoiceKey].elem);
};
waveStore[recwaveChoiceKey].input(buffers[buffers.length-1],powerLevel,sampleRate);
};
//实时传输
if(realTimeSendSet&&window.realTimeSendTry){
realTimeSendTry(set,buffers,sampleRate);
};
if(realTimeSendSet&&window.RtVoiceProcess){
RtVoiceProcess(buffers,powerLevel,duration,sampleRate,newBufferIdx);
};
//实时语音识别
if(asrSet&&window.asrInput){
asrInput(buffers,sampleRate,newBufferIdx);
};
}
,takeoffEncodeChunk:!takeoffEncodeChunkSet?null:function(chunkBytes){
takeoffChunks.push(chunkBytes);
}
};
var processTime=0;
curSet=null;
reclog(RecordApp.Current.Key+" "+Html_$T("wFnI::正在打开..."));
RecordApp.Start(set,function(){
curSet=set;
reclog(RecordApp.Current.Key+" "+Html_$T("bYp4::录制中:")+type+" "+bit+"kbps",2);
window.realTimeSendTryReset&&realTimeSendTryReset(set);
//此处创建这些音频可视化图形绘制浏览器支持妥妥的
initWaveStore(waveStore,".recwave");
//【稳如老狗WDT】可选的,监控是否在正常录音有onProcess回调,如果长时间没有回调就代表录音不正常
var this_= RecordApp; //有this就用this,没有就用一个全局对象
if(RecordApp.Current.CanProcess()){
var wdt=this_.watchDogTimer=setInterval(function(){
if(wdt!=this_.watchDogTimer){ clearInterval(wdt); return } //sync
if(Date.now()<this_.wdtPauseT) return; //如果暂停录音了就不检测:puase时赋值this_.wdtPauseT=Date.now()*2(永不监控),resume时赋值this_.wdtPauseT=Date.now()+1000(1秒后再监控)
if(Date.now()-(processTime||startTime)>1500){ clearInterval(wdt);
reclog(processTime?Html_$T("eWu1::录音被中断"):Html_$T("eWu2::录音未能正常开始"),1);
// ... 错误处理,关闭录音,提醒用户
}
},1000);
}else{
reclog(Html_$T("eWu3::当前环境不支持onProcess回调,不启用watchDogTimer"),"#aaa"); //目前都支持回调
}
var startTime=Date.now(); this_.wdtPauseT=0;
call();
},function(err){
call(RecordApp.Current.Key+" "+Html_$T("EBjo::开始录音失败:")+err);
});
};
function recpause(){
if(RecordApp.GetCurrentRecOrNull()){
RecordApp.Pause();
var this_=RecordApp;this_.wdtPauseT=Date.now()*2; //永不监控onProcess超时
reclog(Html_$T("z2B2::已暂停"));
}
};
function recresume(){
if(RecordApp.GetCurrentRecOrNull()){
RecordApp.Resume();
var this_=RecordApp;this_.wdtPauseT=Date.now()+1000; //1秒后再监控onProcess超时
reclog(Html_$T("sTFX::继续录音中..."));
}
};
function recstopX(){
cancelAutoStop();
var this_=RecordApp;this_.watchDogTimer=0; //停止监控onProcess超时
RecordApp.Stop(
null //success传null就只会清理资源,不会进行转码
,function(msg){
reclog(Html_$T("C7au::已清理,错误信息:")+msg);
}
);
};
var recblob={},stopRec;
function recstop(call){
var set=curSet;
recstopFn(call,true,function(err,blob,time){
setTimeout(function(){
window.realTimeSendTryStop&&realTimeSendTryStop(set);
if(!err && set.takeoffEncodeChunk){
reclog(Html_$T("aS2G::启用takeoffEncodeChunk后Stop返回的blob长度为0不提供音频数据"),"#f60");
reclog(Html_$T("Vsr4::takeoffEncodeChunk接收到{1}片音频片段,正在合并成一个音频文件...",0,takeoffChunks.length));
var len=0;
for(var i=0;i<takeoffChunks.length;i++){
len+=takeoffChunks[i].length;
};
var chunkData=new Uint8Array(len);
for(var i=0,idx=0;i<takeoffChunks.length;i++){
var itm=takeoffChunks[i];
chunkData.set(itm,idx);
idx+=itm.length;
};
var blob=new Blob([chunkData],{type:"audio/"+set.type});
addRecLog(time,Html_$T("NcRr::合并"),blob,set,Date.now());
};
});
});
};
function recstopFn(call,isClick,endCall,rec){
cancelAutoStop();
call||(call=function(msg){
msg&&reclog(msg,1);
});
var t1=Date.now();
if(!isClick){
rec.stop(function(blob,time){
var tag=endCall("",blob,time);
if(tag==-1){
return;
};
addRecLog(time,tag||Html_$T("SS8P::已录制"),blob,rec.set,t1);
},function(s){
reclog(Html_$T("Xnib::失败:")+s);
endCall(s);
});
return;
};
var setData=curSet;
curSet=null;
if(!setData){
//没有开始?不管,stop清理资源
setData={};
}else{
reclog(RecordApp.Current.Key+" "+Html_$T("s99V::正在结束")+" "+setData.type+"...");
};
var this_=RecordApp;this_.watchDogTimer=0; //停止监控onProcess超时
RecordApp.Stop(function(aBuf,time,mime){
var blob=new Blob([aBuf],{type:mime});
endCall("",blob,time);
stopRec=RecordApp.GetCurrentRecOrNull();
addRecLog(time,Html_$T("jpEQ::已录制"),blob,setData,t1);
call(null,{data:blob,duration:time});
},function(s){
endCall(s);
call(Html_$T("lenm::失败:")+s);
});
};
var recLogLast;
var addRecLog=function(time,tag,blob,set,t1){
var id=RandomKey(16);
recLogLast={blob:blob,set:$.extend({},set),time:time,key:id};
recblob[id]=recLogLast;
var a1=intp(Date.now()-t1,4),a2=intp(blob.size,6);
reclog(tag+":"+intp(set.bitRate,3)+"kbps "+intp(set.sampleRate,5)+"hz "
+Html_$T("aZ4T::花{1}ms编码{2}B",0,a1,a2)
+" ["+set.type+"]"+formatMs(time)+'ms'
+' <button onclick="recdown(\''+id+'\')">'+Html_$T("9aiF::下载")+'</button>'
+' <button onclick="recplay(\''+id+'\')">'+Html_$T("56g1::播放")+'</button>'
+' <span class="p'+id+'"></span> <span class="d'+id+'"></span>');
};
var intp=function(s,len){
s=s==null?"-":s+"";
if(s.length>=len)return s;
return ("_______"+s).substr(-len);
};
var formatMs=function(ms,all){
var ss=ms%1000;ms=(ms-ss)/1000;
var s=ms%60;ms=(ms-s)/60;
var m=ms%60;ms=(ms-m)/60;
var h=ms;
var t=(h?h+":":"")
+(all||h+m?("0"+m).substr(-2)+":":"")
+(all||h+m+s?("0"+s).substr(-2)+"″":"")
+("00"+ss).substr(-3);
return t;
};
function recstop2(){
reclog(Html_$T("LZkZ::使用RecordApp.GetCurrentRecOrNull()方法,我们可以在停止录音时,得到RecordApp编码用的rec对象,因此可以进行二次编码。"),2);
var rec=stopRec;
if(!rec||!rec.buffers){
reclog(Html_$T("qKJ9::需先录个音"),1);
return;
};
var type=$("[name=type]:checked").val();
var sample=+$(".sample").val();
var bits=/(\d+)\s+to\s+(\d+)\s+step\s+(\d+)\s*/i.exec($(".bits").val());
if(!bits){
reclog(Html_$T("J1wQ::码率列表有误,需要? to ? step ?结构"));
return;
};
reclog(Html_$T("OQV2::开始批量编码,请勿进行其他操作~"));
rec.set.type=type;
rec.set.sampleRate=sample;
var list=[];
for(var i=+bits[1];i<+bits[2]+1;i+=+bits[3]){
list.push(i);
};
if(rec.set.type=="wav"){
list=[8,16];
};
if(rec.set.type=="amr"){
list=[4.75, 5.15, 5.9, 6.7, 7.4, 7.95, 10.2, 12.2];
};
var i=-1;
var bak=rec.set.bitRate;
var run=function(){
i++;
if(i>=list.length){
rec.set.bitRate=bak;
reclog(Html_$T("nUq7::批量编码完成"));
return;
};
rec.set.bitRate=list[i];
rec.isMock=1;
rec.dataType="blob";
var t1=Date.now();
rec.stop(function(blob,time){
addRecLog(time,Html_$T("A7H4::已编码"),blob,rec.set,t1);
run();
},function(s){
reclog(Html_$T("mFBf::失败:")+s,1);
});
};
run();
};
function recplay(key){
var audio=$(".recPlay")[0];
audio.style.display="inline-block";
if(!(audio.ended || audio.paused)){
audio.pause();
};
var o=recblob[key];
if(o){
o.play=(o.play||0)+1;
var logmsg=function(msg){
$(".p"+key).html('<span style="color:green">'+o.play+'</span> '+new Date().toLocaleTimeString()+" "+msg);
};
logmsg("");
audio.onerror=function(e){
logmsg('<span style="color:red">'+Html_$T("kj0b::播放失败")+'['+audio.error.code+']'+audio.error.message+'</span>');
};
if(o.play2Name){
o.play--;
if(o.play2Msg){
logmsg(o.play2Msg);
}else if(o.play2Err){
logmsg('<span style="color:red">'+o.play2Err+'</span>');
}else{
o.play++;
audio.src=o.play2Url||("../assets/audio/"+o.play2Name);
audio.play();
}
return;
};
var end=function(blob){
audio.src=(window.URL||webkitURL).createObjectURL(blob);
audio.play();
};
var wav=Recorder[o.set.type+"2wav"];
if(wav){
logmsg(Html_$T("Jysa::正在转码成wav..."));
var wavData=o.blob;
if(o.set.type=="pcm"){
wavData={
sampleRate:o.set.sampleRate
,bitRate:o.set.bitRate
,blob:o.blob
};
};
wav(wavData,function(blob){
end(blob);
logmsg(Html_$T("zbUk::已转码成wav播放"));
},function(msg){
logmsg('<span style="color:red">'+Html_$T('v8S9::转码成wav失败:')+msg+'</span>');
});
}else{
end(o.blob);
};
};
};
function recplay2(elem,name){
var url="";
var run=function(msg,err){
elem=$(elem);
var key="recplay2"+elem.html();
Object.assign(recblob[key]||(recblob[key]={}),{
play2Name:name
,play2Url:url
,play2Msg:msg
,play2Err:err
});
if(!$(".p"+key).length){
elem.before('<br>');
elem.after('<span class="p'+key+'"></span><br>');
};
recplay(key);
};
if(name=="nmn5"){ //合成一个5分钟的wav
if(window.nmn5Url){
url=window.nmn5Url; return run();
}
var sr=16000;
var pcm=Recorder.NMN2PCM.GetExamples().Canon.get(sr).pcm;
var pcm5=new Int16Array(5*60*sr),n=0;
while(n<pcm5.length){
var s=Math.min(pcm.length, pcm5.length-n);
pcm5.set(s==pcm.length?pcm:pcm.subarray(0,s),n); n+=pcm.length
}
run(Html_$T("q2iG::正在合成wav..."));
var mock=Recorder({ type:"wav",sampleRate:sr,bitRate:16 });
mock.mock(pcm5, sr);
mock.stop(function(blob){
url=window.nmn5Url=(window.URL||webkitURL).createObjectURL(blob);
run();
},function(err){
run("",err);
});
}else{ //播放音频文件
run();
}
};
function recPlayLast(){
if(!recLogLast){
reclog(Html_$T("U3nx::请先录音,然后停止后再播放"),1);
return;
};
recplay(recLogLast.key);
};
function recUploadLast(){
if(!recLogLast){
reclog(Html_$T("8y8L::请先录音,然后停止后再上传"),1);
return;
};
var blob=recLogLast.blob;
//本例子假设使用原始XMLHttpRequest请求方式,实际使用中自行调整为自己的请求方式
//录音结束时拿到了blob文件对象,可以用FileReader读取出内容,或者用FormData上传
var api="http://127.0.0.1:9528";
var onreadystatechange=function(xhr,title){
return function(){
if(xhr.readyState==4){
if(xhr.status==200){
reclog(title+Html_$T("ebkz::上传成功")+' <span style="color:#999">response: '+xhr.responseText+'</span>',2);
}else{
reclog(title+Html_$T("p3cq::没有完成上传,演示上传地址无需关注上传结果,只要浏览器控制台内Network面板内看到的请求数据结构是预期的就ok了。"), "#d8c1a0");
console.error(Html_xT(title+Html_$T("rscd::上传失败")),xhr.status,xhr.responseText);
};
};
};
};
reclog(Html_$T("t0Vr::开始上传到{1},请稍候... (你可以先到源码 /assets/node-localServer 目录内执行 npm run start 来运行本地测试服务器)",0,api));
/***方式一:将blob文件转成base64纯文本编码,使用普通application/x-www-form-urlencoded表单上传***/
var reader=new FileReader();
reader.onloadend=function(){
var postData="";
postData+="mime="+encodeURIComponent(blob.type);//告诉后端,这个录音是什么格式的,可能前后端都固定的mp3可以不用写
postData+="&upfile_b64="+encodeURIComponent((/.+;\s*base64\s*,\s*(.+)$/i.exec(reader.result)||[])[1]) //录音文件内容,后端进行base64解码成二进制
//...其他表单参数
var xhr=new XMLHttpRequest();
xhr.open("POST", api+"/uploadBase64");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.onreadystatechange=onreadystatechange(xhr,Html_$T("3Auy::上传方式一【Base64】"));
xhr.send(postData);
};
reader.readAsDataURL(blob);
/***方式二:使用FormData用multipart/form-data表单上传文件***/
var form=new FormData();
form.append("upfile",blob,"recorder.mp3"); //和普通form表单并无二致,后端接收到upfile参数的文件,文件名为recorder.mp3
//...其他表单参数
var xhr=new XMLHttpRequest();
xhr.open("POST", api+"/upload");
xhr.onreadystatechange=onreadystatechange(xhr,Html_$T("GEBC::上传方式二【FormData】"));
xhr.send(form);
};
function recDownLast(){
if(!recLogLast){
reclog(Html_$T("g1CD::请先录音,然后停止后再下载"),1);
return;
};
recdown(recLogLast.key);
};
function recdown(key){
var o=recblob[key];
if(o){
var cls=RandomKey(16);
var name="rec-"+o.time+"ms-"+o.set.bitRate+"kbps-"+o.set.sampleRate+"hz."+o.set.type;
o.down=(o.down||0)+1;
$(".d"+key).html('<span style="color:red">'+o.down+'</span> '
+Html_$T('Lw0c::点击{1}',0,"")+' <span class="'+cls+'"> '
+Html_$T('cs8P::下载,或复制文本')
+'<button onclick="recdown64(\''+key+'\',\''+cls+'\')">'+Html_$T('hziK::生成Base64文本')+'</button></span>');
var downA=document.createElement("A");