PageSourceSearch

https://talktinker.com/build/assets/VolumeMeter-Dq_uOgmO.js

js talktinker.com collected 2026-10-02 01:46:39 UTC 5,488 bytes, 1 lines download raw bytes

1import{d as se,u as oe,al as le,o as c,c as u,a as E,b as a,t as l,h as ne,e as r,w as re,f as ie,g as p,bP as ce,i as ue,s as S,q,F as A,B as de,j as g,y as k}from"./app-CCBQfkKJ.js";import{A as ve}from"./arrow-left-BpA_Avbt.js";import{M as me}from"./mic-Dpt0pbxl.js";const fe={class:"mx-auto max-w-2xl px-4 py-6 sm:px-6 lg:px-8"},pe={class:"rounded-2xl border border-gray-200 bg-white p-8 text-center shadow-sm"},ge={class:"text-xl font-semibold text-gray-900"},he={class:"my-8 flex items-center justify-center gap-6"},be={class:"relative flex h-72 w-72 items-center justify-center"},xe=["disabled","aria-label"],_e={class:"font-mono text-5xl font-bold tabular-nums"},ye={class:"mt-2 text-xs font-semibold uppercase tracking-wider opacity-95"},we={class:"mt-2 text-xs font-semibold uppercase tracking-wider opacity-95"},ke={class:"flex h-72 w-10 flex-col-reverse gap-1 py-1"},Me={key:0,class:"mt-2 text-sm text-rose-600",role:"alert"},Ce={key:1,class:"mt-2 text-sm text-gray-500"},P=-65,Ee=-6,D=16,Se=1200,Ae=.6,Ne=se({__name:"VolumeMeter",setup(De){const $=oe(),j=g(()=>$.props.locale||"en"),T={r:16,g:185,b:129},h={r:245,g:158,b:11},B={r:239,g:68,b:68},n=k(!1),o=k(0),d=k(0),i=k("idle"),b=k("");let _=null,v=null,m=null,y=null,w=null,x=null,M=0,F=0;const R=e=>Math.max(0,Math.min(1,e)),f=(e,t,s)=>e+(t-e)*s,z=e=>{if(e<=.6){const s=e/.6;return{r:Math.round(f(T.r,h.r,s)),g:Math.round(f(T.g,h.g,s)),b:Math.round(f(T.b,h.b,s))}}const t=(e-.6)/.4;return{r:Math.round(f(h.r,B.r,t)),g:Math.round(f(h.g,B.g,t)),b:Math.round(f(h.b,B.b,t))}},N=e=>{const t=z(e);return`rgb(${t.r}, ${t.g}, ${t.b})`},G=g(()=>N(o.value)),K=g(()=>N(d.value)),Y=g(()=>.6+o.value*.65),H=g(()=>o.value*.35),Q=g(()=>.5+d.value*.5),W=g(()=>Math.round(o.value*100)),U=()=>{if(!m||!x)return;m.getFloatTimeDomainData(x);let e=0;for(let V=0;V<x.length;V++){const O=Math.abs(x[V]);O>e&&(e=O)}const t=e>0?20*Math.log10(e):P,s=R((t-P)/(Ee-P)),te=s>o.value?.85:.4;o.value=f(o.value,s,te);const C=performance.now(),ae=M===0?0:(C-M)/1e3;M=C,o.value>=d.value?(d.value=o.value,F=C):C-F>Se&&(d.value=Math.max(o.value,d.value-Ae*ae)),w=requestAnimationFrame(U)},L=()=>
1{if(n.value=!1,w!==null&&(cancelAnimationFrame(w),w=null),y){try{y.disconnect()}catch{}y=null}m=null,x=null,_&&(_.getTracks().forEach(e=>e.stop()),_=null),v&&(v.close().catch(()=>{}),v=null),o.value=0,d.value=0,M=0,F=0,i.value==="active"&&(i.value="idle")},J=async()=>{if(!n.value){if(typeof navigator>"u"||!navigator.mediaDevices?.getUserMedia){i.value="unsupported",b.value=l("Microphone is not supported in this browser.");return}i.value="requesting",b.value="";try{_=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1}});const e=window.AudioContext||window.webkitAudioContext;v=new e,v.state==="suspended"&&await v.resume(),y=v.createMediaStreamSource(_),m=v.createAnalyser(),m.fftSize=1024,m.smoothingTimeConstant=.2,x=new Float32Array(new ArrayBuffer(m.fftSize*Float32Array.BYTES_PER_ELEMENT)),y.connect(m),n.value=!0,i.value="active",w=requestAnimationFrame(U)}catch(e){const t=e;t.name==="NotAllowedError"||t.name==="PermissionDeniedError"?(i.value="denied",b.value=l("Microphone access was blocked. Update your browser permissions and try again.")):(i.value="idle",b.value=l("We couldn't start the microphone. Try again in a moment.")),L()}}},X=()=>{n.value?L():J()},Z=Array.from({length:D},(e,t)=>t),I=e=>{const t=(e+1)/D;return n.value&&o.value>=t-.5/D},ee=e=>N((e+1)/D);return le(()=>L()),(e,t)=>(c(),u(A,null,[E(a(ne),{title:a(l)("Volume Meter")},null,8,["title"]),r("div",fe,[E(a(ue),{href:a(ce).url({locale:j.value}),class:"mb-4 inline-flex items-center gap-1 text-sm text-gray-600 hover:text-pink-600"},{default:re(()=>[E(a(ve),{class:"h-4 w-4"}),ie(" "+p(a(l)("Tools")),1)]),_:1},8,["href"]),r("div",pe,[r("h1",ge,p(a(l)("Volume Meter")),1),r("div",he,[r("div",be,[n.value?(c(),u("div",{key:0,class:"pointer-events-none absolute h-72 w-72 rounded-full transition-all duration-100 ease-out",style:S({backgroundColor:G.value,opacity:H.value,transform:`scale(${Y.value})`})},null,4)):q("",!0),n.value&&d.value>0?(c(),u("div",{key:1,class:"pointer-events-none absolute h-64 w-64 rounded-full border-[3px] transition-all duration-200 ease-out",style:S({borderColor:K.value,transform:`scale(${Q.value})`})},null,4)):q("",!0),r("button",{type:"button",onClick:X,disabled:i.value==="requesting","aria-label":n.value?a(l)("Stop"):a(l)("Start listening"),class:"relative flex h-56 w-56 flex-col items-center justify-center rounded-full text-white shadow-xl outline-none transition-colors duration-150 ease-out hover:brightness-105 focus-visible:ring-4 focus-visible:ring-pink-300 active:scale-[0.98] disabled:cursor-progress",style:S(n.value?{backgroundColor:"#10B981"}:{backgroundImage:"linear-gradient(135deg, #db2777 0%, #ec4899 100%)"})},[n.value?(c(),u(A,{key:0},[r("span",_e,p(W.value)+"% ",1),r("span",ye,p(a(l)("Stop")),1)],64)):(c(),u(A,{key:1},[E(a(me),{class:"h-14 w-14","stroke-width":"2"}),r("span",we,p(i.value==="requesting"?a(l)("Requesting access..."):a(l)("Start listening")),1)],64))],12,xe)]),r("div",ke,[(c(!0),u(A,null,de(a(Z),s=>(c(),u("div",{key:s,class:"w-full flex-1 rounded-md transition-all duration-75",style:S({backgroundColor:I(s)?ee(s):"#E5E7EB",opacity:I(s)?1:.5})},null,4))),128))])]),b.value?(c(),u("p",Me,p(b.value),1)):n.value?q("",!0):(c(),u("p",Ce,p(a(l)("Visualise voice volume to practise speaking softly or loudly.")),1))])])],64))}});export{Ne as default};

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.