Skip to content

Commit

Permalink
累积更新:增加对MediaStream的直接支持,增加BufferStreamPlayer扩展用于实时音频片段文件播放,新增pcm格式编码器
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Aug 3, 2021
1 parent 59f9649 commit d3f8543
Show file tree
Hide file tree
Showing 26 changed files with 1,676 additions and 156 deletions.
302 changes: 253 additions & 49 deletions README.md

Large diffs are not rendered by default.

34 changes: 27 additions & 7 deletions app-support-sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@

<script>
//兼容环境
var PageLM="2021-2-15 17:38:39";
var PageLM="2021-08-03 21:16:50";

function RandomKey(){
return "randomkey"+(RandomKey.idx++);
Expand Down Expand Up @@ -266,9 +266,10 @@
<span class="lb">类型 :</span>
<label><input type="radio" name="type" value="mp3" engine="mp3,mp3-engine" class="initType" checked>mp3</label>
<label><input type="radio" name="type" value="wav" engine="wav">wav</label>
<label><input type="radio" name="type" value="pcm" engine="pcm" addload="wav">pcm</label>
<label><input type="radio" name="type" value="ogg" engine="beta-ogg,beta-ogg-engine">ogg(beta)</label>
<label><input type="radio" name="type" value="webm" engine="beta-webm">webm(beta)</label>
<label><input type="radio" name="type" value="amr" engine="beta-amr,beta-amr-engine,wav">amr(beta)</label>
<label><input type="radio" name="type" value="amr" engine="beta-amr,beta-amr-engine" addload="wav">amr(beta)</label>
</div>
<div class="pd">
<span class="lb">提示 :</span> <span class="typeTips">-</span>
Expand Down Expand Up @@ -775,11 +776,19 @@
var wav=Recorder[o.set.type+"2wav"];
if(wav){
logmsg("正在转码成wav...");
wav(o.blob,function(blob){
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("已转码成wav播放");
},function(msg){
logmsg("转码成wav失败:"+msg);
logmsg('<span style="color:red">转码成wav失败:'+msg+'</span>');
});
}else{
end(o.blob);
Expand Down Expand Up @@ -931,14 +940,25 @@
function loadEngine(input){
if(input.length&&input[0].nodeName=="INPUT"){
var type=input.val();
var engines=input.attr("engine").split(",");
var srcs=input.attr("engine").split(",");
var adds=input.attr("addload");
if(adds){
adds=adds.split(",");
};

var engines=[].concat(srcs, adds||[]);
var end=function(){
var enc=Recorder.prototype["enc_"+type];
var tips=[!enc?"这个编码器无提示信息":type+"编码器"+(enc.stable?"稳定版":"beta版")+",<span style='color:"+(type=="wav"?"#0b1'>wav转码超快":Recorder.prototype[type+"_start"]?"#0b1'>支持边录边转码(Worker)":"red'>仅支持标准UI线程转码")+"</span>,"+enc.testmsg];
var tips=[!enc?"这个编码器无提示信息":type+"编码器"+(enc.stable?"稳定版":"beta版")+",<span style='color:"
+(type=="wav"?"#0b1'>wav转码超快"
:type=="pcm"?"#0b1'>pcm转码超快"
:Recorder.prototype[type+"_start"]?"#0b1'>支持边录边转码(Worker)"
:"red'>仅支持标准UI线程转码")
+"</span>,"+enc.testmsg];
tips.push('<div style="color:green">');
tips.push("【使用"+type+"录音需要在app.js Platforms.Default内注册】:");
tips.push("src/recorder-core.js, src/engine/");
tips.push(engines.join(".js, src/engine/"));
tips.push(srcs.join(".js, src/engine/"));
tips.push(".js</div>");

$(".typeTips").html(tips.join(""));
Expand Down
Binary file not shown.
Binary file modified assets/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/header-leg__diygod.me.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions assets/npm-home/hash-history.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"sha1": "f25250465e0e93c0f75f6c0a16a0940e9c350857",
"time": "2021-8-4 02:20:20"
},
{
"sha1": "991658bd6c1486dbc6c639dbbc295d4e6aab2182",
"time": "2021-2-15 17:57:07"
Expand All @@ -14,9 +18,5 @@
{
"sha1": "fb3ceae274cae979c7ba353ec59cd38e95016fc9",
"time": "2020-11-17 10:37:35"
},
{
"sha1": "326682217de610f15e0e456fdfe0725362dc5cd2",
"time": "2020-6-26 19:35:22"
}
]
2 changes: 2 additions & 0 deletions assets/runtime-codes/fragment.playbuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ DemoFragment.PlayBuffer(store,buffer,sampleRate)
调用本方法前,应当确保Recorder.Support()是支持的。
本方法默认会缓冲播放,如果缓冲未满将不会进行播放,小片段偶尔播放应当禁用此特性store.PlayBufferDisable=true。
升级:新增的 BufferStreamPlayer 扩展(src/extensions/buffer_stream.player.js),完全包含了本功能,并且播放音质效果更佳,可参考 teach.realtime.decode_buffer_stream_player.js 中的示例;不过对于仅仅播放PCM数据,本方法还是不错的选择,简单小巧。
******************/
(
window.DemoFragment||(window.DemoFragment={})
Expand Down
Loading

0 comments on commit d3f8543

Please sign in to comment.