PageSourceSearch

https://app.partgenie.ai/assets/createSttProvider-CDAVxb7o.js

js partgenie.ai collected 2026-10-05 12:23:45 UTC 4,563 bytes, 1 lines download raw bytes

1var u=Object.defineProperty;var h=(s,e,t)=>e in s?u(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>h(s,typeof e!="symbol"?e+"":e,t);import{dL as m,cn as f,dM as w}from"./index-DWNk6RiV.js";import"./markdown-BHI3NCWy.js";import"./headlessui-N-fPSRQf.js";import"./cos-DEg_Xlof.js";import"./katex-Ct3U8f3M.js";import"./router-DU3DDJf2.js";import"./pdf-Bkvtm_2f.js";import"./i18n-D-QaD5s1.js";import"./query-CBc6I7sO.js";import"./radix-cSjvLwSS.js";import"./motion-bQT0Bb1X.js";async function S(s,e){const t=new FormData;t.append("file",s,"recording.webm"),t.append("lang",e);const r=await m.post(`${f}voice/transcribe`,{body:t,credentials:"same-origin",timeout:6e4}).json();if(r.code!==w)throw new Error(r.msg||"Transcription failed");return r.data}function l(){return typeof MediaRecorder>"u"?void 0:["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(e=>MediaRecorder.isTypeSupported(e))}class g{constructor(){i(this,"id","server");i(this,"supportsInterim",!1);i(this,"mediaRecorder",null);i(this,"chunks",[]);i(this,"lang","en-US");i(this,"stream",null);i(this,"ownsStream",!1)}isSupported(){return typeof MediaRecorder<"u"&&l()!=null}async start(e){if(!this.isSupported())throw new Error("Server speech-to-text is not available");this.cancel(),this.lang=e.lang,this.chunks=[],e.mediaStream?(this.stream=e.mediaStream,this.ownsStream=!1):(this.stream=await navigator.mediaDevices.getUserMedia({audio:!0}),this.ownsStream=!0);const t=l();this.mediaRecorder=t?new MediaRecorder(this.stream,{mimeType:t}):new MediaRecorder(this.stream),this.mediaRecorder.ondataavailable=r=>{r.data.size>0&&this.chunks.push(r.data)},this.mediaRecorder.start(250)}async stop(){const e=this.mediaRecorder;if(!e||e.state==="inactive")return this.releaseStream(),{text:"",isFinal:!0,provider:"server"};const t=await new Promise((n,a)=>{e.onstop=()=>{const o=e.mimeType||"audio/webm";n(new Blob(this.chunks,{type:o}))},e.onerror=()=>a(new Error("Recording failed")),e.stop()});this.mediaRecorder=null,this.chunks=[],this.releaseStream();const r=await S(t,this.lang);return{text:r.text.trim(),isFinal:!0,provider:"server",confidence:r.confidence}}cancel(){if(this.mediaRecorder&&this.mediaRecorder.state!=="inactive")try{this.mediaRecorder.stop()}catch{}this.mediaRecorder=null,this.chunks=[],this.releaseStream()}releaseStream(){if(this.ownsStream&&this.stream)for(const e of this.stream.getTracks())e.stop();this.stream=null,this.ownsStream=!1}}function p(){return typeof window>"u"?null:window.SpeechRecognition??window.webkitSpeechRecognition??null}function R(){return p()!=null}class v{constructor(){i(this,"id","browser");i(this,"supportsInterim",!0);i(this,"recognition",null);i(this,"latestTranscript","");i(this,"stopResolve",null);i(this,"stopReject",null);i(this,"stoppedIntentionally",!1)}isSupported(){return R()}async start(e){const t=p();if(!t)throw new Error("Web Speech API is not supported in this browser");this.cancel(),this.latestTranscript="",this.stoppedIntentionally=!1;const r=new t;r.continuous=!0,r.interimResults=!0,r.lang=e.lang,r.maxAlternatives=1,r.onresult=n=>{var o,d;let a="";for(let c=0;c<n.results.length;c+=1)a+=((o=n.results[c][0])==null?void 0:o.transcript)??"";this.latestTranscript=a.trim(),(d=e.onPartial)==null||d.call(e,this.latestTranscript)},r.onerror=n=>{var o;if(n.error==="aborted")return;const a=new Error(n.message||n.error||"Speech recognition failed");(o=this.stopReject)==null||o.call(this,a),this.cleanup()},r.onend=()=>{if(!this.stoppedIntentionally){this.finishStop();return}this.finishStop()},this.recognition=r,r.start()}stop(){return this.recognition?(this.stoppedIntentionally=!0,new Promise((e,t)=>{var r;this.stopResolve=e,this.stopReject=t;try{(r=this.recognition)==null||r.stop()}catch{this.finishStop()}})):Promise.resolve({text:this.latestTranscript,isFinal:!0,provider:"browser"})}cancel(){var e;this.stoppedIntentionally=!0;try{(e=this.recognition)==null||e.abort()}catch{}this.cleanup()}finishStop(){var t;const e={text:this.latestTranscript,isFinal:!0,provider:"browser"};(t=this.stopResolve)==null||t.call(this,e),this.cleanup()}cleanup(){this.recognition=null,this.stopResolve=null,this.stopReject=null}}function b(){return null}function y(){return b()??"browser"}function W(s){const e=s??y(),t=new v,r=new g;if(e==="server"&&r.isSupported())return r;if(e==="browser"&&t.isSupported())return t;if(e==="auto"){if(t.isSupported())return t;if(r.isSupported())return r}return t.isSupported()?t:r}export{W as createSttProvider,y as resolveVoiceSttPreference};

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.