ruiyun-human 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -605,8 +605,8 @@ const _sfc_main = {
605
605
  const dpr = window.devicePixelRatio || 1;
606
606
  const width = containerRef.value.clientWidth;
607
607
  const height = containerRef.value.clientHeight;
608
- canvas.width = width * 3 * dpr;
609
- canvas.height = height * 3 * dpr;
608
+ canvas.width = width * dpr;
609
+ canvas.height = height * dpr;
610
610
  canvas.style.width = width + "px";
611
611
  canvas.style.height = height + "px";
612
612
  ctx.value = canvas.getContext("2d");
@@ -877,7 +877,7 @@ const _sfc_main = {
877
877
  };
878
878
  }
879
879
  };
880
- const DigitalHuman = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-132811db"]]);
880
+ const DigitalHuman = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-6406e025"]]);
881
881
  DigitalHuman.install = (app) => app.component("DigitalHuman", DigitalHuman);
882
882
  const components = [DemoButton, DemoInput, DigitalHuman];
883
883
  const install = (app) => {
@@ -8,4 +8,4 @@
8
8
  * @author 2fps <echoweb@126.com> (https://www.zhuyuntao.cn)
9
9
  * @license MIT
10
10
  *
11
- */c.exports=function(e){var t={};function n(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(a,o,function(t){return e[t]}.bind(null,o));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,a){function i(e,t,a){for(var o=0;o<a.length;o++)e.setUint8(t+o,a.charCodeAt(o))}Object.defineProperty(t,"__esModule",{value:!0}),t.compress=function(e,t,a){for(var o=t/a,r=Math.max(o,1),s=e.left,l=e.right,u=Math.floor((s.length+l.length)/o),c=new Float32Array(u),f=0,v=0;f<u;){var y=Math.floor(v);c[f]=s[y],f++,l.length&&(c[f]=l[y],f++),v+=r}return c},t.encodePCM=function(e,t,a){void 0===a&&(a=!0);var o=0,r=e.length*(t/8),s=new ArrayBuffer(r),l=new DataView(s);if(8===t)for(var u=0;u<e.length;u++,o++){var c=(f=Math.max(-1,Math.min(1,e[u])))<0?128*f:127*f;c=+c+128,l.setInt8(o,c)}else for(u=0;u<e.length;u++,o+=2){var f=Math.max(-1,Math.min(1,e[u]));l.setInt16(o,f<0?32768*f:32767*f,a)}return l},t.encodeWAV=function(e,t,a,o,r,s){void 0===s&&(s=!0);var l=a>t?t:a,u=r,c=new ArrayBuffer(44+e.byteLength),f=new DataView(c),v=o,y=0;i(f,y,"RIFF"),y+=4,f.setUint32(y,36+e.byteLength,s),i(f,y+=4,"WAVE"),i(f,y+=4,"fmt "),y+=4,f.setUint32(y,16,s),y+=4,f.setUint16(y,1,s),y+=2,f.setUint16(y,v,s),y+=2,f.setUint32(y,l,s),y+=4,f.setUint32(y,v*l*(u/8),s),y+=4,f.setUint16(y,v*(u/8),s),y+=2,f.setUint16(y,u,s),i(f,y+=2,"data"),y+=4,f.setUint32(y,e.byteLength,s),y+=4;for(var g=0;g<e.byteLength;)f.setUint8(y,e.getUint8(g)),y++,g++;return f}},function(e,t,a){var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var a in t)t.hasOwnProperty(a)&&(e[a]=t[a])})(e,t)},function(e,t){function n2(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n2.prototype=t.prototype,new n2)});Object.defineProperty(t,"__esModule",{value:!0});var s=a(2),l=a(0),u=a(3),c=function(e){function e2(t){void 0===t&&(t={});var a=e.call(this,t)||this;return a.isrecording=!1,a.ispause=!1,a.isplaying=!1,a}return r(e2,e),e2.prototype.setOption=function(e){void 0===e&&(e={}),this.setNewOption(e)},e2.prototype.start=function(){return this.isrecording?Promise.reject():(this.isrecording=!0,this.startRecord())},e2.prototype.pause=function(){this.isrecording&&!this.ispause&&(this.ispause=!0,this.pauseRecord())},e2.prototype.resume=function(){this.isrecording&&this.ispause&&(this.ispause=!1,this.resumeRecord())},e2.prototype.stop=function(){this.isrecording&&(this.isrecording=!1,this.ispause=!1,this.stopRecord())},e2.prototype.play=function(){this.stop(),this.isplaying=!0,this.onplay&&this.onplay(),u.default.addPlayEnd(this.onplayend);var e=this.getWAV();e.byteLength>44&&u.default.play(e.buffer)},e2.prototype.getPlayTime=function(){return u.default.getPlayTime()},e2.prototype.pausePlay=function(){!this.isrecording&&this.isplaying&&(this.isplaying=!1,this.onpauseplay&&this.onpauseplay(),u.default.pausePlay())},e2.prototype.resumePlay=function(){this.isrecording||this.isplaying||(this.isplaying=!0,this.onresumeplay&&this.onresumeplay(),u.default.resumePlay())},e2.prototype.stopPlay=function(){this.isrecording||(this.isplaying=!1,this.onstopplay&&this.onstopplay(),u.default.stopPlay())},e2.prototype.destroy=function(){return u.default.destroyPlay(),this.destroyRecord()},e2.prototype.getRecordAnalyseData=function(){return this.getAnalyseData()},e2.prototype.getPlayAnalyseData=function(){return u.default.getAnalyseData()},e2.prototype.getPCM=function(){this.stop();var e=this.getData();return e=l.compress(e,this.inputSampleRate,this.outputSampleRate),l.encodePCM(e,this.oututSampleBits,this.littleEdian)},e2.prototype.getPCMBlob=function(){return new Blob([this.getPCM()])},e2.prototype.downloadPCM=function(e){void 0===e&&(e="recorder");var t=this.getPCMBlob();s.downloadPCM(t,e)},e2.prototype.getWAV=function(){var e=this.getPCM();return l.encodeWAV(e,this.inputSampleRate,this.outputSampleRate,this.config.numChannels,this.oututSampleBits,this.littleEdian)},e2.prototype.getWAVBlob=function(){return new Blob([this.getWAV()],{type:"audio/wav"})},e2.prototype.downloadWAV=function(e){void 0===e&&(e="recorder");var t=this.getWAVBlob();s.downloadWAV(t,e)},e2.prototype.download=function(e,t,a){s.download(e,t,a)},e2.prototype.getChannelData=function(){var e=this.getPCM(),t=e.byteLength,a=this.littleEdian,o={left:null,right:null};if(2===this.config.numChannels){var r=new DataView(new ArrayBuffer(t/2)),s=new DataView(new ArrayBuffer(t/2));if(16===this.config.sampleBits)for(var l=0;l<t/2;l+=2)r.setInt16(l,e.getInt16(2*l,a),a),s.setInt16(l,e.getInt16(2*l+2,a),a);else for(l=0;l<t/2;l+=2)r.setInt8(l,e.getInt8(2*l)),s.setInt8(l,e.getInt8(2*l+1));o.left=r,o.right=s}else o.left=e;return o},e2}(a(5).default);t.default=c},function(e,t,a){function i(e,t,a){var o=document.createElement("a");o.href=window.URL.createObjectURL(e),o.download=t+"."+a,o.click()}Object.defineProperty(t,"__esModule",{value:!0}),t.downloadWAV=function(e,t){void 0===t&&(t="recorder"),i(e,t,"wav")},t.downloadPCM=function(e,t){void 0===t&&(t="recorder"),i(e,t,"pcm")},t.download=function(e,t,a){return i(e,t,a)}},function(e,t,a){Object.defineProperty(t,"__esModule",{value:!0});var o=a(4),r=null,s=0,l=0,u=null,c=null,f=null,v=!1,y=0,p=function(){};function d(){return v=!1,u.decodeAudioData(f.slice(0),function(e){(r=u.createBufferSource()).onended=function(){v||(y=u.currentTime-l+s,p())},r.buffer=e,r.connect(c),c.connect(u.destination),r.start(0,s),l=u.currentTime},function(e){o.throwError(e)})}function h(){r&&(r.stop(),r=null)}var g=function(){function t2(){}return t2.play=function(e){return u||(u=new(window.AudioContext||window.webkitAudioContext),(c=u.createAnalyser()).fftSize=2048),this.stopPlay(),f=e,y=0,d()},t2.pausePlay=function(){h(),s+=u.currentTime-l,v=!0},t2.resumePlay=function(){return d()},t2.stopPlay=function(){s=0,f=null,h()},t2.destroyPlay=function(){this.stopPlay()},t2.getAnalyseData=function(){var e=new Uint8Array(c.frequencyBinCount);return c.getByteTimeDomainData(e),e},t2.addPlayEnd=function(e){void 0===e&&(e=function(){}),p=e},t2.getPlayTime=function(){var e=v?s:u.currentTime-l+s;return y||e},t2}();t.default=g},function(e,t,a){Object.defineProperty(t,"__esModule",{value:!0}),t.throwError=function(e){throw new Error(e)}},function(e,t,a){Object.defineProperty(t,"__esModule",{value:!0});var o=a(0),r=function(){function t2(e){void 0===e&&(e={}),this.size=0,this.lBuffer=[],this.rBuffer=[],this.tempPCM=[],this.inputSampleBits=16,this.fileSize=0,this.duration=0,this.needRecord=!0;var t,a=new(window.AudioContext||window.webkitAudioContext);this.inputSampleRate=a.sampleRate,this.setNewOption(e),this.littleEdian=(t=new ArrayBuffer(2),new DataView(t).setInt16(0,256,!0),256===new Int16Array(t)[0]),t2.initUserMedia()}return t2.prototype.setNewOption=function(e){void 0===e&&(e={}),this.config={sampleBits:~[8,16].indexOf(e.sampleBits)?e.sampleBits:16,sampleRate:~[8e3,11025,16e3,22050,24e3,44100,48e3].indexOf(e.sampleRate)?e.sampleRate:this.inputSampleRate,numChannels:~[1,2].indexOf(e.numChannels)?e.numChannels:1},this.outputSampleRate=this.config.sampleRate,this.oututSampleBits=this.config.sampleBits},t2.prototype.startRecord=function(){var e=this;return this.context&&this.destroyRecord(),this.initRecorder(),navigator.mediaDevices.getUserMedia({audio:!0}).then(function(t){e.audioInput=e.context.createMediaStreamSource(t),e.stream=t}).then(function(){e.audioInput.connect(e.analyser),e.analyser.connect(e.recorder),e.recorder.connect(e.context.destination)})},t2.prototype.pauseRecord=function(){this.needRecord=!1},t2.prototype.resumeRecord=function(){this.needRecord=!0},t2.prototype.stopRecord=function(){this.audioInput&&this.audioInput.disconnect(),this.source&&this.source.stop(),this.recorder.disconnect(),this.analyser.disconnect(),this.needRecord=!0},t2.prototype.destroyRecord=function(){return this.clearRecordStatus(),this.stopStream(),this.closeAudioContext()},t2.prototype.getAnalyseData=function(){var e=new Uint8Array(this.analyser.frequencyBinCount);return this.analyser.getByteTimeDomainData(e),e},t2.prototype.getData=function(){return this.flat()},t2.prototype.clearRecordStatus=function(){this.lBuffer.length=0,this.rBuffer.length=0,this.size=0,this.fileSize=0,this.PCM=null,this.audioInput=null,this.duration=0},t2.prototype.flat=function(){var e=null,t=new Float32Array(0);1===this.config.numChannels?e=new Float32Array(this.size):(e=new Float32Array(this.size/2),t=new Float32Array(this.size/2));for(var a=0,o=0;o<this.lBuffer.length;o++)e.set(this.lBuffer[o],a),a+=this.lBuffer[o].length;for(a=0,o=0;o<this.rBuffer.length;o++)t.set(this.rBuffer[o],a),a+=this.rBuffer[o].length;return{left:e,right:t}},t2.prototype.initRecorder=function(){var e=this;this.clearRecordStatus(),this.context=new(window.AudioContext||window.webkitAudioContext),this.analyser=this.context.createAnalyser(),this.analyser.fftSize=2048;var t=this.context.createScriptProcessor||this.context.createJavaScriptNode;this.recorder=t.apply(this.context,[4096,this.config.numChannels,this.config.numChannels]),this.recorder.onaudioprocess=function(t){if(e.needRecord){var a,o=t.inputBuffer.getChannelData(0),r=null;e.lBuffer.push(new Float32Array(o)),e.size+=o.length,2===e.config.numChannels&&(r=t.inputBuffer.getChannelData(1),e.rBuffer.push(new Float32Array(r)),e.size+=r.length),e.fileSize=Math.floor(e.size/Math.max(e.inputSampleRate/e.outputSampleRate,1))*(e.oututSampleBits/8),a=100*Math.max.apply(Math,o),e.duration+=4096/e.inputSampleRate,e.onprocess&&e.onprocess(e.duration),e.onprogress&&e.onprogress({duration:e.duration,fileSize:e.fileSize,vol:a})}}},t2.prototype.stopStream=function(){this.stream&&this.stream.getTracks&&(this.stream.getTracks().forEach(function(e){return e.stop()}),this.stream=null)},t2.prototype.closeAudioContext=function(){return this.context&&this.context.close&&"closed"!==this.context.state?this.context.close():new Promise(function(e){e()})},t2.initUserMedia=function(){void 0===navigator.mediaDevices&&(navigator.mediaDevices={}),void 0===navigator.mediaDevices.getUserMedia&&(navigator.mediaDevices.getUserMedia=function(e){var t=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia;return t?new Promise(function(a,o){t.call(navigator,e,a,o)}):Promise.reject(new Error("浏览器不支持 getUserMedia !"))})},t2.prototype.transformIntoPCM=function(e,t){var a=new Float32Array(e),r=new Float32Array(t),s=o.compress({left:a,right:r},this.inputSampleRate,this.outputSampleRate);return o.encodePCM(s,this.oututSampleBits,this.littleEdian)},t2.getPermission=function(){return this.initUserMedia(),navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){e&&e.getTracks().forEach(function(e){return e.stop()})})},t2}();t.default=r}]).default;const f=getDefaultExportFromCjs(c.exports),v=_export_sfc({__name:"index",props:{humans:{type:Array,default:()=>[]}},emits:["loaded","changed","paused","resumed","audio-ready"],setup(e,{expose:a,emit:o}){const r=e,s=o,l=t.ref(null),u=t.ref(null),c=t.ref(null),v=t.ref(null),y=t.ref(null),g=t.ref(1),m=t.ref(null),w=t.ref({standby:[],speakStart:[],speakLoop:[],speakEnd:[]}),b=t.ref("standby"),k=t.ref(1),U=t.ref(!1),x=t.ref(null),draw=e=>{if(!c.value||!e||e.width<=0||e.height<=0)return;const t=u.value;c.value.clearRect(0,0,t.width,t.height);const a=Math.min(t.width/e.width,t.height/e.height),o=e.width*a,r=e.height*a,s=(t.width-o)/2,l=(t.height-r)/2;c.value.drawImage(e,s,l,o,r)},stop=()=>{y.value&&(cancelAnimationFrame(y.value),y.value=null),g.value=1,b.value="standby"},runAnimation=e=>{let t,a;stop(),b.value=e,k.value=1;let o=null;switch(e){case"standby":t=w.value.standby,a=v.value.standby.interval,o={type:"pingpong",next:"standby"};break;case"speak":t=w.value.speakStart,a=v.value.speak.interval,o={type:"once",next:"speakLoop"};break;case"speakLoop":t=w.value.speakLoop,a=v.value.speak.interval,o={type:"pingpong",next:"speakLoop"};break;case"speakEnd":t=w.value.speakEnd,a=v.value.speak.interval,o={type:"once",next:"standby"};break;default:return}const animate=e=>{if(m.value||(m.value=e),U.value)y.value=requestAnimationFrame(animate);else{if(e-m.value>=a){if(o&&"pingpong"===o.type){const e=g.value+k.value;e>t.length?k.value=-1:e<1&&(k.value=1)}draw(t[g.value-1]);if(o?"once"===o.type?(g.value++,!(g.value<=t.length||("standby"===o.next?(standby(),0):("speakLoop"===o.next&&(g.value=1,t=w.value.speakLoop,o={type:"pingpong",next:"speakLoop"}),1)))):("pingpong"===o.type&&(g.value+=k.value),!1):(g.value=g.value>=t.length?1:g.value+1,!1))return;m.value=e}y.value=requestAnimationFrame(animate)}};y.value=requestAnimationFrame(animate)},standby=()=>{runAnimation("standby")},speak=()=>{runAnimation("speak")},stopSpeaking=()=>{"speak"===b.value||"speakLoop"===b.value?runAnimation("speakEnd"):standby()},init=()=>{t.nextTick(()=>{if(!l.value||!u.value)return;if(!r.humans||0===r.humans.length)return;v.value||(v.value=r.humans[0]);const e=u.value,t=window.devicePixelRatio||1,a=l.value.clientWidth,o=l.value.clientHeight;e.width=3*a*t,e.height=3*o*t,e.style.width=a+"px",e.style.height=o+"px",c.value=e.getContext("2d"),c.value.scale(t,t),(()=>{w.value={standby:[],speakStart:[],speakLoop:[],speakEnd:[]};const e=v.value.folder,{standbyNum:t,speakNum:a}={standbyNum:v.value.standby.standbyNum,speakNum:v.value.speak.speakNum};for(let s=1;s<=t;s++){const t=new Image;t.src=encodeURI(`${e}/standby/standby (${s}).png`),w.value.standby.push(t)}const o=Math.floor(.6*a),r=Math.floor(.9*a);for(let s=1;s<=o;s++){const t=new Image;t.src=encodeURI(`${e}/speak/speak (${s}).png`),w.value.speakStart.push(t)}for(let s=o;s<=r;s++){const t=new Image;t.src=encodeURI(`${e}/speak/speak (${s}).png`),w.value.speakLoop.push(t)}for(let s=r;s<=a;s++){const t=new Image;t.src=encodeURI(`${e}/speak/speak (${s}).png`),w.value.speakEnd.push(t)}})(),(e=>{let t=0;const a=[...w.value.standby,...w.value.speakStart,...w.value.speakLoop,...w.value.speakEnd],checkLoaded=()=>{t++,t>=a.length&&e()};a.forEach(e=>{e.complete?checkLoaded():(e.onload=checkLoaded,e.onerror=checkLoaded)})})(()=>{draw(w.value.standby[0]),s("loaded",v.value)})})},A=t.ref(null),R=t.ref(null),audioToText=async e=>{var t;const a=new FormData;a.append("file",e,"recorded_audio.wav");try{const e=await fetch("http://192.168.3.182:9988/transcribe",{method:"POST",body:a});(null==(t=e.data)?void 0:t.text)||e.text}catch(o){}},createWavBlob=(e,t,a,o)=>{const r=a*(o/8),s=e.byteLength,l=new ArrayBuffer(44+s),u=new DataView(l);u.setUint8(0,82),u.setUint8(1,73),u.setUint8(2,70),u.setUint8(3,70),u.setUint32(4,36+s,!0),u.setUint8(8,87),u.setUint8(9,65),u.setUint8(10,86),u.setUint8(11,69),u.setUint8(12,102),u.setUint8(13,109),u.setUint8(14,116),u.setUint8(15,32),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,a,!0),u.setUint32(24,t,!0),u.setUint32(28,t*r,!0),u.setUint16(32,r,!0),u.setUint16(34,o,!0),u.setUint8(36,100),u.setUint8(37,97),u.setUint8(38,116),u.setUint8(39,97),u.setUint32(40,s,!0);const c=new Uint8Array(e);return new Uint8Array(l,44).set(c),new Blob([l],{type:"audio/wav"})};let S=t.ref(null);return a({standby:standby,speak:speak,stopSpeaking:stopSpeaking,pause:()=>{U.value||(U.value=!0,x.value={state:b.value,frameIndex:g.value,loopDirection:k.value},s("paused"))},resume:()=>{U.value&&(U.value=!1,m.value=null,x.value&&(b.value=x.value.state,g.value=x.value.frameIndex,k.value=x.value.loopDirection),s("resumed"))},playTTS:async e=>{var t,a,o,r,s,l,u,c;if(!e||!(null==(t=v.value)?void 0:t.isMuted))return;A.value&&(A.value.pause(),A.value=null),R.value=Date.now();const f=R.value;try{const t=e.replace(/```[\s\S]*?```/g,"").replace(/`[^`]+`/g,"").replace(/[#*_~]/g,"").replace(/\n+/g,",").replace(/\s+/g," ").replace(/[,。!?]{2,}/g,",").trim();if(!t)return;const g="http://192.168.3.182:8002",m="session_"+Date.now();let w=(null==(o=null==(a=v.value)?void 0:a.speakSet)?void 0:o.speed)||1,b=(null==(s=null==(r=v.value)?void 0:r.speakSet)?void 0:s.age)||"Young Adult / 青年";const k=[t,"Auto",32,2,!0,w,null,!0,!0,(null==(u=null==(l=v.value)?void 0:l.speakSet)?void 0:u.sex)||"Female / 女",b,"Auto","Auto","Auto","Auto"],U=await fetch(`${g}/gradio_api/queue/join`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:k,session_hash:m,fn_index:1,trigger_id:50})});await U.json();let x="",S=60,_=1e3;for(;!x&&S>0;){await new Promise(e=>setTimeout(e,_)),S--;try{const e=await fetch(`${g}/gradio_api/queue/data?session_hash=${m}`),t=(await e.text()).split("\n");for(const a of t){const e=a.trim();if(e.startsWith("data: "))try{const t=JSON.parse(e.replace("data: ",""));if("process_completed"===t.msg&&(null==(c=t.output)?void 0:c.data)){const e=t.output.data[0];if(null==e?void 0:e.url)x=e.url;else if(null==e?void 0:e.path)x=`${g}/gradio_api/file=${e.path}`;else if("string"==typeof e)x=e.startsWith("http")?e:`${g}/gradio_api/file=${e}`;else if(Array.isArray(e)&&e.length>=2){const t=e[0],a=e[1];if(t&&a&&Array.isArray(a)){const e=new ArrayBuffer(2*a.length),o=new DataView(e);for(let t=0;t<a.length;t++)o.setInt16(2*t,a[t],!0);const r=createWavBlob(e,t,1,16),s=URL.createObjectURL(r);return R.value!==f?void URL.revokeObjectURL(s):(A.value=new Audio(s),A.value.onplaying=()=>{speak()},A.value.onended=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(s)},A.value.onerror=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(s)},void(await A.value.play()))}}break}if("process_error"===t.msg)return void standby()}catch(y){}}}catch(y){}}if(x){if(x.startsWith("/")&&(x=g+x),R.value!==f)return;const e=await fetch(x),t=await e.blob(),a=URL.createObjectURL(t);A.value=new Audio(a),A.value.onplaying=()=>{speak()},A.value.onended=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(a)},A.value.onerror=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(a)},await A.value.play()}else standby()}catch(y){standby()}},startRecord:async()=>{try{S.value&&S.value.stop(),await S.value.start()}catch(e){}},stopRecord:async()=>{if(S.value)try{S.value.stop();const e=S.value.getWAVBlob();if(e.size<1e3)return;const t=await audioToText(e);s("audio-ready",t)}catch(e){}}}),t.watch(()=>r.humans,e=>{e&&e.length>0&&!v.value&&init()},{deep:!0}),t.onMounted(()=>{S.value||(S.value=new f({sampleBits:16,sampleRate:16e3,numChannels:1})),init()}),t.onUnmounted(()=>{stop(),S.value&&S.value.stop()}),(e,a)=>(t.openBlock(),t.createElementBlock("div",{class:"digital-human",ref_key:"containerRef",ref:l},[t.createElementVNode("canvas",{ref_key:"canvasRef",ref:u},null,512)],512))}},[["__scopeId","data-v-132811db"]]);v.install=e=>e.component("DigitalHuman",v);const y=[a,u,v],g={install:e=>{y.forEach(t=>e.use(t))}};e.DemoButton=a,e.DemoInput=u,e.DigitalHuman=v,e.default=g,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
11
+ */c.exports=function(e){var t={};function n(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(a,o,function(t){return e[t]}.bind(null,o));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,a){function i(e,t,a){for(var o=0;o<a.length;o++)e.setUint8(t+o,a.charCodeAt(o))}Object.defineProperty(t,"__esModule",{value:!0}),t.compress=function(e,t,a){for(var o=t/a,r=Math.max(o,1),s=e.left,l=e.right,u=Math.floor((s.length+l.length)/o),c=new Float32Array(u),f=0,v=0;f<u;){var y=Math.floor(v);c[f]=s[y],f++,l.length&&(c[f]=l[y],f++),v+=r}return c},t.encodePCM=function(e,t,a){void 0===a&&(a=!0);var o=0,r=e.length*(t/8),s=new ArrayBuffer(r),l=new DataView(s);if(8===t)for(var u=0;u<e.length;u++,o++){var c=(f=Math.max(-1,Math.min(1,e[u])))<0?128*f:127*f;c=+c+128,l.setInt8(o,c)}else for(u=0;u<e.length;u++,o+=2){var f=Math.max(-1,Math.min(1,e[u]));l.setInt16(o,f<0?32768*f:32767*f,a)}return l},t.encodeWAV=function(e,t,a,o,r,s){void 0===s&&(s=!0);var l=a>t?t:a,u=r,c=new ArrayBuffer(44+e.byteLength),f=new DataView(c),v=o,y=0;i(f,y,"RIFF"),y+=4,f.setUint32(y,36+e.byteLength,s),i(f,y+=4,"WAVE"),i(f,y+=4,"fmt "),y+=4,f.setUint32(y,16,s),y+=4,f.setUint16(y,1,s),y+=2,f.setUint16(y,v,s),y+=2,f.setUint32(y,l,s),y+=4,f.setUint32(y,v*l*(u/8),s),y+=4,f.setUint16(y,v*(u/8),s),y+=2,f.setUint16(y,u,s),i(f,y+=2,"data"),y+=4,f.setUint32(y,e.byteLength,s),y+=4;for(var g=0;g<e.byteLength;)f.setUint8(y,e.getUint8(g)),y++,g++;return f}},function(e,t,a){var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var a in t)t.hasOwnProperty(a)&&(e[a]=t[a])})(e,t)},function(e,t){function n2(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n2.prototype=t.prototype,new n2)});Object.defineProperty(t,"__esModule",{value:!0});var s=a(2),l=a(0),u=a(3),c=function(e){function e2(t){void 0===t&&(t={});var a=e.call(this,t)||this;return a.isrecording=!1,a.ispause=!1,a.isplaying=!1,a}return r(e2,e),e2.prototype.setOption=function(e){void 0===e&&(e={}),this.setNewOption(e)},e2.prototype.start=function(){return this.isrecording?Promise.reject():(this.isrecording=!0,this.startRecord())},e2.prototype.pause=function(){this.isrecording&&!this.ispause&&(this.ispause=!0,this.pauseRecord())},e2.prototype.resume=function(){this.isrecording&&this.ispause&&(this.ispause=!1,this.resumeRecord())},e2.prototype.stop=function(){this.isrecording&&(this.isrecording=!1,this.ispause=!1,this.stopRecord())},e2.prototype.play=function(){this.stop(),this.isplaying=!0,this.onplay&&this.onplay(),u.default.addPlayEnd(this.onplayend);var e=this.getWAV();e.byteLength>44&&u.default.play(e.buffer)},e2.prototype.getPlayTime=function(){return u.default.getPlayTime()},e2.prototype.pausePlay=function(){!this.isrecording&&this.isplaying&&(this.isplaying=!1,this.onpauseplay&&this.onpauseplay(),u.default.pausePlay())},e2.prototype.resumePlay=function(){this.isrecording||this.isplaying||(this.isplaying=!0,this.onresumeplay&&this.onresumeplay(),u.default.resumePlay())},e2.prototype.stopPlay=function(){this.isrecording||(this.isplaying=!1,this.onstopplay&&this.onstopplay(),u.default.stopPlay())},e2.prototype.destroy=function(){return u.default.destroyPlay(),this.destroyRecord()},e2.prototype.getRecordAnalyseData=function(){return this.getAnalyseData()},e2.prototype.getPlayAnalyseData=function(){return u.default.getAnalyseData()},e2.prototype.getPCM=function(){this.stop();var e=this.getData();return e=l.compress(e,this.inputSampleRate,this.outputSampleRate),l.encodePCM(e,this.oututSampleBits,this.littleEdian)},e2.prototype.getPCMBlob=function(){return new Blob([this.getPCM()])},e2.prototype.downloadPCM=function(e){void 0===e&&(e="recorder");var t=this.getPCMBlob();s.downloadPCM(t,e)},e2.prototype.getWAV=function(){var e=this.getPCM();return l.encodeWAV(e,this.inputSampleRate,this.outputSampleRate,this.config.numChannels,this.oututSampleBits,this.littleEdian)},e2.prototype.getWAVBlob=function(){return new Blob([this.getWAV()],{type:"audio/wav"})},e2.prototype.downloadWAV=function(e){void 0===e&&(e="recorder");var t=this.getWAVBlob();s.downloadWAV(t,e)},e2.prototype.download=function(e,t,a){s.download(e,t,a)},e2.prototype.getChannelData=function(){var e=this.getPCM(),t=e.byteLength,a=this.littleEdian,o={left:null,right:null};if(2===this.config.numChannels){var r=new DataView(new ArrayBuffer(t/2)),s=new DataView(new ArrayBuffer(t/2));if(16===this.config.sampleBits)for(var l=0;l<t/2;l+=2)r.setInt16(l,e.getInt16(2*l,a),a),s.setInt16(l,e.getInt16(2*l+2,a),a);else for(l=0;l<t/2;l+=2)r.setInt8(l,e.getInt8(2*l)),s.setInt8(l,e.getInt8(2*l+1));o.left=r,o.right=s}else o.left=e;return o},e2}(a(5).default);t.default=c},function(e,t,a){function i(e,t,a){var o=document.createElement("a");o.href=window.URL.createObjectURL(e),o.download=t+"."+a,o.click()}Object.defineProperty(t,"__esModule",{value:!0}),t.downloadWAV=function(e,t){void 0===t&&(t="recorder"),i(e,t,"wav")},t.downloadPCM=function(e,t){void 0===t&&(t="recorder"),i(e,t,"pcm")},t.download=function(e,t,a){return i(e,t,a)}},function(e,t,a){Object.defineProperty(t,"__esModule",{value:!0});var o=a(4),r=null,s=0,l=0,u=null,c=null,f=null,v=!1,y=0,p=function(){};function d(){return v=!1,u.decodeAudioData(f.slice(0),function(e){(r=u.createBufferSource()).onended=function(){v||(y=u.currentTime-l+s,p())},r.buffer=e,r.connect(c),c.connect(u.destination),r.start(0,s),l=u.currentTime},function(e){o.throwError(e)})}function h(){r&&(r.stop(),r=null)}var g=function(){function t2(){}return t2.play=function(e){return u||(u=new(window.AudioContext||window.webkitAudioContext),(c=u.createAnalyser()).fftSize=2048),this.stopPlay(),f=e,y=0,d()},t2.pausePlay=function(){h(),s+=u.currentTime-l,v=!0},t2.resumePlay=function(){return d()},t2.stopPlay=function(){s=0,f=null,h()},t2.destroyPlay=function(){this.stopPlay()},t2.getAnalyseData=function(){var e=new Uint8Array(c.frequencyBinCount);return c.getByteTimeDomainData(e),e},t2.addPlayEnd=function(e){void 0===e&&(e=function(){}),p=e},t2.getPlayTime=function(){var e=v?s:u.currentTime-l+s;return y||e},t2}();t.default=g},function(e,t,a){Object.defineProperty(t,"__esModule",{value:!0}),t.throwError=function(e){throw new Error(e)}},function(e,t,a){Object.defineProperty(t,"__esModule",{value:!0});var o=a(0),r=function(){function t2(e){void 0===e&&(e={}),this.size=0,this.lBuffer=[],this.rBuffer=[],this.tempPCM=[],this.inputSampleBits=16,this.fileSize=0,this.duration=0,this.needRecord=!0;var t,a=new(window.AudioContext||window.webkitAudioContext);this.inputSampleRate=a.sampleRate,this.setNewOption(e),this.littleEdian=(t=new ArrayBuffer(2),new DataView(t).setInt16(0,256,!0),256===new Int16Array(t)[0]),t2.initUserMedia()}return t2.prototype.setNewOption=function(e){void 0===e&&(e={}),this.config={sampleBits:~[8,16].indexOf(e.sampleBits)?e.sampleBits:16,sampleRate:~[8e3,11025,16e3,22050,24e3,44100,48e3].indexOf(e.sampleRate)?e.sampleRate:this.inputSampleRate,numChannels:~[1,2].indexOf(e.numChannels)?e.numChannels:1},this.outputSampleRate=this.config.sampleRate,this.oututSampleBits=this.config.sampleBits},t2.prototype.startRecord=function(){var e=this;return this.context&&this.destroyRecord(),this.initRecorder(),navigator.mediaDevices.getUserMedia({audio:!0}).then(function(t){e.audioInput=e.context.createMediaStreamSource(t),e.stream=t}).then(function(){e.audioInput.connect(e.analyser),e.analyser.connect(e.recorder),e.recorder.connect(e.context.destination)})},t2.prototype.pauseRecord=function(){this.needRecord=!1},t2.prototype.resumeRecord=function(){this.needRecord=!0},t2.prototype.stopRecord=function(){this.audioInput&&this.audioInput.disconnect(),this.source&&this.source.stop(),this.recorder.disconnect(),this.analyser.disconnect(),this.needRecord=!0},t2.prototype.destroyRecord=function(){return this.clearRecordStatus(),this.stopStream(),this.closeAudioContext()},t2.prototype.getAnalyseData=function(){var e=new Uint8Array(this.analyser.frequencyBinCount);return this.analyser.getByteTimeDomainData(e),e},t2.prototype.getData=function(){return this.flat()},t2.prototype.clearRecordStatus=function(){this.lBuffer.length=0,this.rBuffer.length=0,this.size=0,this.fileSize=0,this.PCM=null,this.audioInput=null,this.duration=0},t2.prototype.flat=function(){var e=null,t=new Float32Array(0);1===this.config.numChannels?e=new Float32Array(this.size):(e=new Float32Array(this.size/2),t=new Float32Array(this.size/2));for(var a=0,o=0;o<this.lBuffer.length;o++)e.set(this.lBuffer[o],a),a+=this.lBuffer[o].length;for(a=0,o=0;o<this.rBuffer.length;o++)t.set(this.rBuffer[o],a),a+=this.rBuffer[o].length;return{left:e,right:t}},t2.prototype.initRecorder=function(){var e=this;this.clearRecordStatus(),this.context=new(window.AudioContext||window.webkitAudioContext),this.analyser=this.context.createAnalyser(),this.analyser.fftSize=2048;var t=this.context.createScriptProcessor||this.context.createJavaScriptNode;this.recorder=t.apply(this.context,[4096,this.config.numChannels,this.config.numChannels]),this.recorder.onaudioprocess=function(t){if(e.needRecord){var a,o=t.inputBuffer.getChannelData(0),r=null;e.lBuffer.push(new Float32Array(o)),e.size+=o.length,2===e.config.numChannels&&(r=t.inputBuffer.getChannelData(1),e.rBuffer.push(new Float32Array(r)),e.size+=r.length),e.fileSize=Math.floor(e.size/Math.max(e.inputSampleRate/e.outputSampleRate,1))*(e.oututSampleBits/8),a=100*Math.max.apply(Math,o),e.duration+=4096/e.inputSampleRate,e.onprocess&&e.onprocess(e.duration),e.onprogress&&e.onprogress({duration:e.duration,fileSize:e.fileSize,vol:a})}}},t2.prototype.stopStream=function(){this.stream&&this.stream.getTracks&&(this.stream.getTracks().forEach(function(e){return e.stop()}),this.stream=null)},t2.prototype.closeAudioContext=function(){return this.context&&this.context.close&&"closed"!==this.context.state?this.context.close():new Promise(function(e){e()})},t2.initUserMedia=function(){void 0===navigator.mediaDevices&&(navigator.mediaDevices={}),void 0===navigator.mediaDevices.getUserMedia&&(navigator.mediaDevices.getUserMedia=function(e){var t=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia;return t?new Promise(function(a,o){t.call(navigator,e,a,o)}):Promise.reject(new Error("浏览器不支持 getUserMedia !"))})},t2.prototype.transformIntoPCM=function(e,t){var a=new Float32Array(e),r=new Float32Array(t),s=o.compress({left:a,right:r},this.inputSampleRate,this.outputSampleRate);return o.encodePCM(s,this.oututSampleBits,this.littleEdian)},t2.getPermission=function(){return this.initUserMedia(),navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){e&&e.getTracks().forEach(function(e){return e.stop()})})},t2}();t.default=r}]).default;const f=getDefaultExportFromCjs(c.exports),v=_export_sfc({__name:"index",props:{humans:{type:Array,default:()=>[]}},emits:["loaded","changed","paused","resumed","audio-ready"],setup(e,{expose:a,emit:o}){const r=e,s=o,l=t.ref(null),u=t.ref(null),c=t.ref(null),v=t.ref(null),y=t.ref(null),g=t.ref(1),m=t.ref(null),w=t.ref({standby:[],speakStart:[],speakLoop:[],speakEnd:[]}),b=t.ref("standby"),k=t.ref(1),U=t.ref(!1),x=t.ref(null),draw=e=>{if(!c.value||!e||e.width<=0||e.height<=0)return;const t=u.value;c.value.clearRect(0,0,t.width,t.height);const a=Math.min(t.width/e.width,t.height/e.height),o=e.width*a,r=e.height*a,s=(t.width-o)/2,l=(t.height-r)/2;c.value.drawImage(e,s,l,o,r)},stop=()=>{y.value&&(cancelAnimationFrame(y.value),y.value=null),g.value=1,b.value="standby"},runAnimation=e=>{let t,a;stop(),b.value=e,k.value=1;let o=null;switch(e){case"standby":t=w.value.standby,a=v.value.standby.interval,o={type:"pingpong",next:"standby"};break;case"speak":t=w.value.speakStart,a=v.value.speak.interval,o={type:"once",next:"speakLoop"};break;case"speakLoop":t=w.value.speakLoop,a=v.value.speak.interval,o={type:"pingpong",next:"speakLoop"};break;case"speakEnd":t=w.value.speakEnd,a=v.value.speak.interval,o={type:"once",next:"standby"};break;default:return}const animate=e=>{if(m.value||(m.value=e),U.value)y.value=requestAnimationFrame(animate);else{if(e-m.value>=a){if(o&&"pingpong"===o.type){const e=g.value+k.value;e>t.length?k.value=-1:e<1&&(k.value=1)}draw(t[g.value-1]);if(o?"once"===o.type?(g.value++,!(g.value<=t.length||("standby"===o.next?(standby(),0):("speakLoop"===o.next&&(g.value=1,t=w.value.speakLoop,o={type:"pingpong",next:"speakLoop"}),1)))):("pingpong"===o.type&&(g.value+=k.value),!1):(g.value=g.value>=t.length?1:g.value+1,!1))return;m.value=e}y.value=requestAnimationFrame(animate)}};y.value=requestAnimationFrame(animate)},standby=()=>{runAnimation("standby")},speak=()=>{runAnimation("speak")},stopSpeaking=()=>{"speak"===b.value||"speakLoop"===b.value?runAnimation("speakEnd"):standby()},init=()=>{t.nextTick(()=>{if(!l.value||!u.value)return;if(!r.humans||0===r.humans.length)return;v.value||(v.value=r.humans[0]);const e=u.value,t=window.devicePixelRatio||1,a=l.value.clientWidth,o=l.value.clientHeight;e.width=a*t,e.height=o*t,e.style.width=a+"px",e.style.height=o+"px",c.value=e.getContext("2d"),c.value.scale(t,t),(()=>{w.value={standby:[],speakStart:[],speakLoop:[],speakEnd:[]};const e=v.value.folder,{standbyNum:t,speakNum:a}={standbyNum:v.value.standby.standbyNum,speakNum:v.value.speak.speakNum};for(let s=1;s<=t;s++){const t=new Image;t.src=encodeURI(`${e}/standby/standby (${s}).png`),w.value.standby.push(t)}const o=Math.floor(.6*a),r=Math.floor(.9*a);for(let s=1;s<=o;s++){const t=new Image;t.src=encodeURI(`${e}/speak/speak (${s}).png`),w.value.speakStart.push(t)}for(let s=o;s<=r;s++){const t=new Image;t.src=encodeURI(`${e}/speak/speak (${s}).png`),w.value.speakLoop.push(t)}for(let s=r;s<=a;s++){const t=new Image;t.src=encodeURI(`${e}/speak/speak (${s}).png`),w.value.speakEnd.push(t)}})(),(e=>{let t=0;const a=[...w.value.standby,...w.value.speakStart,...w.value.speakLoop,...w.value.speakEnd],checkLoaded=()=>{t++,t>=a.length&&e()};a.forEach(e=>{e.complete?checkLoaded():(e.onload=checkLoaded,e.onerror=checkLoaded)})})(()=>{draw(w.value.standby[0]),s("loaded",v.value)})})},A=t.ref(null),R=t.ref(null),audioToText=async e=>{var t;const a=new FormData;a.append("file",e,"recorded_audio.wav");try{const e=await fetch("http://192.168.3.182:9988/transcribe",{method:"POST",body:a});(null==(t=e.data)?void 0:t.text)||e.text}catch(o){}},createWavBlob=(e,t,a,o)=>{const r=a*(o/8),s=e.byteLength,l=new ArrayBuffer(44+s),u=new DataView(l);u.setUint8(0,82),u.setUint8(1,73),u.setUint8(2,70),u.setUint8(3,70),u.setUint32(4,36+s,!0),u.setUint8(8,87),u.setUint8(9,65),u.setUint8(10,86),u.setUint8(11,69),u.setUint8(12,102),u.setUint8(13,109),u.setUint8(14,116),u.setUint8(15,32),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,a,!0),u.setUint32(24,t,!0),u.setUint32(28,t*r,!0),u.setUint16(32,r,!0),u.setUint16(34,o,!0),u.setUint8(36,100),u.setUint8(37,97),u.setUint8(38,116),u.setUint8(39,97),u.setUint32(40,s,!0);const c=new Uint8Array(e);return new Uint8Array(l,44).set(c),new Blob([l],{type:"audio/wav"})};let S=t.ref(null);return a({standby:standby,speak:speak,stopSpeaking:stopSpeaking,pause:()=>{U.value||(U.value=!0,x.value={state:b.value,frameIndex:g.value,loopDirection:k.value},s("paused"))},resume:()=>{U.value&&(U.value=!1,m.value=null,x.value&&(b.value=x.value.state,g.value=x.value.frameIndex,k.value=x.value.loopDirection),s("resumed"))},playTTS:async e=>{var t,a,o,r,s,l,u,c;if(!e||!(null==(t=v.value)?void 0:t.isMuted))return;A.value&&(A.value.pause(),A.value=null),R.value=Date.now();const f=R.value;try{const t=e.replace(/```[\s\S]*?```/g,"").replace(/`[^`]+`/g,"").replace(/[#*_~]/g,"").replace(/\n+/g,",").replace(/\s+/g," ").replace(/[,。!?]{2,}/g,",").trim();if(!t)return;const g="http://192.168.3.182:8002",m="session_"+Date.now();let w=(null==(o=null==(a=v.value)?void 0:a.speakSet)?void 0:o.speed)||1,b=(null==(s=null==(r=v.value)?void 0:r.speakSet)?void 0:s.age)||"Young Adult / 青年";const k=[t,"Auto",32,2,!0,w,null,!0,!0,(null==(u=null==(l=v.value)?void 0:l.speakSet)?void 0:u.sex)||"Female / 女",b,"Auto","Auto","Auto","Auto"],U=await fetch(`${g}/gradio_api/queue/join`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:k,session_hash:m,fn_index:1,trigger_id:50})});await U.json();let x="",S=60,_=1e3;for(;!x&&S>0;){await new Promise(e=>setTimeout(e,_)),S--;try{const e=await fetch(`${g}/gradio_api/queue/data?session_hash=${m}`),t=(await e.text()).split("\n");for(const a of t){const e=a.trim();if(e.startsWith("data: "))try{const t=JSON.parse(e.replace("data: ",""));if("process_completed"===t.msg&&(null==(c=t.output)?void 0:c.data)){const e=t.output.data[0];if(null==e?void 0:e.url)x=e.url;else if(null==e?void 0:e.path)x=`${g}/gradio_api/file=${e.path}`;else if("string"==typeof e)x=e.startsWith("http")?e:`${g}/gradio_api/file=${e}`;else if(Array.isArray(e)&&e.length>=2){const t=e[0],a=e[1];if(t&&a&&Array.isArray(a)){const e=new ArrayBuffer(2*a.length),o=new DataView(e);for(let t=0;t<a.length;t++)o.setInt16(2*t,a[t],!0);const r=createWavBlob(e,t,1,16),s=URL.createObjectURL(r);return R.value!==f?void URL.revokeObjectURL(s):(A.value=new Audio(s),A.value.onplaying=()=>{speak()},A.value.onended=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(s)},A.value.onerror=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(s)},void(await A.value.play()))}}break}if("process_error"===t.msg)return void standby()}catch(y){}}}catch(y){}}if(x){if(x.startsWith("/")&&(x=g+x),R.value!==f)return;const e=await fetch(x),t=await e.blob(),a=URL.createObjectURL(t);A.value=new Audio(a),A.value.onplaying=()=>{speak()},A.value.onended=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(a)},A.value.onerror=()=>{stopSpeaking(),A.value=null,URL.revokeObjectURL(a)},await A.value.play()}else standby()}catch(y){standby()}},startRecord:async()=>{try{S.value&&S.value.stop(),await S.value.start()}catch(e){}},stopRecord:async()=>{if(S.value)try{S.value.stop();const e=S.value.getWAVBlob();if(e.size<1e3)return;const t=await audioToText(e);s("audio-ready",t)}catch(e){}}}),t.watch(()=>r.humans,e=>{e&&e.length>0&&!v.value&&init()},{deep:!0}),t.onMounted(()=>{S.value||(S.value=new f({sampleBits:16,sampleRate:16e3,numChannels:1})),init()}),t.onUnmounted(()=>{stop(),S.value&&S.value.stop()}),(e,a)=>(t.openBlock(),t.createElementBlock("div",{class:"digital-human",ref_key:"containerRef",ref:l},[t.createElementVNode("canvas",{ref_key:"canvasRef",ref:u},null,512)],512))}},[["__scopeId","data-v-6406e025"]]);v.install=e=>e.component("DigitalHuman",v);const y=[a,u,v],g={install:e=>{y.forEach(t=>e.use(t))}};e.DemoButton=a,e.DemoInput=u,e.DigitalHuman=v,e.default=g,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .demo-btn[data-v-9a48516a]{padding:6px 14px;border-radius:4px;border:none;cursor:pointer;font-size:14px}.primary[data-v-9a48516a]{background:#409eff;color:#fff}.success[data-v-9a48516a]{background:#67c23a;color:#fff}.warning[data-v-9a48516a]{background:#e6a23c;color:#fff}.demo-input-wrap[data-v-28a3493c]{display:inline-flex;align-items:center;border:1px solid #dcdcdc;border-radius:4px;padding:0 10px}.demo-input-wrap[data-v-28a3493c]:focus-within{border-color:#409eff}.demo-input[data-v-28a3493c]{border:none;outline:none;padding:8px 6px;flex:1}.prefix[data-v-28a3493c],.suffix[data-v-28a3493c]{color:#909399}.digital-human[data-v-132811db]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.digital-human canvas[data-v-132811db]{max-width:100%;max-height:100%}
1
+ .demo-btn[data-v-9a48516a]{padding:6px 14px;border-radius:4px;border:none;cursor:pointer;font-size:14px}.primary[data-v-9a48516a]{background:#409eff;color:#fff}.success[data-v-9a48516a]{background:#67c23a;color:#fff}.warning[data-v-9a48516a]{background:#e6a23c;color:#fff}.demo-input-wrap[data-v-28a3493c]{display:inline-flex;align-items:center;border:1px solid #dcdcdc;border-radius:4px;padding:0 10px}.demo-input-wrap[data-v-28a3493c]:focus-within{border-color:#409eff}.demo-input[data-v-28a3493c]{border:none;outline:none;padding:8px 6px;flex:1}.prefix[data-v-28a3493c],.suffix[data-v-28a3493c]{color:#909399}.digital-human[data-v-6406e025]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.digital-human canvas[data-v-6406e025]{max-width:100%;max-height:100%}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruiyun-human",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "数字人初步实现",
6
6
  "main": "./dist/ruiyun-human.umd.js",
Binary file