import{S as ll,i as al,s as ol,e as a,k as h,w as b,t as n,M as rl,c as o,d as t,m as f,a as r,x as M,h as i,b as c,G as s,g as p,y as J,q as T,o as $,B as _,v as nl}from"../../chunks/vendor-hf-doc-builder.js";import{T as sl}from"../../chunks/Tip-hf-doc-builder.js";import{I as $t}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as de}from"../../chunks/CodeBlock-hf-doc-builder.js";function il(we){let u,U,d,m,v;return{c(){u=a("p"),U=n("This tutorial will be written as an ES module, but you can easily adapt it to use CommonJS instead. For more information, see the "),d=a("a"),m=n("node tutorial"),v=n("."),this.h()},l(w){u=o(w,"P",{});var y=r(u);U=i(y,"This tutorial will be written as an ES module, but you can easily adapt it to use CommonJS instead. For more information, see the "),d=o(y,"A",{href:!0,rel:!0});var E=r(d);m=i(E,"node tutorial"),E.forEach(t),v=i(y,"."),y.forEach(t),this.h()},h(){c(d,"href","https://huggingface.co/docs/transformers.js/tutorials/node"),c(d,"rel","nofollow")},m(w,y){p(w,u,y),s(u,U),s(u,d),s(d,m),s(u,v)},d(w){w&&t(u)}}}function pl(we){let u,U,d,m,v,w,y,E;return{c(){u=a("p"),U=n("Remember to add "),d=a("code"),m=n('"type": "module"'),v=n(" to your "),w=a("code"),y=n("package.json"),E=n(" to indicate that your project uses ECMAScript modules.")},l(G){u=o(G,"P",{});var j=r(u);U=i(j,"Remember to add "),d=o(j,"CODE",{});var g=r(d);m=i(g,'"type": "module"'),g.forEach(t),v=i(j," to your "),w=o(j,"CODE",{});var me=r(w);y=i(me,"package.json"),me.forEach(t),E=i(j," to indicate that your project uses ECMAScript modules."),j.forEach(t)},m(G,j){p(G,u,j),s(u,U),s(u,d),s(d,m),s(u,v),s(u,w),s(w,y),s(u,E)},d(G){G&&t(u)}}}function cl(we){let u,U,d,m,v,w,y,E,G,j,g,me,z,_t,Ut,Re,I,Et,H,It,gt,L,Ue,kt,Zt,Ee,Gt,Wt,Pe,N,Qe,ye,Ie,At,Ve,x,ge,D,Bt,Nt,ke,q,xt,ze,W,S,Ze,K,St,Ge,Ct,He,C,ve,O,Yt,Xt,Ft,je,ee,Rt,Pt,Le,A,Y,We,te,Qt,Ae,Vt,De,X,zt,se,Ht,Lt,qe,le,Ke,F,Oe,k,Dt,ae,Be,qt,Kt,Ne,Ot,es,et,oe,tt,B,R,xe,re,ts,Se,ss,st,P,ls,Ce,as,os,lt,ne,at,Z,rs,Ye,ns,is,ie,ps,cs,ot,pe,rt,be,hs,nt,ce,it,Me,fs,pt,he,ct,Q,us,Xe,ds,ws,ht,Je,ms,ft,fe,ut,Te,ys,dt;return w=new $t({}),N=new sl({props:{$$slots:{default:[il]},$$scope:{ctx:we}}}),K=new $t({}),te=new $t({}),le=new de({props:{code:"bnBtJTIwaW5pdCUyMC15JTBBbnBtJTIwaSUyMCU0MHhlbm92YSUyRnRyYW5zZm9ybWVycw==",highlighted:`npm init -y
npm i @xenova/transformers`}}),F=new sl({props:{$$slots:{default:[pl]},$$scope:{ctx:we}}}),oe=new de({props:{code:"bnBtJTIwaSUyMHdhdmVmaWxl",highlighted:"npm i wavefile"}}),re=new $t({}),ne=new de({props:{code:"aW1wb3J0JTIwJTdCJTIwcGlwZWxpbmUlMjAlN0QlMjBmcm9tJTIwJyU0MHhlbm92YSUyRnRyYW5zZm9ybWVycyclM0IlMEFpbXBvcnQlMjB3YXZlZmlsZSUyMGZyb20lMjAnd2F2ZWZpbGUnJTNC",highlighted:`<span class="hljs-keyword">import</span> { pipeline } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@xenova/transformers&#x27;</span>;
<span class="hljs-keyword">import</span> wavefile <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;wavefile&#x27;</span>;`}}),pe=new de({props:{code:"bGV0JTIwdHJhbnNjcmliZXIlMjAlM0QlMjBhd2FpdCUyMHBpcGVsaW5lKCdhdXRvbWF0aWMtc3BlZWNoLXJlY29nbml0aW9uJyUyQyUyMCdYZW5vdmElMkZ3aGlzcGVyLXRpbnkuZW4nKSUzQg==",highlighted:'<span class="hljs-keyword">let</span> transcriber = <span class="hljs-keyword">await</span> <span class="hljs-title function_">pipeline</span>(<span class="hljs-string">&#x27;automatic-speech-recognition&#x27;</span>, <span class="hljs-string">&#x27;Xenova/whisper-tiny.en&#x27;</span>);'}}),ce=new de({props:{code:"JTJGJTJGJTIwTG9hZCUyMGF1ZGlvJTIwZGF0YSUwQWxldCUyMHVybCUyMCUzRCUyMCdodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZYZW5vdmElMkZ0cmFuc2Zvcm1lcnMuanMtZG9jcyUyRnJlc29sdmUlMkZtYWluJTJGamZrLndhdiclM0IlMEFsZXQlMjBidWZmZXIlMjAlM0QlMjBCdWZmZXIuZnJvbShhd2FpdCUyMGZldGNoKHVybCkudGhlbih4JTIwJTNEJTNFJTIweC5hcnJheUJ1ZmZlcigpKSklMEElMEElMkYlMkYlMjBSZWFkJTIwLndhdiUyMGZpbGUlMjBhbmQlMjBjb252ZXJ0JTIwaXQlMjB0byUyMHJlcXVpcmVkJTIwZm9ybWF0JTBBbGV0JTIwd2F2JTIwJTNEJTIwbmV3JTIwd2F2ZWZpbGUuV2F2ZUZpbGUoYnVmZmVyKSUzQiUwQXdhdi50b0JpdERlcHRoKCczMmYnKSUzQiUyMCUyRiUyRiUyMFBpcGVsaW5lJTIwZXhwZWN0cyUyMGlucHV0JTIwYXMlMjBhJTIwRmxvYXQzMkFycmF5JTBBd2F2LnRvU2FtcGxlUmF0ZSgxNjAwMCklM0IlMjAlMkYlMkYlMjBXaGlzcGVyJTIwZXhwZWN0cyUyMGF1ZGlvJTIwd2l0aCUyMGElMjBzYW1wbGluZyUyMHJhdGUlMjBvZiUyMDE2MDAwJTBBbGV0JTIwYXVkaW9EYXRhJTIwJTNEJTIwd2F2LmdldFNhbXBsZXMoKSUzQiUwQWlmJTIwKEFycmF5LmlzQXJyYXkoYXVkaW9EYXRhKSklMjAlN0IlMEElMjAlMjAlMjAlMjAlMkYlMkYlMjBGb3IlMjB0aGlzJTIwZGVtbyUyQyUyMGlmJTIwdGhlcmUlMjBhcmUlMjBtdWx0aXBsZSUyMGNoYW5uZWxzJTIwZm9yJTIwdGhlJTIwYXVkaW8lMjBmaWxlJTJDJTIwd2UlMjBqdXN0JTIwc2VsZWN0JTIwdGhlJTIwZmlyc3QlMjBvbmUuJTBBJTIwJTIwJTIwJTIwJTJGJTJGJTIwSW4lMjBwcmFjdGljZSUyQyUyMHlvdSdkJTIwcHJvYmFibHklMjB3YW50JTIwdG8lMjBjb252ZXJ0JTIwYWxsJTIwY2hhbm5lbHMlMjB0byUyMGElMjBzaW5nbGUlMjBjaGFubmVsJTIwKGUuZy4lMkMlMjBzdGVyZW8lMjAtJTNFJTIwbW9ubykuJTBBJTIwJTIwJTIwJTIwYXVkaW9EYXRhJTIwJTNEJTIwYXVkaW9EYXRhJTVCMCU1RCUzQiUwQSU3RA==",highlighted:`<span class="hljs-comment">// Load audio data</span>
<span class="hljs-keyword">let</span> url = <span class="hljs-string">&#x27;https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav&#x27;</span>;
<span class="hljs-keyword">let</span> buffer = <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-keyword">await</span> <span class="hljs-title function_">fetch</span>(url).<span class="hljs-title function_">then</span>(<span class="hljs-function"><span class="hljs-params">x</span> =&gt;</span> x.<span class="hljs-title function_">arrayBuffer</span>()))

<span class="hljs-comment">// Read .wav file and convert it to required format</span>
<span class="hljs-keyword">let</span> wav = <span class="hljs-keyword">new</span> wavefile.<span class="hljs-title class_">WaveFile</span>(buffer);
wav.<span class="hljs-title function_">toBitDepth</span>(<span class="hljs-string">&#x27;32f&#x27;</span>); <span class="hljs-comment">// Pipeline expects input as a Float32Array</span>
wav.<span class="hljs-title function_">toSampleRate</span>(<span class="hljs-number">16000</span>); <span class="hljs-comment">// Whisper expects audio with a sampling rate of 16000</span>
<span class="hljs-keyword">let</span> audioData = wav.<span class="hljs-title function_">getSamples</span>();
<span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(audioData)) {
    <span class="hljs-comment">// For this demo, if there are multiple channels for the audio file, we just select the first one.</span>
    <span class="hljs-comment">// In practice, you&#x27;d probably want to convert all channels to a single channel (e.g., stereo -&gt; mono).</span>
    audioData = audioData[<span class="hljs-number">0</span>];
}`}}),he=new de({props:{code:"bGV0JTIwc3RhcnQlMjAlM0QlMjBwZXJmb3JtYW5jZS5ub3coKSUzQiUwQWxldCUyMG91dHB1dCUyMCUzRCUyMGF3YWl0JTIwdHJhbnNjcmliZXIoYXVkaW9EYXRhKSUzQiUwQWxldCUyMGVuZCUyMCUzRCUyMHBlcmZvcm1hbmNlLm5vdygpJTNCJTBBY29uc29sZS5sb2coJTYwRXhlY3V0aW9uJTIwZHVyYXRpb24lM0ElMjAlMjQlN0IoZW5kJTIwLSUyMHN0YXJ0KSUyMCUyRiUyMDEwMDAlN0QlMjBzZWNvbmRzJTYwKSUzQiUwQWNvbnNvbGUubG9nKG91dHB1dCklM0I=",highlighted:`<span class="hljs-keyword">let</span> start = performance.<span class="hljs-title function_">now</span>();
<span class="hljs-keyword">let</span> output = <span class="hljs-keyword">await</span> <span class="hljs-title function_">transcriber</span>(audioData);
<span class="hljs-keyword">let</span> end = performance.<span class="hljs-title function_">now</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">\`Execution duration: <span class="hljs-subst">\${(end - start) / <span class="hljs-number">1000</span>}</span> seconds\`</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(output);`}}),fe=new de({props:{code:"RXhlY3V0aW9uJTIwZHVyYXRpb24lM0ElMjAwLjY0NjAzMTc5OTk3MjA1NzQlMjBzZWNvbmRzJTBBJTdCJTBBJTIwJTIwdGV4dCUzQSUyMCclMjBBbmQlMjBzbyUyMG15JTIwZmVsbG93JTIwQW1lcmljYW5zJTIwYXNrJTIwbm90JTIwd2hhdCUyMHlvdXIlMjBjb3VudHJ5JTIwY2FuJTIwZG8lMjBmb3IlMjB5b3UuJTIwQXNrJTIwd2hhdCUyMHlvdSUyMGNhbiUyMGRvJTIwZm9yJTIweW91ciUyMGNvdW50cnkuJyUwQSU3RA==",highlighted:`Execution duration: <span class="hljs-number">0.6460317999720574</span> seconds
{
  text: &#x27; And so my fellow Americans ask not what your country can <span class="hljs-keyword">do</span> <span class="hljs-keyword">for</span> <span class="hljs-title class_">you</span>. Ask what you can <span class="hljs-keyword">do</span> <span class="hljs-keyword">for</span> <span class="hljs-title class_">your</span> country.&#x27;
}`}}),{c(){u=a("meta"),U=h(),d=a("h1"),m=a("a"),v=a("span"),b(w.$$.fragment),y=h(),E=a("span"),G=n("Server-side Audio Processing in Node.js"),j=h(),g=a("p"),me=n("A major benefit of writing code for the web is that you can access the multitude of APIs that are available in modern browsers. Unfortunately, when writing server-side code, we are not afforded such luxury, so we have to find another way. In this tutorial, we will design a simple Node.js application that uses Transformers.js for speech recognition with "),z=a("a"),_t=n("Whisper"),Ut=n(", and in the process, learn how to process audio on the server."),Re=h(),I=a("p"),Et=n("The main problem we need to solve is that the "),H=a("a"),It=n("Web Audio API"),gt=n(" is not available in Node.js, meaning we can\u2019t use the "),L=a("a"),Ue=a("code"),kt=n("AudioContext"),Zt=n(" class to process audio. So, we will need to install third-party libraries to obtain the raw audio data. For this example, we will only consider "),Ee=a("code"),Gt=n(".wav"),Wt=n(" files, but the same principles apply to other audio formats."),Pe=h(),b(N.$$.fragment),Qe=h(),ye=a("p"),Ie=a("strong"),At=n("Useful links:"),Ve=h(),x=a("ul"),ge=a("li"),D=a("a"),Bt=n("Source code"),Nt=h(),ke=a("li"),q=a("a"),xt=n("Documentation"),ze=h(),W=a("h2"),S=a("a"),Ze=a("span"),b(K.$$.fragment),St=h(),Ge=a("span"),Ct=n("Prerequisites"),He=h(),C=a("ul"),ve=a("li"),O=a("a"),Yt=n("Node.js"),Xt=n(" version 16+"),Ft=h(),je=a("li"),ee=a("a"),Rt=n("npm"),Pt=n(" version 7+"),Le=h(),A=a("h2"),Y=a("a"),We=a("span"),b(te.$$.fragment),Qt=h(),Ae=a("span"),Vt=n("Getting started"),De=h(),X=a("p"),zt=n("Let\u2019s start by creating a new Node.js project and installing Transformers.js via "),se=a("a"),Ht=n("NPM"),Lt=n(":"),qe=h(),b(le.$$.fragment),Ke=h(),b(F.$$.fragment),Oe=h(),k=a("p"),Dt=n("Next, let\u2019s install the "),ae=a("a"),Be=a("code"),qt=n("wavefile"),Kt=n(" package, which we will use for loading "),Ne=a("code"),Ot=n(".wav"),es=n(" files:"),et=h(),b(oe.$$.fragment),tt=h(),B=a("h2"),R=a("a"),xe=a("span"),b(re.$$.fragment),ts=h(),Se=a("span"),ss=n("Creating the application"),st=h(),P=a("p"),ls=n("Start by creating a new file called "),Ce=a("code"),as=n("index.js"),os=n(", which will be the entry point for our application. Let\u2019s also import the necessary modules:"),lt=h(),b(ne.$$.fragment),at=h(),Z=a("p"),rs=n("For this tutorial, we will use the "),Ye=a("code"),ns=n("Xenova/whisper-tiny.en"),is=n(" model, but feel free to choose one of the other whisper models from the "),ie=a("a"),ps=n("Hugging Face Hub"),cs=n(". Let\u2019s create our pipeline with:"),ot=h(),b(pe.$$.fragment),rt=h(),be=a("p"),hs=n("Next, let\u2019s load an audio file and convert it to the format required by Transformers.js:"),nt=h(),b(ce.$$.fragment),it=h(),Me=a("p"),fs=n("Finally, let\u2019s run the model and measure execution duration."),pt=h(),b(he.$$.fragment),ct=h(),Q=a("p"),us=n("You can now run the application with "),Xe=a("code"),ds=n("node index.js"),ws=n(". Note that when running the script for the first time, it may take a while to download and cache the model. Subsequent requests will use the cached model, and model loading will be much faster."),ht=h(),Je=a("p"),ms=n("You should see output similar to:"),ft=h(),b(fe.$$.fragment),ut=h(),Te=a("p"),ys=n("That\u2019s it! You\u2019ve successfully created a Node.js application that uses Transformers.js for speech recognition with Whisper. You can now use this as a starting point for your own applications."),this.h()},l(e){const l=rl('[data-svelte="svelte-1phssyn"]',document.head);u=o(l,"META",{name:!0,content:!0}),l.forEach(t),U=f(e),d=o(e,"H1",{class:!0});var ue=r(d);m=o(ue,"A",{id:!0,class:!0,href:!0});var Fe=r(m);v=o(Fe,"SPAN",{});var bs=r(v);M(w.$$.fragment,bs),bs.forEach(t),Fe.forEach(t),y=f(ue),E=o(ue,"SPAN",{});var Ms=r(E);G=i(Ms,"Server-side Audio Processing in Node.js"),Ms.forEach(t),ue.forEach(t),j=f(e),g=o(e,"P",{});var wt=r(g);me=i(wt,"A major benefit of writing code for the web is that you can access the multitude of APIs that are available in modern browsers. Unfortunately, when writing server-side code, we are not afforded such luxury, so we have to find another way. In this tutorial, we will design a simple Node.js application that uses Transformers.js for speech recognition with "),z=o(wt,"A",{href:!0,rel:!0});var Js=r(z);_t=i(Js,"Whisper"),Js.forEach(t),Ut=i(wt,", and in the process, learn how to process audio on the server."),wt.forEach(t),Re=f(e),I=o(e,"P",{});var V=r(I);Et=i(V,"The main problem we need to solve is that the "),H=o(V,"A",{href:!0,rel:!0});var Ts=r(H);It=i(Ts,"Web Audio API"),Ts.forEach(t),gt=i(V," is not available in Node.js, meaning we can\u2019t use the "),L=o(V,"A",{href:!0,rel:!0});var $s=r(L);Ue=o($s,"CODE",{});var _s=r(Ue);kt=i(_s,"AudioContext"),_s.forEach(t),$s.forEach(t),Zt=i(V," class to process audio. So, we will need to install third-party libraries to obtain the raw audio data. For this example, we will only consider "),Ee=o(V,"CODE",{});var Us=r(Ee);Gt=i(Us,".wav"),Us.forEach(t),Wt=i(V," files, but the same principles apply to other audio formats."),V.forEach(t),Pe=f(e),M(N.$$.fragment,e),Qe=f(e),ye=o(e,"P",{});var Es=r(ye);Ie=o(Es,"STRONG",{});var Is=r(Ie);At=i(Is,"Useful links:"),Is.forEach(t),Es.forEach(t),Ve=f(e),x=o(e,"UL",{});var mt=r(x);ge=o(mt,"LI",{});var gs=r(ge);D=o(gs,"A",{href:!0,rel:!0});var ks=r(D);Bt=i(ks,"Source code"),ks.forEach(t),gs.forEach(t),Nt=f(mt),ke=o(mt,"LI",{});var Zs=r(ke);q=o(Zs,"A",{href:!0,rel:!0});var Gs=r(q);xt=i(Gs,"Documentation"),Gs.forEach(t),Zs.forEach(t),mt.forEach(t),ze=f(e),W=o(e,"H2",{class:!0});var yt=r(W);S=o(yt,"A",{id:!0,class:!0,href:!0});var Ws=r(S);Ze=o(Ws,"SPAN",{});var As=r(Ze);M(K.$$.fragment,As),As.forEach(t),Ws.forEach(t),St=f(yt),Ge=o(yt,"SPAN",{});var Bs=r(Ge);Ct=i(Bs,"Prerequisites"),Bs.forEach(t),yt.forEach(t),He=f(e),C=o(e,"UL",{});var vt=r(C);ve=o(vt,"LI",{});var vs=r(ve);O=o(vs,"A",{href:!0,rel:!0});var Ns=r(O);Yt=i(Ns,"Node.js"),Ns.forEach(t),Xt=i(vs," version 16+"),vs.forEach(t),Ft=f(vt),je=o(vt,"LI",{});var js=r(je);ee=o(js,"A",{href:!0,rel:!0});var xs=r(ee);Rt=i(xs,"npm"),xs.forEach(t),Pt=i(js," version 7+"),js.forEach(t),vt.forEach(t),Le=f(e),A=o(e,"H2",{class:!0});var jt=r(A);Y=o(jt,"A",{id:!0,class:!0,href:!0});var Ss=r(Y);We=o(Ss,"SPAN",{});var Cs=r(We);M(te.$$.fragment,Cs),Cs.forEach(t),Ss.forEach(t),Qt=f(jt),Ae=o(jt,"SPAN",{});var Ys=r(Ae);Vt=i(Ys,"Getting started"),Ys.forEach(t),jt.forEach(t),De=f(e),X=o(e,"P",{});var bt=r(X);zt=i(bt,"Let\u2019s start by creating a new Node.js project and installing Transformers.js via "),se=o(bt,"A",{href:!0,rel:!0});var Xs=r(se);Ht=i(Xs,"NPM"),Xs.forEach(t),Lt=i(bt,":"),bt.forEach(t),qe=f(e),M(le.$$.fragment,e),Ke=f(e),M(F.$$.fragment,e),Oe=f(e),k=o(e,"P",{});var $e=r(k);Dt=i($e,"Next, let\u2019s install the "),ae=o($e,"A",{href:!0,rel:!0});var Fs=r(ae);Be=o(Fs,"CODE",{});var Rs=r(Be);qt=i(Rs,"wavefile"),Rs.forEach(t),Fs.forEach(t),Kt=i($e," package, which we will use for loading "),Ne=o($e,"CODE",{});var Ps=r(Ne);Ot=i(Ps,".wav"),Ps.forEach(t),es=i($e," files:"),$e.forEach(t),et=f(e),M(oe.$$.fragment,e),tt=f(e),B=o(e,"H2",{class:!0});var Mt=r(B);R=o(Mt,"A",{id:!0,class:!0,href:!0});var Qs=r(R);xe=o(Qs,"SPAN",{});var Vs=r(xe);M(re.$$.fragment,Vs),Vs.forEach(t),Qs.forEach(t),ts=f(Mt),Se=o(Mt,"SPAN",{});var zs=r(Se);ss=i(zs,"Creating the application"),zs.forEach(t),Mt.forEach(t),st=f(e),P=o(e,"P",{});var Jt=r(P);ls=i(Jt,"Start by creating a new file called "),Ce=o(Jt,"CODE",{});var Hs=r(Ce);as=i(Hs,"index.js"),Hs.forEach(t),os=i(Jt,", which will be the entry point for our application. Let\u2019s also import the necessary modules:"),Jt.forEach(t),lt=f(e),M(ne.$$.fragment,e),at=f(e),Z=o(e,"P",{});var _e=r(Z);rs=i(_e,"For this tutorial, we will use the "),Ye=o(_e,"CODE",{});var Ls=r(Ye);ns=i(Ls,"Xenova/whisper-tiny.en"),Ls.forEach(t),is=i(_e," model, but feel free to choose one of the other whisper models from the "),ie=o(_e,"A",{href:!0,rel:!0});var Ds=r(ie);ps=i(Ds,"Hugging Face Hub"),Ds.forEach(t),cs=i(_e,". Let\u2019s create our pipeline with:"),_e.forEach(t),ot=f(e),M(pe.$$.fragment,e),rt=f(e),be=o(e,"P",{});var qs=r(be);hs=i(qs,"Next, let\u2019s load an audio file and convert it to the format required by Transformers.js:"),qs.forEach(t),nt=f(e),M(ce.$$.fragment,e),it=f(e),Me=o(e,"P",{});var Ks=r(Me);fs=i(Ks,"Finally, let\u2019s run the model and measure execution duration."),Ks.forEach(t),pt=f(e),M(he.$$.fragment,e),ct=f(e),Q=o(e,"P",{});var Tt=r(Q);us=i(Tt,"You can now run the application with "),Xe=o(Tt,"CODE",{});var Os=r(Xe);ds=i(Os,"node index.js"),Os.forEach(t),ws=i(Tt,". Note that when running the script for the first time, it may take a while to download and cache the model. Subsequent requests will use the cached model, and model loading will be much faster."),Tt.forEach(t),ht=f(e),Je=o(e,"P",{});var el=r(Je);ms=i(el,"You should see output similar to:"),el.forEach(t),ft=f(e),M(fe.$$.fragment,e),ut=f(e),Te=o(e,"P",{});var tl=r(Te);ys=i(tl,"That\u2019s it! You\u2019ve successfully created a Node.js application that uses Transformers.js for speech recognition with Whisper. You can now use this as a starting point for your own applications."),tl.forEach(t),this.h()},h(){c(u,"name","hf:doc:metadata"),c(u,"content",JSON.stringify(hl)),c(m,"id","serverside-audio-processing-in-nodejs"),c(m,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(m,"href","#serverside-audio-processing-in-nodejs"),c(d,"class","relative group"),c(z,"href","https://huggingface.co/Xenova/whisper-tiny.en"),c(z,"rel","nofollow"),c(H,"href","https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API"),c(H,"rel","nofollow"),c(L,"href","https://developer.mozilla.org/en-US/docs/Web/API/AudioContext"),c(L,"rel","nofollow"),c(D,"href","https://github.com/xenova/transformers.js/tree/main/examples/node-audio-processing"),c(D,"rel","nofollow"),c(q,"href","https://huggingface.co/docs/transformers.js"),c(q,"rel","nofollow"),c(S,"id","prerequisites"),c(S,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(S,"href","#prerequisites"),c(W,"class","relative group"),c(O,"href","https://nodejs.org/en/"),c(O,"rel","nofollow"),c(ee,"href","https://www.npmjs.com/"),c(ee,"rel","nofollow"),c(Y,"id","getting-started"),c(Y,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(Y,"href","#getting-started"),c(A,"class","relative group"),c(se,"href","https://www.npmjs.com/package/@xenova/transformers"),c(se,"rel","nofollow"),c(ae,"href","https://www.npmjs.com/package/wavefile"),c(ae,"rel","nofollow"),c(R,"id","creating-the-application"),c(R,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(R,"href","#creating-the-application"),c(B,"class","relative group"),c(ie,"href","https://huggingface.co/models?library=transformers.js&search=whisper"),c(ie,"rel","nofollow")},m(e,l){s(document.head,u),p(e,U,l),p(e,d,l),s(d,m),s(m,v),J(w,v,null),s(d,y),s(d,E),s(E,G),p(e,j,l),p(e,g,l),s(g,me),s(g,z),s(z,_t),s(g,Ut),p(e,Re,l),p(e,I,l),s(I,Et),s(I,H),s(H,It),s(I,gt),s(I,L),s(L,Ue),s(Ue,kt),s(I,Zt),s(I,Ee),s(Ee,Gt),s(I,Wt),p(e,Pe,l),J(N,e,l),p(e,Qe,l),p(e,ye,l),s(ye,Ie),s(Ie,At),p(e,Ve,l),p(e,x,l),s(x,ge),s(ge,D),s(D,Bt),s(x,Nt),s(x,ke),s(ke,q),s(q,xt),p(e,ze,l),p(e,W,l),s(W,S),s(S,Ze),J(K,Ze,null),s(W,St),s(W,Ge),s(Ge,Ct),p(e,He,l),p(e,C,l),s(C,ve),s(ve,O),s(O,Yt),s(ve,Xt),s(C,Ft),s(C,je),s(je,ee),s(ee,Rt),s(je,Pt),p(e,Le,l),p(e,A,l),s(A,Y),s(Y,We),J(te,We,null),s(A,Qt),s(A,Ae),s(Ae,Vt),p(e,De,l),p(e,X,l),s(X,zt),s(X,se),s(se,Ht),s(X,Lt),p(e,qe,l),J(le,e,l),p(e,Ke,l),J(F,e,l),p(e,Oe,l),p(e,k,l),s(k,Dt),s(k,ae),s(ae,Be),s(Be,qt),s(k,Kt),s(k,Ne),s(Ne,Ot),s(k,es),p(e,et,l),J(oe,e,l),p(e,tt,l),p(e,B,l),s(B,R),s(R,xe),J(re,xe,null),s(B,ts),s(B,Se),s(Se,ss),p(e,st,l),p(e,P,l),s(P,ls),s(P,Ce),s(Ce,as),s(P,os),p(e,lt,l),J(ne,e,l),p(e,at,l),p(e,Z,l),s(Z,rs),s(Z,Ye),s(Ye,ns),s(Z,is),s(Z,ie),s(ie,ps),s(Z,cs),p(e,ot,l),J(pe,e,l),p(e,rt,l),p(e,be,l),s(be,hs),p(e,nt,l),J(ce,e,l),p(e,it,l),p(e,Me,l),s(Me,fs),p(e,pt,l),J(he,e,l),p(e,ct,l),p(e,Q,l),s(Q,us),s(Q,Xe),s(Xe,ds),s(Q,ws),p(e,ht,l),p(e,Je,l),s(Je,ms),p(e,ft,l),J(fe,e,l),p(e,ut,l),p(e,Te,l),s(Te,ys),dt=!0},p(e,[l]){const ue={};l&2&&(ue.$$scope={dirty:l,ctx:e}),N.$set(ue);const Fe={};l&2&&(Fe.$$scope={dirty:l,ctx:e}),F.$set(Fe)},i(e){dt||(T(w.$$.fragment,e),T(N.$$.fragment,e),T(K.$$.fragment,e),T(te.$$.fragment,e),T(le.$$.fragment,e),T(F.$$.fragment,e),T(oe.$$.fragment,e),T(re.$$.fragment,e),T(ne.$$.fragment,e),T(pe.$$.fragment,e),T(ce.$$.fragment,e),T(he.$$.fragment,e),T(fe.$$.fragment,e),dt=!0)},o(e){$(w.$$.fragment,e),$(N.$$.fragment,e),$(K.$$.fragment,e),$(te.$$.fragment,e),$(le.$$.fragment,e),$(F.$$.fragment,e),$(oe.$$.fragment,e),$(re.$$.fragment,e),$(ne.$$.fragment,e),$(pe.$$.fragment,e),$(ce.$$.fragment,e),$(he.$$.fragment,e),$(fe.$$.fragment,e),dt=!1},d(e){t(u),e&&t(U),e&&t(d),_(w),e&&t(j),e&&t(g),e&&t(Re),e&&t(I),e&&t(Pe),_(N,e),e&&t(Qe),e&&t(ye),e&&t(Ve),e&&t(x),e&&t(ze),e&&t(W),_(K),e&&t(He),e&&t(C),e&&t(Le),e&&t(A),_(te),e&&t(De),e&&t(X),e&&t(qe),_(le,e),e&&t(Ke),_(F,e),e&&t(Oe),e&&t(k),e&&t(et),_(oe,e),e&&t(tt),e&&t(B),_(re),e&&t(st),e&&t(P),e&&t(lt),_(ne,e),e&&t(at),e&&t(Z),e&&t(ot),_(pe,e),e&&t(rt),e&&t(be),e&&t(nt),_(ce,e),e&&t(it),e&&t(Me),e&&t(pt),_(he,e),e&&t(ct),e&&t(Q),e&&t(ht),e&&t(Je),e&&t(ft),_(fe,e),e&&t(ut),e&&t(Te)}}}const hl={local:"serverside-audio-processing-in-nodejs",sections:[{local:"prerequisites",title:"Prerequisites"},{local:"getting-started",title:"Getting started"},{local:"creating-the-application",title:"Creating the application"}],title:"Server-side Audio Processing in Node.js"};function fl(we){return nl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class yl extends ll{constructor(u){super();al(this,u,fl,cl,ol,{})}}export{yl as default,hl as metadata};
