@poovit-banton/speech-recognition-sdk 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -179,5 +179,5 @@ File System access not available, please use Push or PullAudioOutputStream`),thi
179
179
  background-color: ${A=>A.$backgroundColor};
180
180
  z-index: ${A=>A.$zIndex};
181
181
  backdrop-filter: blur(8px);
182
- `;function ds({size:A="medium",fullscreen:e=!1,backgroundColor:t="rgba(0, 0, 0, 0.8)",zIndex:a=9999}){const n=A==="small"?20:A==="medium"?30:40,s=[{id:0,size:n*1.5,offsetX:-25,offsetY:-25,delay:0,duration:A==="small"?1.5:A==="medium"?2:2.5,rotate:!1},{id:1,size:n*.6,offsetX:15,offsetY:-35,delay:.2,duration:A==="small"?1.5:A==="medium"?2:2.5,rotate:!0},{id:2,size:n*.4,offsetX:20,offsetY:10,delay:.4,duration:A==="small"?1.5:A==="medium"?2:2.5,rotate:!1}],i=g.jsx(Nm,{className:`loading-stars loading-stars-${A}`,children:s.map(r=>g.jsx("div",{className:`star ${r.rotate?"star-rotate":""}`,style:{width:`${r.size}px`,height:`${r.size}px`,animationDelay:`${r.delay}s`,animationDuration:`${r.duration}s`,left:`calc(50% + ${r.offsetX}px)`,top:`calc(50% + ${r.offsetY}px)`,position:"absolute",transform:"translate(-50%, -50%)"},children:g.jsx("img",{src:mm,alt:"star",draggable:!1})},r.id))});return e?g.jsx(Um,{$backgroundColor:t,$zIndex:a,children:i}):i}ds.displayName="LoadingStars";var qs={exports:{}},Pu;function hm(){return Pu||(Pu=1,(function(A){var e=(function(t){var a=Object.prototype,n=a.hasOwnProperty,s=Object.defineProperty||function(z,h,W){z[h]=W.value},i,r=typeof Symbol=="function"?Symbol:{},p=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",l=r.toStringTag||"@@toStringTag";function c(z,h,W){return Object.defineProperty(z,h,{value:W,enumerable:!0,configurable:!0,writable:!0}),z[h]}try{c({},"")}catch{c=function(h,W,P){return h[W]=P}}function u(z,h,W,P){var K=h&&h.prototype instanceof T?h:T,j=Object.create(K.prototype),rA=new G(P||[]);return s(j,"_invoke",{value:B(z,W,rA)}),j}t.wrap=u;function d(z,h,W){try{return{type:"normal",arg:z.call(h,W)}}catch(P){return{type:"throw",arg:P}}}var q="suspendedStart",V="suspendedYield",f="executing",v="completed",m={};function T(){}function S(){}function b(){}var U={};c(U,p,function(){return this});var L=Object.getPrototypeOf,y=L&&L(L(tA([])));y&&y!==a&&n.call(y,p)&&(U=y);var X=b.prototype=T.prototype=Object.create(U);S.prototype=b,s(X,"constructor",{value:b,configurable:!0}),s(b,"constructor",{value:S,configurable:!0}),S.displayName=c(b,l,"GeneratorFunction");function Z(z){["next","throw","return"].forEach(function(h){c(z,h,function(W){return this._invoke(h,W)})})}t.isGeneratorFunction=function(z){var h=typeof z=="function"&&z.constructor;return h?h===S||(h.displayName||h.name)==="GeneratorFunction":!1},t.mark=function(z){return Object.setPrototypeOf?Object.setPrototypeOf(z,b):(z.__proto__=b,c(z,l,"GeneratorFunction")),z.prototype=Object.create(X),z},t.awrap=function(z){return{__await:z}};function J(z,h){function W(j,rA,aA,R){var Q=d(z[j],z,rA);if(Q.type==="throw")R(Q.arg);else{var zA=Q.arg,gA=zA.value;return gA&&typeof gA=="object"&&n.call(gA,"__await")?h.resolve(gA.__await).then(function(BA){W("next",BA,aA,R)},function(BA){W("throw",BA,aA,R)}):h.resolve(gA).then(function(BA){zA.value=BA,aA(zA)},function(BA){return W("throw",BA,aA,R)})}}var P;function K(j,rA){function aA(){return new h(function(R,Q){W(j,rA,R,Q)})}return P=P?P.then(aA,aA):aA()}s(this,"_invoke",{value:K})}Z(J.prototype),c(J.prototype,o,function(){return this}),t.AsyncIterator=J,t.async=function(z,h,W,P,K){K===void 0&&(K=Promise);var j=new J(u(z,h,W,P),K);return t.isGeneratorFunction(h)?j:j.next().then(function(rA){return rA.done?rA.value:j.next()})};function B(z,h,W){var P=q;return function(j,rA){if(P===f)throw new Error("Generator is already running");if(P===v){if(j==="throw")throw rA;return Y()}for(W.method=j,W.arg=rA;;){var aA=W.delegate;if(aA){var R=D(aA,W);if(R){if(R===m)continue;return R}}if(W.method==="next")W.sent=W._sent=W.arg;else if(W.method==="throw"){if(P===q)throw P=v,W.arg;W.dispatchException(W.arg)}else W.method==="return"&&W.abrupt("return",W.arg);P=f;var Q=d(z,h,W);if(Q.type==="normal"){if(P=W.done?v:V,Q.arg===m)continue;return{value:Q.arg,done:W.done}}else Q.type==="throw"&&(P=v,W.method="throw",W.arg=Q.arg)}}}function D(z,h){var W=h.method,P=z.iterator[W];if(P===i)return h.delegate=null,W==="throw"&&z.iterator.return&&(h.method="return",h.arg=i,D(z,h),h.method==="throw")||W!=="return"&&(h.method="throw",h.arg=new TypeError("The iterator does not provide a '"+W+"' method")),m;var K=d(P,z.iterator,h.arg);if(K.type==="throw")return h.method="throw",h.arg=K.arg,h.delegate=null,m;var j=K.arg;if(!j)return h.method="throw",h.arg=new TypeError("iterator result is not an object"),h.delegate=null,m;if(j.done)h[z.resultName]=j.value,h.next=z.nextLoc,h.method!=="return"&&(h.method="next",h.arg=i);else return j;return h.delegate=null,m}Z(X),c(X,l,"Generator"),c(X,p,function(){return this}),c(X,"toString",function(){return"[object Generator]"});function E(z){var h={tryLoc:z[0]};1 in z&&(h.catchLoc=z[1]),2 in z&&(h.finallyLoc=z[2],h.afterLoc=z[3]),this.tryEntries.push(h)}function H(z){var h=z.completion||{};h.type="normal",delete h.arg,z.completion=h}function G(z){this.tryEntries=[{tryLoc:"root"}],z.forEach(E,this),this.reset(!0)}t.keys=function(z){var h=Object(z),W=[];for(var P in h)W.push(P);return W.reverse(),function K(){for(;W.length;){var j=W.pop();if(j in h)return K.value=j,K.done=!1,K}return K.done=!0,K}};function tA(z){if(z!=null){var h=z[p];if(h)return h.call(z);if(typeof z.next=="function")return z;if(!isNaN(z.length)){var W=-1,P=function K(){for(;++W<z.length;)if(n.call(z,W))return K.value=z[W],K.done=!1,K;return K.value=i,K.done=!0,K};return P.next=P}}throw new TypeError(typeof z+" is not iterable")}t.values=tA;function Y(){return{value:i,done:!0}}return G.prototype={constructor:G,reset:function(z){if(this.prev=0,this.next=0,this.sent=this._sent=i,this.done=!1,this.delegate=null,this.method="next",this.arg=i,this.tryEntries.forEach(H),!z)for(var h in this)h.charAt(0)==="t"&&n.call(this,h)&&!isNaN(+h.slice(1))&&(this[h]=i)},stop:function(){this.done=!0;var z=this.tryEntries[0],h=z.completion;if(h.type==="throw")throw h.arg;return this.rval},dispatchException:function(z){if(this.done)throw z;var h=this;function W(R,Q){return j.type="throw",j.arg=z,h.next=R,Q&&(h.method="next",h.arg=i),!!Q}for(var P=this.tryEntries.length-1;P>=0;--P){var K=this.tryEntries[P],j=K.completion;if(K.tryLoc==="root")return W("end");if(K.tryLoc<=this.prev){var rA=n.call(K,"catchLoc"),aA=n.call(K,"finallyLoc");if(rA&&aA){if(this.prev<K.catchLoc)return W(K.catchLoc,!0);if(this.prev<K.finallyLoc)return W(K.finallyLoc)}else if(rA){if(this.prev<K.catchLoc)return W(K.catchLoc,!0)}else if(aA){if(this.prev<K.finallyLoc)return W(K.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(z,h){for(var W=this.tryEntries.length-1;W>=0;--W){var P=this.tryEntries[W];if(P.tryLoc<=this.prev&&n.call(P,"finallyLoc")&&this.prev<P.finallyLoc){var K=P;break}}K&&(z==="break"||z==="continue")&&K.tryLoc<=h&&h<=K.finallyLoc&&(K=null);var j=K?K.completion:{};return j.type=z,j.arg=h,K?(this.method="next",this.next=K.finallyLoc,m):this.complete(j)},complete:function(z,h){if(z.type==="throw")throw z.arg;return z.type==="break"||z.type==="continue"?this.next=z.arg:z.type==="return"?(this.rval=this.arg=z.arg,this.method="return",this.next="end"):z.type==="normal"&&h&&(this.next=h),m},finish:function(z){for(var h=this.tryEntries.length-1;h>=0;--h){var W=this.tryEntries[h];if(W.finallyLoc===z)return this.complete(W.completion,W.afterLoc),H(W),m}},catch:function(z){for(var h=this.tryEntries.length-1;h>=0;--h){var W=this.tryEntries[h];if(W.tryLoc===z){var P=W.completion;if(P.type==="throw"){var K=P.arg;H(W)}return K}}throw new Error("illegal catch attempt")},delegateYield:function(z,h,W){return this.delegate={iterator:tA(z),resultName:h,nextLoc:W},this.method==="next"&&(this.arg=i),m}},t})(A.exports);try{regeneratorRuntime=e}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})(qs)),qs.exports}hm();const wu=C.createContext(null);function ym({children:A,config:e,showWidget:t=!1,widgetEnabled:a=!0,widgetPosition:n="bottom-left",widgetZIndex:s=9998,modalTitle:i,generateButtonText:r,onGenerate:p,onGenerateComplete:o,onGenerateError:l,apiKey:c=""}){const[u,d]=C.useState(a),[q,V]=C.useState(t),[f,v]=C.useState(null),[m,T]=C.useState(null),[S,b]=C.useState(!1),{transcript:U,interimTranscript:L,finalTranscript:y,listening:X,resetTranscript:Z,browserSupportsSpeechRecognition:J,isMicrophoneAvailable:B}=yd(),D=C.useCallback(h=>{d(h)},[]),E=C.useCallback(()=>{d(h=>!h)},[]),H=C.useCallback(async h=>{const W=h?.language||e?.language||"th-TH",P=h?.continuous??e?.continuous??!0,K=h?.interimResults??e?.interimResults??!0;await KA.startListening({language:W,continuous:P,interimResults:K})},[e]),G=C.useCallback(()=>{},[]),tA=C.useCallback(()=>{},[]),Y=C.useCallback(async()=>{try{V(!0),T(null),b(!1);const h=await da.getAzureToken(c);if(h?.token&&h?.region){v(h),console.log("Azure token fetched:",h.region);const{SpeechRecognition:W}=GV({credentials:{region:h.region,authorizationToken:h.token}});KA.applyPolyfill(W),b(!0),console.log("Azure Speech Recognition registered successfully")}}catch(h){v(null),b(!1),T(h instanceof Error?h.message:"Failed to fetch Azure token"),console.error("Failed to fetch Azure token:",h)}finally{V(!1)}},[c]);C.useEffect(()=>{t&&Y()},[t,Y]);const z=C.useMemo(()=>({transcript:U,interimTranscript:L,finalTranscript:y,isListening:X,browserSupportsSpeechRecognition:J,isMicrophoneAvailable:B,startListening:H,stopListening:G,abortListening:tA,resetTranscript:Z,isWidgetEnabled:u,setWidgetEnabled:D,toggleWidget:E,azureToken:f,isAzureReady:S,azureError:m,apiKey:c}),[U,L,y,X,J,B,H,G,tA,Z,u,D,E,f,S,m,c]);return g.jsxs(wu.Provider,{value:z,children:[A,t&&q&&g.jsx(ds,{fullscreen:!0}),t&&!q&&g.jsx(Ku,{apiKey:c,enabled:u,position:n,config:e,zIndex:s,modalTitle:i,generateButtonText:r,onGenerate:p,onGenerateComplete:o,onGenerateError:l,abortListening:tA,startListening:H,stopListening:G,resetTranscript:Z,transcript:U,isListening:X,browserSupportsSpeechRecognition:J,isMicrophoneAvailable:B})]})}function zm(){const A=C.useContext(wu);if(!A)throw new Error("useSpeechContext must be used within a SpeechProvider");return A}const Wm={sm:60,md:100,lg:140},Cu={button:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",border:"none",borderRadius:"50%",cursor:"pointer",transition:"all 0.2s ease",background:"transparent",padding:0},disabled:{opacity:.5,cursor:"not-allowed"}},Lm=()=>g.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:"32",height:"32",children:[g.jsx("path",{d:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm-1-9c0-.55.45-1 1-1s1 .45 1 1v6c0 .55-.45 1-1 1s-1-.45-1-1V5z"}),g.jsx("path",{d:"M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"})]}),Om=()=>g.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:"32",height:"32",children:g.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})});function gm({isListening:A,onStart:e,onStop:t,disabled:a=!1,className:n,style:s,startIcon:i,stopIcon:r,startLabel:p,stopLabel:o,size:l="md",useAssets:c=!0}){const u=()=>{a||(A?t():e())},d=Wm[l],q={...Cu.button,width:d,height:d,...a&&Cu.disabled,filter:c?"drop-shadow(0 4px 12px rgba(255, 122, 0, 0.4))":void 0,...s};return c?g.jsx("button",{type:"button",onClick:u,disabled:a,className:n,style:q,"aria-label":A?"Stop recording":"Start recording",children:g.jsx("img",{src:A?Gc:Bc,alt:A?"Stop":"Start",style:{width:"100%",height:"100%"}})}):g.jsx("button",{type:"button",onClick:u,disabled:a,className:n,style:{...q,background:A?"linear-gradient(135deg, #ef4444 0%, #dc2626 100%)":"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",color:"white",boxShadow:A?"0 10px 40px rgba(239, 68, 68, 0.4)":"0 10px 40px rgba(102, 126, 234, 0.4)"},"aria-label":A?"Stop recording":"Start recording",children:g.jsxs("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"},children:[A?r||g.jsx(Om,{}):i||g.jsx(Lm,{}),(p||o)&&g.jsx("span",{style:{fontSize:l==="sm"?"10px":l==="md"?"12px":"14px"},children:A?o||"Stop":p||"Start"})]})})}const Ne={container:{width:"100%"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},title:{fontSize:"18px",fontWeight:600,margin:0},resetButton:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 16px",borderRadius:"8px",border:"1px solid #374151",background:"transparent",color:"#9ca3af",fontSize:"14px",cursor:"pointer"},box:{background:"rgba(255, 255, 255, 0.03)",border:"1px solid #374151",borderRadius:"16px",padding:"24px",minHeight:"150px",overflowY:"auto"},text:{fontSize:"18px",lineHeight:1.75,margin:0,wordWrap:"break-word"},placeholder:{color:"#6b7280",fontSize:"16px",textAlign:"center",margin:0,padding:"32px 0"}},Xm=()=>g.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:"16",height:"16",children:g.jsx("path",{d:"M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"})});function Km({transcript:A,placeholder:e="Click the microphone to start speaking...",isListening:t=!1,className:a,style:n,onReset:s,showResetButton:i=!0,maxHeight:r="300px"}){const p={...Ne.box,maxHeight:r,...n};return g.jsxs("div",{className:a,style:Ne.container,children:[g.jsxs("div",{style:Ne.header,children:[g.jsx("h2",{style:Ne.title,children:"📝 Transcript"}),i&&s&&g.jsxs("button",{type:"button",onClick:s,disabled:!A,style:{...Ne.resetButton,opacity:A?1:.5,cursor:A?"pointer":"not-allowed"},children:[g.jsx(Xm,{}),"Clear"]})]}),g.jsx("div",{style:p,children:A?g.jsx("p",{style:Ne.text,children:A}):g.jsx("p",{style:Ne.placeholder,children:t?"🎧 Listening... Speak now!":e})})]})}function Pm(){return typeof window>"u"?!1:!!(window.SpeechRecognition||window.webkitSpeechRecognition)}function wm(){return typeof window>"u"?null:window.SpeechRecognition||window.webkitSpeechRecognition||null}async function Cm(){try{return(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),!0}catch{return!1}}async function xm(){try{return(await navigator.mediaDevices.enumerateDevices()).some(e=>e.kind==="audioinput")}catch{return!1}}function Zm(){return["th-TH","en-US","en-GB","en-AU","zh-CN","zh-TW","ja-JP","ko-KR","vi-VN","id-ID","ms-MY","fr-FR","de-DE","es-ES","pt-BR","ru-RU","ar-SA","hi-IN"]}function Jm(A){return`${Math.round(A*100)}%`}I.ApiError=us,I.LoadingStars=ds,I.SpeechApiService=da,I.SpeechButton=gm,I.SpeechModal=Rc,I.SpeechProvider=ym,I.SpeechWidget=Ku,I.TranscriptDisplay=Km,I.formatConfidence=Jm,I.getSpeechRecognition=wm,I.getSupportedLanguages=Zm,I.isMicrophoneAvailable=xm,I.isSpeechRecognitionSupported=Pm,I.requestMicrophonePermission=Cm,I.useAudioVisualizer=hs,I.useSpeechContext=zm,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}));
182
+ `;function ds({size:A="medium",fullscreen:e=!1,backgroundColor:t="rgba(0, 0, 0, 0.8)",zIndex:a=9999}){const n=A==="small"?20:A==="medium"?30:40,s=[{id:0,size:n*1.5,offsetX:-25,offsetY:-25,delay:0,duration:A==="small"?1.5:A==="medium"?2:2.5,rotate:!1},{id:1,size:n*.6,offsetX:15,offsetY:-35,delay:.2,duration:A==="small"?1.5:A==="medium"?2:2.5,rotate:!0},{id:2,size:n*.4,offsetX:20,offsetY:10,delay:.4,duration:A==="small"?1.5:A==="medium"?2:2.5,rotate:!1}],i=g.jsx(Nm,{className:`loading-stars loading-stars-${A}`,children:s.map(r=>g.jsx("div",{className:`star ${r.rotate?"star-rotate":""}`,style:{width:`${r.size}px`,height:`${r.size}px`,animationDelay:`${r.delay}s`,animationDuration:`${r.duration}s`,left:`calc(50% + ${r.offsetX}px)`,top:`calc(50% + ${r.offsetY}px)`,position:"absolute",transform:"translate(-50%, -50%)"},children:g.jsx("img",{src:mm,alt:"star",draggable:!1})},r.id))});return e?g.jsx(Um,{$backgroundColor:t,$zIndex:a,children:i}):i}ds.displayName="LoadingStars";var qs={exports:{}},Pu;function hm(){return Pu||(Pu=1,(function(A){var e=(function(t){var a=Object.prototype,n=a.hasOwnProperty,s=Object.defineProperty||function(z,h,W){z[h]=W.value},i,r=typeof Symbol=="function"?Symbol:{},p=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",l=r.toStringTag||"@@toStringTag";function c(z,h,W){return Object.defineProperty(z,h,{value:W,enumerable:!0,configurable:!0,writable:!0}),z[h]}try{c({},"")}catch{c=function(h,W,P){return h[W]=P}}function u(z,h,W,P){var K=h&&h.prototype instanceof T?h:T,j=Object.create(K.prototype),rA=new G(P||[]);return s(j,"_invoke",{value:B(z,W,rA)}),j}t.wrap=u;function d(z,h,W){try{return{type:"normal",arg:z.call(h,W)}}catch(P){return{type:"throw",arg:P}}}var q="suspendedStart",V="suspendedYield",f="executing",v="completed",m={};function T(){}function S(){}function b(){}var U={};c(U,p,function(){return this});var L=Object.getPrototypeOf,y=L&&L(L(tA([])));y&&y!==a&&n.call(y,p)&&(U=y);var X=b.prototype=T.prototype=Object.create(U);S.prototype=b,s(X,"constructor",{value:b,configurable:!0}),s(b,"constructor",{value:S,configurable:!0}),S.displayName=c(b,l,"GeneratorFunction");function Z(z){["next","throw","return"].forEach(function(h){c(z,h,function(W){return this._invoke(h,W)})})}t.isGeneratorFunction=function(z){var h=typeof z=="function"&&z.constructor;return h?h===S||(h.displayName||h.name)==="GeneratorFunction":!1},t.mark=function(z){return Object.setPrototypeOf?Object.setPrototypeOf(z,b):(z.__proto__=b,c(z,l,"GeneratorFunction")),z.prototype=Object.create(X),z},t.awrap=function(z){return{__await:z}};function J(z,h){function W(j,rA,aA,R){var Q=d(z[j],z,rA);if(Q.type==="throw")R(Q.arg);else{var zA=Q.arg,gA=zA.value;return gA&&typeof gA=="object"&&n.call(gA,"__await")?h.resolve(gA.__await).then(function(BA){W("next",BA,aA,R)},function(BA){W("throw",BA,aA,R)}):h.resolve(gA).then(function(BA){zA.value=BA,aA(zA)},function(BA){return W("throw",BA,aA,R)})}}var P;function K(j,rA){function aA(){return new h(function(R,Q){W(j,rA,R,Q)})}return P=P?P.then(aA,aA):aA()}s(this,"_invoke",{value:K})}Z(J.prototype),c(J.prototype,o,function(){return this}),t.AsyncIterator=J,t.async=function(z,h,W,P,K){K===void 0&&(K=Promise);var j=new J(u(z,h,W,P),K);return t.isGeneratorFunction(h)?j:j.next().then(function(rA){return rA.done?rA.value:j.next()})};function B(z,h,W){var P=q;return function(j,rA){if(P===f)throw new Error("Generator is already running");if(P===v){if(j==="throw")throw rA;return Y()}for(W.method=j,W.arg=rA;;){var aA=W.delegate;if(aA){var R=D(aA,W);if(R){if(R===m)continue;return R}}if(W.method==="next")W.sent=W._sent=W.arg;else if(W.method==="throw"){if(P===q)throw P=v,W.arg;W.dispatchException(W.arg)}else W.method==="return"&&W.abrupt("return",W.arg);P=f;var Q=d(z,h,W);if(Q.type==="normal"){if(P=W.done?v:V,Q.arg===m)continue;return{value:Q.arg,done:W.done}}else Q.type==="throw"&&(P=v,W.method="throw",W.arg=Q.arg)}}}function D(z,h){var W=h.method,P=z.iterator[W];if(P===i)return h.delegate=null,W==="throw"&&z.iterator.return&&(h.method="return",h.arg=i,D(z,h),h.method==="throw")||W!=="return"&&(h.method="throw",h.arg=new TypeError("The iterator does not provide a '"+W+"' method")),m;var K=d(P,z.iterator,h.arg);if(K.type==="throw")return h.method="throw",h.arg=K.arg,h.delegate=null,m;var j=K.arg;if(!j)return h.method="throw",h.arg=new TypeError("iterator result is not an object"),h.delegate=null,m;if(j.done)h[z.resultName]=j.value,h.next=z.nextLoc,h.method!=="return"&&(h.method="next",h.arg=i);else return j;return h.delegate=null,m}Z(X),c(X,l,"Generator"),c(X,p,function(){return this}),c(X,"toString",function(){return"[object Generator]"});function E(z){var h={tryLoc:z[0]};1 in z&&(h.catchLoc=z[1]),2 in z&&(h.finallyLoc=z[2],h.afterLoc=z[3]),this.tryEntries.push(h)}function H(z){var h=z.completion||{};h.type="normal",delete h.arg,z.completion=h}function G(z){this.tryEntries=[{tryLoc:"root"}],z.forEach(E,this),this.reset(!0)}t.keys=function(z){var h=Object(z),W=[];for(var P in h)W.push(P);return W.reverse(),function K(){for(;W.length;){var j=W.pop();if(j in h)return K.value=j,K.done=!1,K}return K.done=!0,K}};function tA(z){if(z!=null){var h=z[p];if(h)return h.call(z);if(typeof z.next=="function")return z;if(!isNaN(z.length)){var W=-1,P=function K(){for(;++W<z.length;)if(n.call(z,W))return K.value=z[W],K.done=!1,K;return K.value=i,K.done=!0,K};return P.next=P}}throw new TypeError(typeof z+" is not iterable")}t.values=tA;function Y(){return{value:i,done:!0}}return G.prototype={constructor:G,reset:function(z){if(this.prev=0,this.next=0,this.sent=this._sent=i,this.done=!1,this.delegate=null,this.method="next",this.arg=i,this.tryEntries.forEach(H),!z)for(var h in this)h.charAt(0)==="t"&&n.call(this,h)&&!isNaN(+h.slice(1))&&(this[h]=i)},stop:function(){this.done=!0;var z=this.tryEntries[0],h=z.completion;if(h.type==="throw")throw h.arg;return this.rval},dispatchException:function(z){if(this.done)throw z;var h=this;function W(R,Q){return j.type="throw",j.arg=z,h.next=R,Q&&(h.method="next",h.arg=i),!!Q}for(var P=this.tryEntries.length-1;P>=0;--P){var K=this.tryEntries[P],j=K.completion;if(K.tryLoc==="root")return W("end");if(K.tryLoc<=this.prev){var rA=n.call(K,"catchLoc"),aA=n.call(K,"finallyLoc");if(rA&&aA){if(this.prev<K.catchLoc)return W(K.catchLoc,!0);if(this.prev<K.finallyLoc)return W(K.finallyLoc)}else if(rA){if(this.prev<K.catchLoc)return W(K.catchLoc,!0)}else if(aA){if(this.prev<K.finallyLoc)return W(K.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(z,h){for(var W=this.tryEntries.length-1;W>=0;--W){var P=this.tryEntries[W];if(P.tryLoc<=this.prev&&n.call(P,"finallyLoc")&&this.prev<P.finallyLoc){var K=P;break}}K&&(z==="break"||z==="continue")&&K.tryLoc<=h&&h<=K.finallyLoc&&(K=null);var j=K?K.completion:{};return j.type=z,j.arg=h,K?(this.method="next",this.next=K.finallyLoc,m):this.complete(j)},complete:function(z,h){if(z.type==="throw")throw z.arg;return z.type==="break"||z.type==="continue"?this.next=z.arg:z.type==="return"?(this.rval=this.arg=z.arg,this.method="return",this.next="end"):z.type==="normal"&&h&&(this.next=h),m},finish:function(z){for(var h=this.tryEntries.length-1;h>=0;--h){var W=this.tryEntries[h];if(W.finallyLoc===z)return this.complete(W.completion,W.afterLoc),H(W),m}},catch:function(z){for(var h=this.tryEntries.length-1;h>=0;--h){var W=this.tryEntries[h];if(W.tryLoc===z){var P=W.completion;if(P.type==="throw"){var K=P.arg;H(W)}return K}}throw new Error("illegal catch attempt")},delegateYield:function(z,h,W){return this.delegate={iterator:tA(z),resultName:h,nextLoc:W},this.method==="next"&&(this.arg=i),m}},t})(A.exports);try{regeneratorRuntime=e}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})(qs)),qs.exports}hm();const wu=C.createContext(null);function ym({children:A,config:e,showWidget:t=!1,widgetEnabled:a=!0,widgetPosition:n="bottom-left",widgetZIndex:s=9998,modalTitle:i,generateButtonText:r,onGenerate:p,onGenerateComplete:o,onGenerateError:l,apiKey:c="YCpjZ6ez98Qp7AMR7Eh1rtdwG1TZgyDO"}){const[u,d]=C.useState(a),[q,V]=C.useState(t),[f,v]=C.useState(null),[m,T]=C.useState(null),[S,b]=C.useState(!1),U=C.useCallback(h=>{d(h)},[]),L=C.useCallback(()=>{d(h=>!h)},[]),y=C.useCallback(async()=>{try{V(!0),T(null),b(!1);const h=await da.getAzureToken(c);if(h?.token&&h?.region){v(h),console.log("Azure token fetched:",h.region);const{SpeechRecognition:W}=GV({credentials:{region:h.region,authorizationToken:h.token}});KA.applyPolyfill(W),b(!0),console.log("Azure Speech Recognition registered successfully")}}catch(h){v(null),b(!1),T(h instanceof Error?h.message:"Failed to fetch Azure token"),console.error("Failed to fetch Azure token:",h)}finally{V(!1)}},[c]);C.useEffect(()=>{t&&y()},[t,y]);const{transcript:X,interimTranscript:Z,finalTranscript:J,listening:B,resetTranscript:D,browserSupportsSpeechRecognition:E,isMicrophoneAvailable:H}=yd(),G=C.useCallback(async h=>{const W=h?.language||e?.language||"th-TH",P=h?.continuous??e?.continuous??!0,K=h?.interimResults??e?.interimResults??!0;await KA.startListening({language:W,continuous:P,interimResults:K})},[e]),tA=C.useCallback(()=>{},[]),Y=C.useCallback(()=>{console.log("Abort Listening"),console.log("isAzureReady",S),console.log("Abort Listening Success")},[S]),z=C.useMemo(()=>({transcript:X,interimTranscript:Z,finalTranscript:J,isListening:B,browserSupportsSpeechRecognition:E,isMicrophoneAvailable:H,startListening:G,stopListening:tA,abortListening:Y,resetTranscript:D,isWidgetEnabled:u,setWidgetEnabled:U,toggleWidget:L,azureToken:f,isAzureReady:S,azureError:m,apiKey:c}),[X,Z,J,B,E,H,G,tA,Y,D,u,U,L,f,S,m,c]);return g.jsxs(wu.Provider,{value:z,children:[A,t&&q&&g.jsx(ds,{fullscreen:!0}),t&&!q&&g.jsx(Ku,{apiKey:c,enabled:u,position:n,config:e,zIndex:s,modalTitle:i,generateButtonText:r,onGenerate:p,onGenerateComplete:o,onGenerateError:l,abortListening:Y,startListening:G,stopListening:tA,resetTranscript:D,transcript:X,isListening:B,browserSupportsSpeechRecognition:E,isMicrophoneAvailable:H})]})}function zm(){const A=C.useContext(wu);if(!A)throw new Error("useSpeechContext must be used within a SpeechProvider");return A}const Wm={sm:60,md:100,lg:140},Cu={button:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",border:"none",borderRadius:"50%",cursor:"pointer",transition:"all 0.2s ease",background:"transparent",padding:0},disabled:{opacity:.5,cursor:"not-allowed"}},Lm=()=>g.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:"32",height:"32",children:[g.jsx("path",{d:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm-1-9c0-.55.45-1 1-1s1 .45 1 1v6c0 .55-.45 1-1 1s-1-.45-1-1V5z"}),g.jsx("path",{d:"M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"})]}),Om=()=>g.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:"32",height:"32",children:g.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})});function gm({isListening:A,onStart:e,onStop:t,disabled:a=!1,className:n,style:s,startIcon:i,stopIcon:r,startLabel:p,stopLabel:o,size:l="md",useAssets:c=!0}){const u=()=>{a||(A?t():e())},d=Wm[l],q={...Cu.button,width:d,height:d,...a&&Cu.disabled,filter:c?"drop-shadow(0 4px 12px rgba(255, 122, 0, 0.4))":void 0,...s};return c?g.jsx("button",{type:"button",onClick:u,disabled:a,className:n,style:q,"aria-label":A?"Stop recording":"Start recording",children:g.jsx("img",{src:A?Gc:Bc,alt:A?"Stop":"Start",style:{width:"100%",height:"100%"}})}):g.jsx("button",{type:"button",onClick:u,disabled:a,className:n,style:{...q,background:A?"linear-gradient(135deg, #ef4444 0%, #dc2626 100%)":"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",color:"white",boxShadow:A?"0 10px 40px rgba(239, 68, 68, 0.4)":"0 10px 40px rgba(102, 126, 234, 0.4)"},"aria-label":A?"Stop recording":"Start recording",children:g.jsxs("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"4px"},children:[A?r||g.jsx(Om,{}):i||g.jsx(Lm,{}),(p||o)&&g.jsx("span",{style:{fontSize:l==="sm"?"10px":l==="md"?"12px":"14px"},children:A?o||"Stop":p||"Start"})]})})}const Ne={container:{width:"100%"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"12px"},title:{fontSize:"18px",fontWeight:600,margin:0},resetButton:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 16px",borderRadius:"8px",border:"1px solid #374151",background:"transparent",color:"#9ca3af",fontSize:"14px",cursor:"pointer"},box:{background:"rgba(255, 255, 255, 0.03)",border:"1px solid #374151",borderRadius:"16px",padding:"24px",minHeight:"150px",overflowY:"auto"},text:{fontSize:"18px",lineHeight:1.75,margin:0,wordWrap:"break-word"},placeholder:{color:"#6b7280",fontSize:"16px",textAlign:"center",margin:0,padding:"32px 0"}},Xm=()=>g.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:"16",height:"16",children:g.jsx("path",{d:"M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"})});function Km({transcript:A,placeholder:e="Click the microphone to start speaking...",isListening:t=!1,className:a,style:n,onReset:s,showResetButton:i=!0,maxHeight:r="300px"}){const p={...Ne.box,maxHeight:r,...n};return g.jsxs("div",{className:a,style:Ne.container,children:[g.jsxs("div",{style:Ne.header,children:[g.jsx("h2",{style:Ne.title,children:"📝 Transcript"}),i&&s&&g.jsxs("button",{type:"button",onClick:s,disabled:!A,style:{...Ne.resetButton,opacity:A?1:.5,cursor:A?"pointer":"not-allowed"},children:[g.jsx(Xm,{}),"Clear"]})]}),g.jsx("div",{style:p,children:A?g.jsx("p",{style:Ne.text,children:A}):g.jsx("p",{style:Ne.placeholder,children:t?"🎧 Listening... Speak now!":e})})]})}function Pm(){return typeof window>"u"?!1:!!(window.SpeechRecognition||window.webkitSpeechRecognition)}function wm(){return typeof window>"u"?null:window.SpeechRecognition||window.webkitSpeechRecognition||null}async function Cm(){try{return(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop()),!0}catch{return!1}}async function xm(){try{return(await navigator.mediaDevices.enumerateDevices()).some(e=>e.kind==="audioinput")}catch{return!1}}function Zm(){return["th-TH","en-US","en-GB","en-AU","zh-CN","zh-TW","ja-JP","ko-KR","vi-VN","id-ID","ms-MY","fr-FR","de-DE","es-ES","pt-BR","ru-RU","ar-SA","hi-IN"]}function Jm(A){return`${Math.round(A*100)}%`}I.ApiError=us,I.LoadingStars=ds,I.SpeechApiService=da,I.SpeechButton=gm,I.SpeechModal=Rc,I.SpeechProvider=ym,I.SpeechWidget=Ku,I.TranscriptDisplay=Km,I.formatConfidence=Jm,I.getSpeechRecognition=wm,I.getSupportedLanguages=Zm,I.isMicrophoneAvailable=xm,I.isSpeechRecognitionSupported=Pm,I.requestMicrophonePermission=Cm,I.useAudioVisualizer=hs,I.useSpeechContext=zm,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}));
183
183
  //# sourceMappingURL=speech-recognition-sdk.umd.js.map