Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed May 24, 2022
1 parent 77c4de0 commit ba392ad
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 23 deletions.
63 changes: 54 additions & 9 deletions QuickStart.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<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="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/assets/icon.png">
<link rel="shortcut icon" type="image/png" href="assets/icon.png">

<title>Recorder H5 QuickStart: 快速入门</title>
<script>
Expand All @@ -13,12 +13,46 @@
</head>

<body>
<!-- ↓↓↓这部分代码无关紧要,可全部删掉,选择CDN线路用的↓↓↓ -->
<base href="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/" />
<script>
console.warn("本页面的js资源采用的CDN链接,这些CDN并不稳定,仅供测试用");
var setCDNUrl=function(url){
var old=document.querySelector("base");
if(old)old.parentNode.removeChild(old);
if(!url)return;
var base=document.createElement("base");
base.setAttribute("href",url);
document.head.appendChild(base);
console.warn("已切换CDN线路",url);
};
var useCDN={};
var intBadCDN=setTimeout(function(){ onBadCDN() },10000);
var onOKCDN=function(){ clearTimeout(intBadCDN) };
var onBadCDN=function(){
document.querySelector(".badCDN").innerHTML="cdn.jsdelivr.net可能不稳定,未能检测到js被成功加载。<br>如果页面异常,请复制本页面源码到本地测试,并且批量替换掉 https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/ 为 https://xiangyuecn.gitee.io/recorder/ 就能正常测试了";
clearTimeout(intBadCDN);
var cdn=useCDN.cdn;
var url=!cdn?"https://unpkg.com/recorder-core/":
/unpkg/i.test(cdn)?"https://xiangyuecn.gitee.io/recorder/":"";
if(!url){ setCDNUrl(""); return;}
location.hash="#useCDN="+encodeURIComponent(JSON.stringify({
time:Date.now()
,cdn:url
}));
location.reload();
};
if(/useCDN=([^&#]+)/.test(location.href)){
useCDN=JSON.parse(decodeURIComponent(RegExp.$1));
if(Date.now()-useCDN.time<60000){
setCDNUrl(useCDN.cdn);
}else{ useCDN={}; }
location.hash="";
}
</script>
<div class="badCDN" style="font-size: 50px;text-align: center;color: #f60;"></div>
<!-- ↑↑↑这部分代码无关紧要,可全部删掉,选择CDN线路用的↑↑↑ -->




<!--
Expand All @@ -28,15 +62,17 @@
-->

<!-- 【1.1】引入核心文件 -->
<script src="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/src/recorder-core.js" onerror="onBadCDN()"></script>
<script src="改成你clone的源码目录/../src/recorder-core.js" onerror="!window.onBadCDN||onBadCDN()" onload="!window.onOKCDN||onOKCDN()"></script>

<!-- 【1.2】引入相应格式支持文件;如果需要多个格式支持,把这些格式的编码引擎js文件放到后面统统加载进来即可 -->
<script src="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/src/engine/mp3.js"></script>
<script src="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/src/engine/mp3-engine.js"></script>
<script src="改成你clone的源码目录/../src/engine/mp3.js"></script>
<script src="改成你clone的源码目录/../src/engine/mp3-engine.js"></script>

<!-- 【1.3】引入可选的扩展支持项,如果不需要这些扩展功能可以不引入 -->
<script src="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/src/extensions/frequency.histogram.view.js"></script>
<script src="https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/src/extensions/lib.fft.js"></script>
<script src="改成你clone的源码目录/../src/extensions/frequency.histogram.view.js"></script>
<script src="改成你clone的源码目录/../src/extensions/lib.fft.js"></script>

<script>window.setCDNUrl&&setCDNUrl("");//清除CDN地址</script>


<!-- 【2】构建界面 -->
Expand Down Expand Up @@ -352,9 +388,18 @@

reclog("RecordApp[即将废弃] 除Recorder支持的外,支持Hybrid App,低版本IOS上支持微信网页和小程序web-view"+unescape("%uD83C%uDF89"),"#f60;font-weight:bold;font-size:24px");
reclog("Recorder H5使用简单,功能丰富,支持PC、Android、IOS 14.3+"+unescape("%uD83D%uDCAA"),"#0b1;font-weight:bold;font-size:24px");
reclog('本页面修改时间(有可能修改了忘改):2022-03-03 21:48:53',"#999");
reclog('Recorder库修改时间(有可能修改了忘改):'+Recorder.LM,"#999");
reclog('本页面修改时间(有可能修改了忘改):2022-05-24 19:31:18',"#999");
reclog('Recorder库修改时间(有可能修改了忘改):'+(window.Recorder&&Recorder.LM),"#999");
reclog(Tips);

if(window.useCDN && useCDN.cdn){
reclog('本页面的js资源采用的CDN不稳定,已切换到:'+useCDN.cdn,'#f60');
}
if(window.Recorder){
reclog('页面已准备好,请先点击打开录音,然后点击录制',2);
}else{
reclog("js文件加载失败,请刷新重试!","#f00;font-size:50px");
}
</script>

<script>
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ iOS Demo App :[下载源码](https://github.com/xiangyuecn/Recorder/tree/maste
<p align="center">
Traffic:
<a title="npm Downloads" href="https://www.npmjs.com/package/recorder-core"><img src="https://img.shields.io/npm/dt/recorder-core?color=f60&logo=npm" alt="npm Downloads"></a>
<a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://img.shields.io/badge/cnpm-available-1690CD" alt="cnpm"></a><a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://npmmirror.com/badge/d/recorder-core.svg" alt="cnpm"></a>
<a title="JsDelivr CDN" href="https://www.jsdelivr.com/package/gh/xiangyuecn/Recorder"><img src="https://data.jsdelivr.com/v1/package/gh/xiangyuecn/Recorder/badge" alt="JsDelivr CDN"></a>
<a title="51LA" href="https://www.51.la/?20469973"><img src="https://img.shields.io/badge/51LA-available-0b1" alt="cnpm"></a>
<a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://img.shields.io/badge/-cnpm-555" alt="cnpm"></a><a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://npmmirror.com/badge/d/recorder-core.svg" alt="cnpm"></a>
<a title="JsDelivr CDN" href="https://www.jsdelivr.com/package/gh/xiangyuecn/Recorder"><img src="https://img.shields.io/badge/CDN-JsDelivr-f60" alt="JsDelivr CDN"></a>
<a title="unpkg CDN" href="https://unpkg.com/recorder-core/"><img src="https://img.shields.io/badge/CDN-unpkg-f60" alt="unpkg CDN"></a>
<a title="51LA" href="https://www.51.la/?20469973"><img src="https://img.shields.io/badge/51LA-available-0b1" alt="51LA"></a>
</p>

[](?RefEnd)
Expand All @@ -157,13 +158,13 @@ iOS Demo App :[下载源码](https://github.com/xiangyuecn/Recorder/tree/maste

**方式一**:使用script标签引入

在需要录音功能的页面引入压缩好的recorder.xxx.min.js文件即可[JsDelivr CDN](https://www.jsdelivr.com/features)
在需要录音功能的页面引入压缩好的recorder.xxx.min.js文件即可(CDN:[JsDelivr](https://www.jsdelivr.com/package/gh/xiangyuecn/Recorder)[unpkg](https://unpkg.com/recorder-core/)
``` html
<script src="recorder.mp3.min.js"></script> <!--已包含recorder-core和mp3格式支持, CDN: https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/recorder.mp3.min.js-->
<script src="recorder.mp3.min.js"></script> <!--已包含recorder-core和mp3格式支持, CDN不稳定仅供测试: https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/recorder.mp3.min.js-->
```
或者直接使用源码(src内的为源码、dist内的为压缩后的),可以引用src目录中的recorder-core.js+相应类型的实现文件,比如要mp3录音:
``` html
<script src="src/recorder-core.js"></script> <!--必须引入的录音核心,CDN: https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/dist/recorder-core.js-->
<script src="src/recorder-core.js"></script> <!--必须引入的录音核心,CDN不稳定仅供测试: https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/src/recorder-core.js-->

<script src="src/engine/mp3.js"></script> <!--相应格式支持文件;如果需要多个格式支持,把这些格式的编码引擎js文件放到后面统统加载进来即可-->
<script src="src/engine/mp3-engine.js"></script> <!--如果此格式有额外的编码引擎(*-engine.js)的话,必须要加上-->
Expand Down Expand Up @@ -707,7 +708,7 @@ function transformOgg(pcmData){
//仅作为返回值
frameNext:null||[Int16,...] 下一帧的部分数据,frameSize设置了的时候才可能会有
sampleRate:16000 结果的采样率,<=newSampleRate
data:[Int16,...] 转换后的PCM结果(16位小端LE),为一维数组,可直接new Blob([data],"audio/pcm")生成Blob文件,或者使用mock方法转换成其他音频格式;注意:如果是连续转换,并且pcmDatas中并没有新数据时,data的长度可能为0
data:[Int16,...] 转换后的PCM结果(16位小端LE),为一维数组,可直接new Blob([data],{type:"audio/pcm"})生成Blob文件,或者使用mock方法转换成其他音频格式;注意:如果是连续转换,并且pcmDatas中并没有新数据时,data的长度可能为0
}
```

Expand Down
7 changes: 4 additions & 3 deletions app-support-sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

Traffic:
<a title="npm Downloads" href="https://www.npmjs.com/package/recorder-core"><img src="https://img.shields.io/npm/dt/recorder-core?color=f60&logo=npm" alt="npm Downloads"></a>
<a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://img.shields.io/badge/cnpm-available-1690CD" alt="cnpm"></a><a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://npmmirror.com/badge/d/recorder-core.svg" alt="cnpm"></a>
<a title="JsDelivr CDN" href="https://www.jsdelivr.com/package/gh/xiangyuecn/Recorder"><img src="https://data.jsdelivr.com/v1/package/gh/xiangyuecn/Recorder/badge" alt="JsDelivr CDN"></a>
<a title="51LA" href="https://www.51.la/?20469973"><img src="https://img.shields.io/badge/51LA-available-0b1" alt="cnpm"></a>
<a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://img.shields.io/badge/-cnpm-555" alt="cnpm"></a><a title="cnpm" href="https://npmmirror.com/package/recorder-core"><img src="https://npmmirror.com/badge/d/recorder-core.svg" alt="cnpm"></a>
<a title="JsDelivr CDN" href="https://www.jsdelivr.com/package/gh/xiangyuecn/Recorder"><img src="https://img.shields.io/badge/CDN-JsDelivr-f60" alt="JsDelivr CDN"></a>
<a title="unpkg CDN" href="https://unpkg.com/recorder-core/"><img src="https://img.shields.io/badge/CDN-unpkg-f60" alt="unpkg CDN"></a>
<a title="51LA" href="https://www.51.la/?20469973"><img src="https://img.shields.io/badge/51LA-available-0b1" alt="51LA"></a>



Expand Down
4 changes: 2 additions & 2 deletions assets/runtime-codes/lib.transform.amr2other.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ var test=function(amrBlob){
//加载录音框架
Runtime.Import([
{url:RootFolder+"/src/recorder-core.js",check:function(){return !window.Recorder}}
,{url:"https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/dist/engine/mp3.js",check:function(){return !Recorder.prototype.mp3}}
,{url:"https://cdn.jsdelivr.net/gh/xiangyuecn/Recorder@latest/dist/engine/beta-amr.js",check:function(){return !Recorder.prototype.amr}}
,{url:RootFolder+"/dist/engine/mp3.js",check:function(){return !Recorder.prototype.mp3}}
,{url:RootFolder+"/dist/engine/beta-amr.js",check:function(){return !Recorder.prototype.amr}}
]);

//显示控制按钮
Expand Down
2 changes: 1 addition & 1 deletion assets/runtime-codes/teach.realtime.encode_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var RealTimeSendTry=function(buffers,bufferSampleRate,isClose){
};
realTimeSendTryEncBusy++;

//通过mock方法实时转码成mp3、wav;16位pcm格式可以不经过此操作,直接发送new Blob([pcm],"audio/pcm") 要8位的就必须转码
//通过mock方法实时转码成mp3、wav;16位pcm格式可以不经过此操作,直接发送new Blob([pcm.buffer],{type:"audio/pcm"}) 要8位的就必须转码
var encStartTime=Date.now();
var recMock=Recorder({
type:realTimeSendTryType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var RealTimeSendTry=function(buffers,bufferSampleRate,isClose){
return;
};

//16位pcm格式可以不经过mock转码,直接发送new Blob([pcm],"audio/pcm") 但8位的就必须转码,通用起见,均转码处理,pcm转码速度极快
//16位pcm格式可以不经过mock转码,直接发送new Blob([pcm.buffer],{type:"audio/pcm"}) 但8位的就必须转码,通用起见,均转码处理,pcm转码速度极快
var number=++realTimeSendTryNumber;
var encStartTime=Date.now();
var recMock=Recorder({
Expand Down

0 comments on commit ba392ad

Please sign in to comment.