1import{j as o,r as n}from"./chunk-UIGDSWPH-CcLCFrea.js";import{u as R,T as k}from"./useTranslation-C6k5gwFo.js";import{C as F,I as L}from"./Close-CBqugbig.js";import{d as w,t as D}from"./audioHelpers-DNH3Sr4q.js";import{c as B}from"./Paper-D3V4rGTt.js";import{u as U}from"./BuyCreditsModal-l2ImXwxC.js";import"./index-CWSbccL4.js";import{e as z}from"./BaseDialog-CFfqCgCH.js";import{F as W}from"./FormatTime-CDjDn3UG.js";import{s as d}from"./styled-B-E3RNVO.js";import{B as I}from"./Box-B70oA6jf.js";import{I as M}from"./IconButton-Dp5jd_nM.js";import{u as $}from"./useTheme-Bq_Ywf3t.js";import{S as A}from"./Stack-CAG9CRF7.js";const N=B(o.jsx("path",{d:"M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3m-1.2-9.1c0-.66.54-1.2 1.2-1.2s1.2.54 1.2 1.2l-.01 6.2c0 .66-.53 1.2-1.19 1.2s-1.2-.54-1.2-1.2zm6.5 6.1c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72z"})),P=B(o.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8m4-4H8V8h8z"})),v=1024,j=v*1024,be=e=>{const{t:c}=R();return n.useMemo(()=>e<v?c("general:fileSizeUnits:bytes",{size:e}):e<j?c("general:fileSizeUnits:kb",{size:(e/v).toFixed(2)}):c("general:fileSizeUnits:mb",{size:(e/j).toFixed(2)}),[e,c])},x=n.createContext({audioContext:null,audioSource:null,mediaStream:null}),V=({children:e})=>{const[c,i]=n.useState(null),[s,m]=n.useState(null);n.useEffect(()=>{(async()=>{const a=await navigator.mediaDevices.getUserMedia({audio:!0});m(a)})()},[]);const[r,l]=n.useState(null);return n.useEffect(()=>{const a=new AudioContext,t=()=>{a.state!=="closed"&&a.resume()};return document.body.addEventListener("click",t,{once:!0}),l(a),()=>{document.body.removeEventListener("click",t),a.close()}},[]),n.useEffect(()=>{if(!s||!r)return;const a=r.createMediaStreamSource(s);return i(a),()=>{s.getTracks().forEach(u=>{u.stop()})}},[s,r]),o.jsx(x.Provider,{value:{audioContext:r,audioSource:c,mediaStream:s},children:e})},H=d(I)(()=>({display:"grid",gridTemplate:"'. button time'",gridTemplateColumns:"30% 1fr 30%",alignItems:"center",width:"100%"})),E=d(M)(({theme:e})=>({gridArea:"button",justifySelf:"center",borderRadius:e.spacing(.5)})),q=d(E)(({theme:e})=>({color:e.palette.grey[800],background:e.palette.error.light,"&:hover":{background:e.palette.error.main},"&.Mui-disabled":{background:e.palette.grey[200],color:e.palette.grey[300]}})),O=d(E)(({theme:e})=>({background:e.palette.grey[400],"&:hover":{background:e.palette.grey[500]}})),_=d(k)(()=>({gridArea:"time",justifySelf:"end"})),G=30,K=({onBlobRecorded:e})=>{const{track:c}=U(),{mediaStream:i}=n.useContext(x),[s,m]=n.useState(!1),[r,l]=n.useState(0),a=n.useCallback(async({data:f})=>{e(f);const{duration:p}=await w(f);c(z.audioClipRecorded({duration:p}))},[e,c]),t=n.useMemo(()=>i?new MediaRecorder(i):null,[i]);n.useEffect(()=>(t==null||t.addEventListener("dataavailable",a),()=>{t==null||t.removeEventListener("dataavailable",a)}),[t,a]),n.useEffect(()=>{let f;const p=()=>{l(0),m(()=>!0),f=setInterval(()=>l(S=>S+1),1e3)},h=()=>{m(()=>!1),clearInterval(f)};return t==null||t.addEventListener("start",p),t==null||t.addEventListener("stop",h),()=>{t==null||t.removeEventListener("start",p),t==null||t.removeEventListener("stop",h)}},[t]);const u=n.useCallback(()=>t==null?void 0:t.start(),[t]),g=n.useCallback(()=>t==null?void 0:t.stop(),[t]);return n.useEffect(()=>{r>=G&&g()},[r,g]),o.jsxs(H,{children:[s?o.jsx(O,{onClick:g,children:o.jsx(P,{})}):o.jsx(q,{onClick:u,disabled:!i,children:o.jsx(N,{})}),i&&o.jsx(_,{children:o.jsx(W,{time:r})})]})},X=d("canvas")(()=>({})),J=e=>{const c=$(),{audioSource:i,audioContext:s}=n.useContext(x),m=n.useRef(null),r=n.useRef(null),l=n.useMemo(()=>{if(!s)return null;const t=s==null?void 0:s.createAnalyser();return t.fftSize=1024,t},[s]),a=n.useCallback(()=>{if(!l||!r.current)return;const t=r.current,u=t.getContext("2d");if(!u)return;
1const g=l.frequencyBinCount,f=new Uint8Array(g),p=()=>{l.getByteTimeDomainData(f),u.clearRect(0,0,t.width,t.height),u.lineWidth=4,u.strokeStyle=c.palette.grey[600],u.beginPath();const h=t.width/g;let S=0;for(let y=0;y<g;y+=1){const b=f[y]/128*t.height/2;y===0?u.moveTo(S,b):u.lineTo(S,b),S+=h}u.lineTo(t.width,t.height/2),u.stroke(),m.current=requestAnimationFrame(p)};p()},[l,r,c]);return n.useEffect(()=>{if(!(!l||!i))return i.connect(l),a(),()=>{i.disconnect(l),m.current&&cancelAnimationFrame(m.current)}},[l,i,a]),o.jsx(X,{...e,ref:r})},Q=d(I)(({theme:e})=>({background:e.palette.grey[100],padding:e.spacing(2),borderRadius:e.spacing(1)})),C=d(A)(({theme:e})=>({gap:e.spacing(4),alignItems:"center"})),Y=d("audio")(({theme:e})=>({height:e.spacing(5),width:"100%",maxWidth:e.spacing(30)})),Z=d(J)(({theme:e})=>({height:e.spacing(5),width:"100%",maxWidth:e.spacing(30)})),ee=d(k)(({theme:e})=>({color:e.palette.grey[600],height:e.spacing(5),width:"100%",maxWidth:e.spacing(30),textAlign:"center"})),te=d(A)(({theme:e})=>({flexDirection:"row",gap:e.spacing(1)})),T=d(M)(({theme:e})=>({borderRadius:e.spacing(.5)})),ne=d(T)(({theme:e})=>({background:e.palette.error.light,"&:hover":{background:e.palette.error.main}})),oe=d(T)(({theme:e})=>({background:e.palette.success.light,"&:hover":{background:e.palette.success.main}})),se=()=>{const e=new Date,c=new Intl.DateTimeFormat("en",{year:"2-digit"}).format(e),i=new Intl.DateTimeFormat("en",{month:"short"}).format(e),s=new Intl.DateTimeFormat("en",{day:"2-digit"}).format(e),m=new Intl.DateTimeFormat("en",{hour:"numeric",hour12:!1}).format(e),r=new Intl.DateTimeFormat("en",{minute:"numeric"}).format(e);return`recording-${s}${i}${c}-${m}${r}.mp3`},re=({onAddFile:e,onError:c})=>{const{t:i}=R(),[s,m]=n.useState(null),{audioContext:r,audioSource:l}=n.useContext(x),a=n.useMemo(()=>s?URL.createObjectURL(s):null,[s]),t=n.useCallback(async()=>{if(!r||!s)return;const f=se();try{const p=await w(s,r),h=await D(p),S=new Blob(h,{type:"audio/mpeg"}),y=new File([S],f);e(y)}catch(p){const h=new File([],f);c(h,new Error(p))}},[r,e,c,s]),u=()=>m(null),g=s&&a;return o.jsx(Q,{children:g?o.jsxs(C,{children:[o.jsx(Y,{controls:!0,src:a}),o.jsxs(te,{children:[o.jsx(ne,{onClick:u,children:o.jsx(F,{})}),o.jsx(oe,{onClick:t,children:o.jsx(L,{})})]})]}):o.jsxs(C,{children:[l?o.jsx(Z,{}):o.jsx(ee,{children:i("vega:userLoop:microphoneAccessMessage")}),o.jsx(K,{onBlobRecorded:m})]})})},je=e=>o.jsx(V,{children:o.jsx(re,{...e})});export{N as M,je as R,be as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.