1 |
- import{s as e,K as a,X as t,Y as s,e as l,f as o,w as n,l as u,j as c,A as r,k as i,r as d,F as p,t as v,u as h,g as m,i as f,G as y,m as _,E as g,x as w}from"./index-b48a414d.js";import{_ as b}from"./s-layout.d6dcdc81.js";import{_ as x}from"./_plugin-vue_export-helper.1b428a4d.js";import"./phone-international-input.feef99c7.js";const M=""+new URL("audioPaly-372169db.png",import.meta.url).href,j=x({__name:"speechtotext",setup(x){const{safeAreaInsets:j,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 R=null;const L=a(0);let P=null,Y=[],B=a(!1);t((()=>{navigator.mediaDevices.getUserMedia({audio:!0}).then((e=>{P=new MediaRecorder(e),P.ondataavailable=e=>{Y.push(e.data)},P.onstop=()=>{B.value||C(),Y=[]}})).catch((e=>{console.error("Error accessing media devices.",e)}))}));const C=()=>{const e=new Blob(Y,{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://letcgo.com/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,R=setInterval(F,1e3),A.value="1s",e.preventDefault(),L.value=e.touches?e.touches[0].clientY:0,Y=[],B.value=!1,P.start())},S=e=>{!U.value||"mouseup"!==e.type&&"touchend"!==e.type&&"mouseleave"!==e.type&&"touchcancel"!==e.type||(clearInterval(R),U.value=!1,A.value="",new Date-E.value>=500?P.stop():console.log("录音时间太短,不保存"))},$=()=>{U.value&&(clearInterval(R),console.log("录音取消"),B.value=!0,P.stop(),G())},G=()=>{U.value=!1,A.value=0,E.value=null,Y=[]},H=e=>{const a=e.touches[0].clientY;L.value-a>280&&$()};return(e,a)=>{const t=g,s=w,x=f,j=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(h(e.duration)+'" ',1)])),_:2},1024),c(t,{class:"ss-m-l-10"},{default:n((()=>[c(s,{src:M,class:"audioPaly"})])),_:1})])),_:2},1024),null!=e.transcription&&""!=e.transcription?(l(),o(x,{key:0,class:"text"},{default:n((()=>[v(h(e.transcription),1)])),_:2},1024)):m("",!0)])),_:2},1032,["onClick"])))),128))])),_:1},8,["style"]),c(x,{class:"input-area"},{default:n((()=>[c(j,{onMousedown:O,onMouseup:S,onMouseleave:$,onTouchstart:O,onTouchend:S,onTouchcancel:$,onTouchmove:H},{default:n((()=>[v(" 按住 说话 ")])),_:1}),U.value?(l(),o(x,{key:0,class:"recording-overlay"},{default:n((()=>[c(x,null,{default:n((()=>[v(h(A.value),1)])),_:1}),c(x,null,{default:n((()=>[v("上滑至此取消")])),_:1})])),_:1})):m("",!0)])),_:1})])),_:1})])),_:1})}}},[["__scopeId","data-v-d67bddcf"]]);export{j as default};
|