import{s as e,P as a,a2 as t,a4 as s,f as l,g as o,w as n,q as u,n as c,E as r,p as i,r as d,F as p,m as v,t as f,i as h,l as m,L as y,u as _,K as g,A as w}from"./index-007bf156.js";import{_ as b}from"./s-layout.19bedb43.js";import{_ as x}from"./_plugin-vue_export-helper.1b428a4d.js";import"./phone-international-input.3617e4e0.js";import"./useGoods.ac3bf93e.js";const j=""+new URL("audioPaly-372169db.png",import.meta.url).href,M=x({__name:"speechtotext",setup(x){const{safeAreaInsets:M,safeArea:D}=e.$platform.device,k=e.$platform.navbar,I=D.height-k-20-60,T=a([]),U=a(!1);let E=a(null);const A=a("");let L=null;const P=a(0);let R=null,z=[],B=a(!1);t((()=>{navigator.mediaDevices.getUserMedia({audio:!0}).then((e=>{R=new MediaRecorder(e),R.ondataavailable=e=>{z.push(e.data)},R.onstop=()=>{B.value||C(),z=[]}})).catch((e=>{console.error("Error accessing media devices.",e)}))}));const C=()=>{const e=new Blob(z,{type:"audio/mpeg"}),a=URL.createObjectURL(e),t=Math.max(Math.floor((new Date-E.value)/1e3),1);!async function(e,a,t,s){const l=new FormData;l.append("audio_file",e);try{const e=await fetch("https://zxgz.newfeifan.cn/voice2text/",{method:"POST",body:l}),a=await e.json();a.success&&(T.value[s].transcription=a.transcription),console.log("Server response:",a)}catch(o){console.error("Error sending audio file:",o)}}(e,0,0,T.value.push({duration:t,audioUrl:a,transcription:""})-1),s((()=>{let e=document.getElementById("messages");e.scrollTop=e.scrollHeight}))},F=()=>{const e=Math.floor((new Date-E.value)/1e3);A.value=e+"s",e>=60&&S(new Event("mouseup"))},O=e=>{U.value||"mousedown"!==e.type&&"touchstart"!==e.type||(E.value=new Date,U.value=!0,L=setInterval(F,1e3),A.value="1s",e.preventDefault(),P.value=e.touches?e.touches[0].clientY:0,z=[],B.value=!1,R.start())},S=e=>{!U.value||"mouseup"!==e.type&&"touchend"!==e.type&&"mouseleave"!==e.type&&"touchcancel"!==e.type||(clearInterval(L),U.value=!1,A.value="",new Date-E.value>=500?R.stop():console.log("录音时间太短，不保存"))},Y=()=>{U.value&&(clearInterval(L),console.log("录音取消"),B.value=!0,R.stop(),$())},$=()=>{U.value=!1,A.value=0,E.value=null,z=[]},q=e=>{const a=e.touches[0].clientY;P.value-a>280&&Y()};return(e,a)=>{const t=g,s=w,x=m,M=y,D=u(_("s-layout"),b);return l(),o(D,{class:"chat-wrap",title:"语音转文字"},{default:n((()=>[c(x,{class:"chat-container"},{default:n((()=>[c(x,{class:"messages",style:r({height:I+"px"}),id:"messages"},{default:n((()=>[(l(!0),i(p,null,d(T.value,((e,a)=>(l(),o(x,{key:a,class:"message",onClick:e=>(e=>{const a=T.value[e];new Audio(a.audioUrl).play()})(a)},{default:n((()=>[c(x,{class:"bubble"},{default:n((()=>[c(t,{class:"duration"},{default:n((()=>[v(f(e.duration)+'" ',1)])),_:2},1024),c(t,{class:"ss-m-l-10"},{default:n((()=>[c(s,{src:j,class:"audioPaly"})])),_:1})])),_:2},1024),null!=e.transcription&&""!=e.transcription?(l(),o(x,{key:0,class:"text"},{default:n((()=>[v(f(e.transcription),1)])),_:2},1024)):h("",!0)])),_:2},1032,["onClick"])))),128))])),_:1},8,["style"]),c(x,{class:"input-area"},{default:n((()=>[c(M,{onMousedown:O,onMouseup:S,onMouseleave:Y,onTouchstart:O,onTouchend:S,onTouchcancel:Y,onTouchmove:q},{default:n((()=>[v(" 按住 说话 ")])),_:1}),U.value?(l(),o(x,{key:0,class:"recording-overlay"},{default:n((()=>[c(x,null,{default:n((()=>[v(f(A.value),1)])),_:1}),c(x,null,{default:n((()=>[v("上滑至此取消")])),_:1})])),_:1})):h("",!0)])),_:1})])),_:1})])),_:1})}}},[["__scopeId","data-v-d67bddcf"]]);export{M as default};
