From 8806e2dd66d7c0a2908bcd579813a13de14eb026 Mon Sep 17 00:00:00 2001 From: xiangyuecn <753610399@qq.com> Date: Tue, 25 Jun 2024 01:56:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0demo=5FUniApp=E5=92=8C?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app-support-sample/demo_UniApp/README.md | 21 +- app-support-sample/demo_UniApp/pages.json | 74 +++-- .../pages/recTest/main_recTest.vue | 7 + .../pages/recTest/page_renderjsWithout.vue | 295 ++++++++++++++++++ .../pages/recTest/test_native_plugin.vue | 8 + .../pages/recTest/test_player___.vue | 4 +- .../Recorder-UniCore/app-uni-support.js | 2 +- .../uni_modules/Recorder-UniCore/changelog.md | 2 + .../Recorder-UniCore/i18n/Template.js | 56 +++- .../Recorder-UniCore/i18n/en-US.js | 46 ++- .../uni_modules/Recorder-UniCore/package.json | 2 +- .../uni_modules/Recorder-UniCore/readme.md | 44 ++- 12 files changed, 502 insertions(+), 59 deletions(-) create mode 100644 app-support-sample/demo_UniApp/pages/recTest/page_renderjsWithout.vue diff --git a/app-support-sample/demo_UniApp/README.md b/app-support-sample/demo_UniApp/README.md index 8b3549e..7ab94e8 100644 --- a/app-support-sample/demo_UniApp/README.md +++ b/app-support-sample/demo_UniApp/README.md @@ -323,7 +323,10 @@ RecordApp.Start({ ,audioTrackSet:{echoCancellation:true,noiseSuppression:true,autoGainControl:true} //Android指定麦克风源(App搭配原生插件、小程序可用),0 DEFAULT 默认音频源,1 MIC 主麦克风,5 CAMCORDER 相机方向的麦,6 VOICE_RECOGNITION 语音识别,7 VOICE_COMMUNICATION 语音通信(带回声消除) - ,android_audioSource:7 //提供此配置时优先级比audioTrackSet更高 + ,android_audioSource:7 //提供此配置时优先级比audioTrackSet更高,默认值为0 + + //iOS的AVAudioSession setCategory的withOptions参数值(App搭配原生插件可用),取值请参考本文档下面的iosSetDefault_categoryOptions + //,ios_categoryOptions:0x1|0x4|0x8 //0x8是外放,默认值为0x1|0x4不带0x8是听筒播放,等同于下面的setSpeakerOff }); //App搭配原生插件时尝试切换听筒播放或外放 @@ -456,7 +459,7 @@ base64解码,将base64字符串转为字符串 var dataMB=new Uint8Array(1*1024*1024); //可选的,假设同时需要传递1MB的数据到renderjs中 var set={ //可选配置 tag:"格式转码" //可选调用标记,抛异常时会添加到错误消息开头,默认为空字符串 - ,timeout:5000 //可选调用超时,默认5秒超时 + ,timeout:5000 //可选调用超时,默认5秒超时,-1不超时 ,useEval:false //可选是否要通过UniWebViewEval来执行jsCode,默认false使用UniWebViewVueCall来执行jsCode(此时jsCode中的this为renderjs模块的this) }; try{ @@ -473,7 +476,7 @@ try{ CallSuccess({abc:123}, new Uint8Array(9).buffer); //可以额外返回一个ArrayBuffer,逻辑层将接收到一个对象 result={ value:{abc:123}, bigBytes:ArrayBuffer } `, dataMB.buffer); }catch(e){ - result={errMsg:e.message}; + result={timeout:!!e.isTimeout, errMsg:e.message}; } uni.showModal({title:"renderjs调用结果", content:JSON.stringify(result)}); ``` @@ -482,7 +485,7 @@ uni.showModal({title:"renderjs调用结果", content:JSON.stringify(result)}); App 逻辑层中直接调用此页面或组件的WebView renderjs中的eval(componentThis为null时使用UniWebViewActivate切换的页面或组件);要调用renderjs模块vue组件内的方法请用UniWebViewVueCall;如果需要传递大的数据请用bigBytes参数传入一个ArrayBuffer,jsCode中使用BigBytes变量得到这个数据 ``` javascript -//调用示例代码,可使用UniWebViewCallAsync简化这些调用 +//调用示例代码,非频繁调用时建议使用UniWebViewCallAsync简化这些调用 var cb=RecordApp.UniMainCallBack((data)=>{ //可选的,renderjs执行完成后回调 uni.showModal({title:"收到了renderjs回调", content:JSON.stringify(data)}); }); @@ -501,7 +504,8 @@ RecordApp.UniWebViewEval(this,` App 逻辑层中直接调用此页面或组件的renderjs模块vue组件内的方法(componentThis为null时使用UniWebViewActivate切换的页面或组件),jsCode中的this为renderjs模块的this(也可以用This变量)(如需renderjs中调用逻辑层vue实例方法,请直接用$ownerInstance.callMethod即可);如果需要传递大的数据请用bigBytes参数传入一个ArrayBuffer,jsCode中使用BigBytes变量得到这个数据 ``` javascript -//调用示例代码,可使用UniWebViewCallAsync简化这些调用 +//调用示例代码,非频繁调用时建议使用UniWebViewCallAsync简化这些调用 +//jsCode可以传个对象{preCode:"",jsCode:""},preCode相当于UniWebViewEval调用,会在获取到vue上下文前执行,获取失败时jsCode无法执行,preCode中可重新赋值CallErr函数来绑定失败回调 var cb=RecordApp.UniMainCallBack((data)=>{ //可选的,renderjs执行完成后回调 uni.showModal({title:"收到了renderjs回调", content:JSON.stringify(data)}); }); @@ -557,6 +561,7 @@ RecordApp.UniNativeUtsPlugin={ //目前仅支持原生插件,uts插件不可 //,nativePluginName:"xxx" //可指定插件名字,默认为Recorder-NativePlugin }; +//配置好后可调用RecordApp.UniCheckNativeUtsPluginConfig()来检查配置是否能生效,返回空字符串代表正常,如果无法加载原生录音插件会返回错误消息 //配置好后在调用录音功能时,会使用原生插件来录音 ``` @@ -582,6 +587,12 @@ setSpeakerOff 切换扬声器外放和听筒播放,随时都可以调用;但 参数:{ off:true } //必填,true听筒播放,false扬声器播放 返回:{ } //空对象 +iosSetDefault_categoryOptions iOS设置默认值,Android不可调用,为iOS的AVAudioSession setCategory的withOptions参数值;RecordApp.Start开始录音时如果未提供ios_categoryOptions参数,将会使用此默认值,提供了时将赋值给此默认值;setSpeakerOff调用时也会使用到此默认值 + 参数:{ + value:0x1|0x4|0x8 //必填,0x8是外放,默认不带0x8是听筒播放,取值(多选,默认 0x1|0x4):0 什么也不设置,0x1 MixWithOthers,0x2 DuckOthers,0x4 AllowBluetooth,0x8 DefaultToSpeaker,0x11 InterruptSpokenAudioAndMixWithOthers,0x20 AllowBluetoothA2DP,0x40 AllowAirPlay,0x80 OverrideMutedMicrophoneInterruption + } + 返回:{ } //空对象 + writeFile 数据写入文件,可新建文件、追加写入(文件流写入) 参数:{ path:"文件路径" //必填,支持的路径请参考下面 diff --git a/app-support-sample/demo_UniApp/pages.json b/app-support-sample/demo_UniApp/pages.json index c385175..2d9a82b 100644 --- a/app-support-sample/demo_UniApp/pages.json +++ b/app-support-sample/demo_UniApp/pages.json @@ -1,54 +1,60 @@ { "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages { - "path" : "pages/recTest/page_index", - "style" : { - "navigationBarTitleText": "RecordApp录音测试 - uni-app" - } - }, + "path" : "pages/recTest/page_index", + "style" : { + "navigationBarTitleText": "RecordApp录音测试 - uni-app" + } + }, + { + "path" : "pages/recTest/page_index2", + "style" : { + "navigationBarTitleText": "RecordApp新开页面index - uni-app" + } + }, { - "path" : "pages/recTest/page_index2", - "style" : { - "navigationBarTitleText": "RecordApp新开页面index - uni-app" - } + "path" : "pages/recTest/main_recTest", + "style" : { + "navigationBarTitleText": "RecordApp新开页面main - uni-app" + } }, { - "path" : "pages/recTest/main_recTest", - "style" : { - "navigationBarTitleText": "RecordApp新开页面main - uni-app" - } + "path" : "pages/recTest/page_asr", + "style" : { + "navigationBarTitleText": "RecordApp语音识别ASR - uni-app" + } }, { - "path" : "pages/recTest/page_asr", - "style" : { - "navigationBarTitleText": "RecordApp语音识别ASR - uni-app" - } + "path" : "pages/recTest/page_i18n", + "style" : { + "navigationBarTitleText": "RecordApp国际化多语言 - uni-app" + } }, { - "path" : "pages/recTest/page_i18n", - "style" : { - "navigationBarTitleText": "RecordApp国际化多语言 - uni-app" - } + "path" : "pages/recTest/page_nvue", + "style" : { + "navigationBarTitleText": "RecordApp nvue原生页面 - uni-app" + } }, { - "path" : "pages/recTest/page_nvue", - "style" : { - "navigationBarTitleText": "RecordApp nvue原生页面 - uni-app" - } + "path" : "pages/recTest/page_renderjsOnly", + "style" : { + "navigationBarTitleText": "RecordApp纯renderjs调用 - uni-app" + } }, { - "path" : "pages/recTest/page_renderjsOnly", - "style" : { - "navigationBarTitleText": "RecordApp纯renderjs调用 - uni-app" - } + "path" : "pages/recTest/page_renderjsWithout", + "style" : { + "navigationBarTitleText": "逻辑层编码UniWithoutAppRenderjs - uni-app" + } }, { - "path" : "pages/recTest/page_vue3____composition_api", - "style" : { - "navigationBarTitleText": "RecordApp vue3组合式api测试 - uni-app" - } + "path" : "pages/recTest/page_vue3____composition_api", + "style" : { + "navigationBarTitleText": "RecordApp vue3组合式api测试 - uni-app" + } } - ], + ], "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "uni-app", diff --git a/app-support-sample/demo_UniApp/pages/recTest/main_recTest.vue b/app-support-sample/demo_UniApp/pages/recTest/main_recTest.vue index eb20adb..a760260 100644 --- a/app-support-sample/demo_UniApp/pages/recTest/main_recTest.vue +++ b/app-support-sample/demo_UniApp/pages/recTest/main_recTest.vue @@ -153,6 +153,13 @@ DCloud 插件市场下载组件: https://ext.dcloud.net.cn/plugin?name=Recorder- + + + + + + + diff --git a/app-support-sample/demo_UniApp/pages/recTest/page_renderjsWithout.vue b/app-support-sample/demo_UniApp/pages/recTest/page_renderjsWithout.vue new file mode 100644 index 0000000..1c7c723 --- /dev/null +++ b/app-support-sample/demo_UniApp/pages/recTest/page_renderjsWithout.vue @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + diff --git a/app-support-sample/demo_UniApp/pages/recTest/test_native_plugin.vue b/app-support-sample/demo_UniApp/pages/recTest/test_native_plugin.vue index 008202c..80ce7f8 100644 --- a/app-support-sample/demo_UniApp/pages/recTest/test_native_plugin.vue +++ b/app-support-sample/demo_UniApp/pages/recTest/test_native_plugin.vue @@ -227,6 +227,14 @@ export default { return "code:"+data.code }]]); } + if(RecordApp.UniIsApp()==2){ + await this.exec("iOS设置categoryOptions",[ + ["iosSetDefault_categoryOptions",{value:123456789}], + ["iosSetDefault_categoryOptions",{value:0}], + ["iosSetDefault_categoryOptions",{value:0x1 | 0x2 | 0x4 | 0x8 | 0x20 | 0x40 | 0x80}], + ["iosSetDefault_categoryOptions",{value:0x1 | 0x4}] + ]); + } this.reclog("测试完成"); } diff --git a/app-support-sample/demo_UniApp/pages/recTest/test_player___.vue b/app-support-sample/demo_UniApp/pages/recTest/test_player___.vue index dc05c5c..57d0120 100644 --- a/app-support-sample/demo_UniApp/pages/recTest/test_player___.vue +++ b/app-support-sample/demo_UniApp/pages/recTest/test_player___.vue @@ -36,7 +36,7 @@ export default { return { ...this.getTexts() ,show:false, statusMsg:"", Class:("a"+Math.random()).replace(".","") - ,showControlUI:false, useNvuePlayer:false + ,showControlUI:false, useNvuePlayer:false, useAppRenderjs:false ,playing:false ,player_position:0 ,player_currentTime:"00:00" @@ -411,7 +411,7 @@ export default { var end=()=>{ this.createAudio(recSet.type,aBuf0,mime0,aBuf,duration,mime) } - if(!RecordApp.UniIsApp() || RecordApp.UniWithoutAppRenderjs){ + if(!RecordApp.UniIsApp() || RecordApp.UniWithoutAppRenderjs && !this.useAppRenderjs){ var wav=Recorder[recSet.type+"2wav"],t1=Date.now(); if(!wav) return end(); var wavData=aBuf; diff --git a/app-support-sample/demo_UniApp/uni_modules/Recorder-UniCore/app-uni-support.js b/app-support-sample/demo_UniApp/uni_modules/Recorder-UniCore/app-uni-support.js index bbbbe2b..775d648 100644 --- a/app-support-sample/demo_UniApp/uni_modules/Recorder-UniCore/app-uni-support.js +++ b/app-support-sample/demo_UniApp/uni_modules/Recorder-UniCore/app-uni-support.js @@ -35,4 +35,4 @@ App配套原生插件:https://ext.dcloud.net.cn/plugin?name=Recorder-NativePlu 【App nvue】 引入RecordApp和本js,配置RecordApp.UniWithoutAppRenderjs=true 和提供RecordApp.UniNativeUtsPlugin,录音操作和H5完全相同,但不支持可视化扩展 ***/ -!function(e){var n="object"==typeof window&&!!window.document,t=n?window:Object,i="https://github.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_UniApp";if(t.RecordApp){var r=t.Recorder,a=r.i18n;!function(m,S,e,y,C){"use strict";var W=S.RecordApp,h=W.CLog,B=function(){};W.UniSupportLM="2024-04-09 19:56";var P="app-uni-support.js",V=!1,M=!1,I=!1,j=!1,N=!1;(function(){/* #ifdef APP */if(C){V=!0;var e=navigator.userAgent.replace(/[_\d]/g," ");M=!/\bandroid\b/i.test(e)&&/\bios\b|\biphone\b/i.test(e)}else"object"==typeof plus&&("Android"==plus.os.name?V=!0:"iOS"==plus.os.name&&(M=V=!0)),(I=V)||h("App !plus",1)/* #endif */})(),V||((function(){/* #ifdef H5 */j=!0/* #endif */})(),(function(){/* #ifdef MP-WEIXIN */N=!0/* #endif */})());W.UniIsApp=function(){return V?M?2:1:0};var T=W.UniBtoa=function(e){if("object"==typeof uni&&uni.arrayBufferToBase64)return uni.arrayBufferToBase64(e);for(var n=new Uint8Array(e),t="",i=0,r=n.length;i=a[e(196)])o[e(464)](e(303)+c+e(233)+c+e(454)+i+e(445));else{var t=W[e(141)](p),n=u;u+=524288;var r=a[e(310)](n,u);o[e(464)](e(380)+c+e(293)+c+e(304)+a[e(196)]+e(396)+T(r)+e(224)+t+e(336))}};p()}else o[s(464)](s(295)+i+s(190))},W[f(314)]=function(e,t,n){var r=f,i="";i||I||(i=y(r(406)));var a=!i&&l(e,null==e);if(i||a||(i=y(r(null==e?400:397))),i)return i+=y(r(142)),h(i+r(188)+t[r(429)](0,200),1),i;W[r(273)](e,r(389)+a+r(480)+t+r(451),n)},W[f(264)]=function(t,c,s,u){return new Promise(function(n,r){var i=A,a=(c=c||{})[i(172)]||"",o=setTimeout(function(){o=0,r(new Error(a+i(386)))},c[i(206)]||5e3),e=W[i(141)](function(e){var t=i;if(o)return clearTimeout(o),o=0,e[t(456)]?n({value:e[t(193)],bigBytes:W[t(131)](e[t(456)])}):e[t(483)]?n(e[t(193)]):void r(new Error(a+e[t(466)]))});W[c[i(144)]?i(273):i(314)](t,i(423)+e+i(488)+e+i(463)+e+i(528)+s+"\n\t",u)})};var p=f(395),r=function(){var i=f;if(I&&i(425)!=typeof UniServiceJSBridge){var e=W[i(391)];if(e){var t="";try{t=uni[i(135)](p)}catch(e){}if(e==t)return;h(y(i(453)),3)}e="r"+Math[i(449)]();try{uni[i(248)](p,e)}catch(e){}W[i(391)]=e,UniServiceJSBridge[i(129)](p),UniServiceJSBridge[i(267)](p,function(e){var t=i,n=e[t(368)]||"";if(t(125)!=n)if(t(370)!=n)if(-1==n[t(341)](t(185)))-1==n[t(341)](t(363))?h(y(t(364))+JSON[t(511)](e),1):W[t(509)](e);else{var r=W[t(532)][n];r&&r(e)}else O(e);else g(e)})}};W[f(141)]=function(t){var e=f,n=W[e(532)],r=++n.id,i=e(185)+r;return n[i]=function(e){delete n[i],t(e)},i},W[f(232)]=function(e){UniViewJSBridge[f(280)](p,e)},W[f(237)]=function(r,i,e){var a=f;if(C&&V){var o=W[a(288)];if(o){var c=W[a(532)],s=0,u=++c.id;c[a(363)+u]=function(e){s=e,t()};var p=0,t=function(){var e=a;if(0!=p&&p>=r[e(196)])return delete c[e(363)+u],void i(s);var t=p;p+=524288;var n=r[e(310)](t,p);W[e(232)]({action:e(t?227:317),wvCid:o,wvID:u,mainID:s,b64:T(n)})};t()}else e(y(a(379)))}else e(y(a(157)))},W[f(509)]=function(e){var t=f,n=e[t(139)],r=W[t(532)],i=t(363);t(317)==e[t(368)]&&(n=++r.id,r[i+n]={memory:new Uint8Array(2097152),mOffset:0});var a=r[i+n];if(a){var o=new Uint8Array(k(e[t(419)])),c=o[t(162)];if(a[t(217)]+c>a[t(132)][t(162)]){var s=new Uint8Array(a[t(132)][t(162)]+Math[t(335)](2097152,c));s[t(468)](a[t(132)][t(481)](0,a[t(217)])),a[t(132)]=s}a[t(132)][t(468)](o,a[t(217)]),a[t(217)]+=c,W[t(273)](R(e[t(519)]),t(147)+i+e[t(255)]+t(155)+n+t(212))}else h(y(t(128)),3)},W[f(131)]=function(e){var t=f;if(!I)return null;var n=W[t(532)],r=n[t(363)+e];return delete n[t(363)+e],r?r[t(132)][t(322)][t(310)](0,r[t(217)]):null},W[f(431)]=function(n,i,a,r){var o=f;a=a||B,r=r||B;var c=function(e){var t=A;r(y(t(170),0,n)+(e[t(348)]||e[t(466)]))};if(N){var e=wx[o(359)][o(515)]+"/"+n;wx[o(376)]()[o(437)]({filePath:e,encoding:o(458),data:i,success:function(){a(e)},fail:c})}else I?plus.io[o(173)](plus.io[o(489)],function(e){var t=o;e[t(210)][t(146)](n,{create:!0},function(n){var r=t;n[r(313)](function(e){var t=r;e[t(175)]=function(){a(n[t(494)])},e[t(243)]=c;try{e[t(282)](T(i))}catch(e){c(e)}},c)},c)},c):r(y(o(152)))};var i=function(e){var t=f;if(_(),I){var n=y(t(486),0,m),r=W[t(296)];r&&(!e&&W[t(374)]||(W[t(374)]=1,r[t(521)]?h(y(t(174))+n):h(y(t(235))+n))),W[t(375)]?r?!e&&W[t(291)]||(W[t(291)]=1,h(y(t(473))+n)):h(y(t(428))+n,1):W[t(289)]&&(W[t(524)]?!e&&W[t(278)]||(W[t(278)]=1,h(y(t(133))+n)):h(y(t(477))+n,1))}};W[f(283)]=function(e,t,n,i){var r=f,a=[];if(N){var o=function(n){var r=A;n>=t[r(162)]?i[r(345)](e,a):e[r(367)]()[r(471)](t[n])[r(323)]({node:!0})[r(347)](function(e){var t=r;a[t(285)](e[0][t(286)]),o(n+1)})};o(0)}else if(j){for(var c=0,s=t[r(162)];c=a[e(711)])o[e(712)](e(581)+c+e(419)+c+e(648)+i+e(474));else{var t=h[e(340)](l),n=u;u+=524288;var r=a[e(524)](n,u);o[e(712)](e(565)+c+e(518)+c+e(553)+a[e(711)]+e(503)+E(r)+e(590)+t+e(432))}};l()}else o[s(712)](s(315)+i+s(470))},h[f(678)]=function(e,t,n){var r=f,i="";r(301)==typeof t&&(i=t[r(300)]||"",t=t[r(378)]||"");var a="";a||V||(a=C(r(570)));var o=!a&&p(e,null==e);if(a||o||(a=C(r(null==e?555:427))),a)return a+=C(r(639)),W(a+r(596)+t[r(434)](0,200),1),a;h[r(529)](e,r(392)+i+r(538)+JSON[r(572)](C(r(696)))+r(389)+o+r(426)+JSON[r(572)](C(r(617)))+r(663)+JSON[r(572)](C(r(609)))+r(638)+t+r(298),n)},h[f(438)]=function(d,v,f,A){return new Promise(function(n,r){var i=w,a=(v=v||{})[i(682)]||"",o=-1==v[i(674)],t="",c=setTimeout(function(){var e=i;s(),c=0;var t=new Error(C(e(o?425:520),0,a));t[e(399)]=1,r(t)},o?2e3:v[i(674)]||5e3),s=function(){var e=h[i(472)];delete e[u],delete e[t]};o&&(t=h[i(340)](function(){clearTimeout(c)}));var e=function(e){var t=i;if(s(),c)return clearTimeout(c),c=0,e[t(452)]?n({value:e[t(626)],bigBytes:h[t(379)](e[t(452)])}):e[t(635)]?n(e[t(626)]):void r(new Error(a+e[t(531)]))},u=h[i(340)](e),l=i(345)+u+i(415)+u+i(489)+R+i(457)+u+i(380)+(o?i(677)+R+i(457)+t+i(652):"")+i(622)+JSON[i(572)](C(i(655)))+i(362)+JSON[i(572)](C(i(670),0,i(477)+P+'"'))+i(310);v[i(410)]?l+=f:l={preCode:l+=i(325),jsCode:f};var p=h[v[i(410)]?i(529):i(678)](d,l,A);p&&e({errMsg:p})})};var R=f(695),r=function(){var i=f;if(V&&i(542)!=typeof UniServiceJSBridge){var e=h[i(304)];if(e){var t="";try{t=uni[i(309)](R)}catch(e){}if(e==t)return;W(C(i(577)),3)}e="r"+Math[i(418)]();try{uni[i(672)](R,e)}catch(e){}h[i(304)]=e,UniServiceJSBridge[i(413)](R),UniServiceJSBridge[i(621)](R,function(e){var t=i,n=e[t(411)]||"";if(t(584)!=n)if(t(690)!=n)if(-1==n[t(435)](t(713)))-1==n[t(435)](t(403))?W(C(t(480))+JSON[t(572)](e),1):h[t(580)](e);else{var r=h[t(472)][n];r&&r(e)}else F(e);else k(e)})}};function w(e,t){var n=i();return(w=function(e,t){return n[e-=296]})(e,t)}h[f(340)]=function(t){var e=f,n=h[e(472)],r=++n.id,i=e(713)+r;return n[i]=function(e){delete n[i],t(e)},i},h[f(509)]=function(e){UniViewJSBridge[f(349)](R,e)},h[f(700)]=function(r,i,e){var a=f;if(y&&j){var o=h[a(710)];if(o){var c=h[a(472)],s=0,u=++c.id;c[a(403)+u]=function(e){s=e,t()};var l=0,t=function(){var e=a;if(0!=l&&l>=r[e(711)])return delete c[e(403)+u],void i(s);var t=l;l+=524288;var n=r[e(524)](t,l);h[e(509)]({action:e(t?640:306),wvCid:o,wvID:u,mainID:s,b64:E(n)})};t()}else e(C(a(675)))}else e(C(a(715)))},h[f(580)]=function(e){var t=f,n=e[t(485)],r=h[t(472)],i=t(403);t(306)==e[t(411)]&&(n=++r.id,r[i+n]={memory:new Uint8Array(2097152),mOffset:0});var a=r[i+n];if(a){var o=new Uint8Array(T(e[t(563)])),c=o[t(650)];if(a[t(628)]+c>a[t(687)][t(650)]){var s=new Uint8Array(a[t(687)][t(650)]+Math[t(659)](2097152,c));s[t(334)](a[t(687)][t(536)](0,a[t(628)])),a[t(687)]=s}a[t(687)][t(334)](o,a[t(628)]),a[t(628)]+=c,h[t(529)](v(e[t(619)]),t(352)+i+e[t(350)]+t(685)+n+t(574))}else W(C(t(631)),3)},h[f(379)]=function(e){var t=f;if(!V)return null;var n=h[t(472)],r=n[t(403)+e];return delete n[t(403)+e],r?r[t(687)][t(559)][t(524)](0,r[t(628)]):null},h[f(680)]=function(n,i,a,r){var o=f;a=a||B,r=r||B;var c=function(e){var t=w;r(C(t(606),0,n)+(e[t(679)]||e[t(531)]))};if(N){var e=wx[o(431)][o(607)]+"/"+n;wx[o(383)]()[o(357)]({filePath:e,encoding:o(447),data:i,success:function(){a(e)},fail:c})}else V?plus.io[o(686)](plus.io[o(533)],function(e){var t=o;e[t(402)][t(521)](n,{create:!0},function(n){var r=t;n[r(467)](function(e){var t=r;e[t(595)]=function(){a(n[t(676)])},e[t(605)]=c;try{e[t(561)](E(i))}catch(e){c(e)}},c)},c)},c):r(C(o(461)))};var a=function(e){var t=f;if(_(),V){var n=C(t(443),0,b),r=h[t(377)];r&&(!e&&h[t(537)]||(h[t(537)]=1,r[t(328)]?W(C(t(456))+n):W(C(t(424))+n))),h[t(437)]?r?!e&&h[t(366)]||(h[t(366)]=1,W(C(t(615))+n)):W(C(t(448))+n,1):h[t(649)]&&(h[t(551)]?!e&&h[t(371)]||(h[t(371)]=1,W(C(t(388))+n)):W(C(t(708))+n,1))}};h[f(492)]=function(e,t,n,i){var r=f,a=[];if(N){var o=function(n){var r=w;n>=t[r(650)]?i[r(548)](e,a):e[r(370)]()[r(473)](t[n])[r(450)]({node:!0})[r(683)](function(e){var t=r;a[t(571)](e[0][t(578)]),o(n+1)})};o(0)}else if(M){for(var c=0,s=t[r(650)];c`后台运行能力`中提供`audio`配置,不然App切到后台后立马会停止录音 +``` + + +*⠀* + +## 语音通话、回声消除、声音外放 +在App、H5中,使用[BufferStreamPlayer](https://gitee.com/xiangyuecn/Recorder/tree/master/src/extensions/buffer_stream.player.js)可以实时播放语音;其中App中需要在renderjs中加载BufferStreamPlayer,在逻辑层中调用`RecordApp.UniWebViewVueCall`等方法将逻辑层中接收到的实时语音数据发送到renderjs中播放;播放声音的同时进行录音,声音可能会被录进去产生回声,因此一般需要打开回声消除。 + +微信小程序请参考 [miniProgram-wx](https://gitee.com/xiangyuecn/Recorder/tree/master/app-support-sample/miniProgram-wx) 文档里面的同名章节,使用WebAudioContext播放。 + +配置audioTrackSet可尝试打开回声消除,或者切换听筒播放或外放,打开回声消除时,一般会转为听筒播放显著降低回声。 +``` js +//打开回声消除 +RecordApp.Start({ + ... 更多配置参数请参考RecordApp文档 + //此配置App、H5、小程序均可打开回声消除;注意:H5、App+renderjs中需要在请求录音权限前进行相同配置RecordApp.RequestPermission_H5OpenSet后此配置才会生效 + ,audioTrackSet:{echoCancellation:true,noiseSuppression:true,autoGainControl:true} + + //Android指定麦克风源(App搭配原生插件、小程序可用),0 DEFAULT 默认音频源,1 MIC 主麦克风,5 CAMCORDER 相机方向的麦,6 VOICE_RECOGNITION 语音识别,7 VOICE_COMMUNICATION 语音通信(带回声消除) + ,android_audioSource:7 //提供此配置时优先级比audioTrackSet更高,默认值为0 + + //iOS的AVAudioSession setCategory的withOptions参数值(App搭配原生插件可用),取值请参考配套原生插件文档中的iosSetDefault_categoryOptions + //,ios_categoryOptions:0x1|0x4|0x8 //0x8是外放,默认值为0x1|0x4不带0x8是听筒播放,等同于下面的setSpeakerOff +}); + +//App搭配原生插件时尝试切换听筒播放或外放 +await RecordApp.UniNativeUtsPluginCallAsync("setSpeakerOff",{off:true或false}); +//小程序尝试切换 +wx.setInnerAudioOption({ speakerOn:false或true }) +//H5不支持切换 ``` +*⠀* + +*⠀* + +*⠀* + +# 详细文档、RecordApp方法、属性文档 +请先阅读 [demo_UniApp文档](https://gitee.com/xiangyuecn/Recorder/tree/master/app-support-sample/demo_UniApp),含Demo项目;更高级使用还需深入阅读 [Recorder文档](https://gitee.com/xiangyuecn/Recorder)、[RecordApp文档](https://gitee.com/xiangyuecn/Recorder/tree/master/app-support-sample) (均为完整的一个README.md文档),Recorder文档中包含了更丰富的示例代码:基础录音、实时处理、格式转码、音频分析、音频混音、音频生成 等等,大部分能在uniapp中直接使用。 + + + + *⠀* *⠀*