"use strict";const e=require("../../common/vendor.js"),r=require("../../common/assets.js"),s=require("../../sheep/index.js");if(require("../../sheep/request/index.js"),require("../../sheep/url/index.js"),require("../../sheep/store/index.js"),require("../../sheep/store/app.js"),require("../../sheep/api/promotion/diy.js"),require("../../sheep/platform/index.js"),require("../../sheep/platform/provider/wechat/index.js"),require("../../sheep/platform/provider/wechat/miniProgram.js"),require("../../sheep/api/member/auth.js"),require("../../sheep/api/member/social.js"),require("../../sheep/api/member/user.js"),require("../../sheep/platform/provider/apple/index.js"),require("../../sheep/platform/share.js"),require("../../sheep/router/index.js"),require("../../sheep/hooks/useModal.js"),require("../../sheep/helper/index.js"),require("../../sheep/helper/test.js"),require("../../sheep/helper/digit.js"),require("../../sheep/api/member/signin.js"),require("../../sheep/helper/throttle.js"),require("../../sheep/platform/pay.js"),require("../../sheep/api/pay/order.js"),require("../../sheep/store/user.js"),require("../../sheep/store/cart.js"),require("../../sheep/api/trade/cart.js"),require("../../sheep/api/pay/wallet.js"),require("../../sheep/api/trade/order.js"),require("../../sheep/api/promotion/coupon.js"),require("../../sheep/store/sys.js"),require("../../sheep/store/modal.js"),require("../../sheep/config/index.js"),require("../../sheep/config/zIndex.js"),!Array){e.resolveComponent("s-layout")()}Math;const t={__name:"speechtotext",setup(t){const{safeAreaInsets:a,safeArea:o}=s.sheep.$platform.device,i=s.sheep.$platform.navbar,p=o.height-i-20-60,u=e.ref([]),n=e.ref(!1);let l=e.ref(null);const c=e.ref("");let h=null;const d=e.ref(0);let v=null,m=[],j=e.ref(!1);e.onMounted((()=>{navigator.mediaDevices.getUserMedia({audio:!0}).then((e=>{v=new MediaRecorder(e),v.ondataavailable=e=>{m.push(e.data)},v.onstop=()=>{j.value||q(),m=[]}})).catch((e=>{console.error("Error accessing media devices.",e)}))}));const q=()=>{const r=new Blob(m,{type:"audio/mpeg"}),s=URL.createObjectURL(r),t=Math.max(Math.floor((new Date-l.value)/1e3),1);!async function(e,r,s,t){const a=new FormData;a.append("audio_file",e);try{const e=await fetch("http://192.168.0.110:8000/voice2text/",{method:"POST",body:a}),r=await e.json();r.success&&(u.value[t].transcription=r.transcription),console.log("Server response:",r)}catch(o){console.error("Error sending audio file:",o)}}(r,0,0,u.value.push({duration:t,audioUrl:s,transcription:""})-1),e.nextTick$1((()=>{let e=document.getElementById("messages");e.scrollTop=e.scrollHeight}))},f=()=>{const e=Math.floor((new Date-l.value)/1e3);c.value=e+"s",e>=60&&y(new Event("mouseup"))},g=e=>{n.value||"mousedown"!==e.type&&"touchstart"!==e.type||(l.value=new Date,n.value=!0,h=setInterval(f,1e3),c.value="1s",e.preventDefault(),d.value=e.touches?e.touches[0].clientY:0,m=[],j.value=!1,v.start())},y=e=>{!n.value||"mouseup"!==e.type&&"touchend"!==e.type&&"mouseleave"!==e.type&&"touchcancel"!==e.type||(clearInterval(h),n.value=!1,c.value="",new Date-l.value>=500?v.stop():console.log("录音时间太短，不保存"))},x=()=>{n.value&&(clearInterval(h),console.log("录音取消"),j.value=!0,v.stop(),w())},w=()=>{n.value=!1,c.value=0,l.value=null,m=[]},b=e=>{const r=e.touches[0].clientY;d.value-r>280&&x()};return(s,t)=>e.e({a:e.f(u.value,((r,s,t)=>e.e({a:e.t(r.duration),b:null!=r.transcription&&""!=r.transcription},null!=r.transcription&&""!=r.transcription?{c:e.t(r.transcription)}:{},{d:s,e:e.o((e=>(e=>{const r=u.value[e];new Audio(r.audioUrl).play()})(s)),s)}))),b:r._imports_0$3,c:p+"px",d:e.o(g),e:e.o(y),f:e.o(x),g:e.o(g),h:e.o(y),i:e.o(x),j:e.o(b),k:n.value},n.value?{l:e.t(c.value)}:{},{m:e.p({title:"语音转文字"})})}},a=e._export_sfc(t,[["__scopeId","data-v-d67bddcf"]]);wx.createPage(a);
