import{S as aa,i as la,s as oa,e as l,k as h,w as J,t as r,M as na,c as o,d as s,m as f,a as n,x as M,h as i,b as c,G as t,g as p,y as T,q as b,o as U,B as $,v as ra}from"../../chunks/vendor-hf-doc-builder.js";import{T as ta}from"../../chunks/Tip-hf-doc-builder.js";import{I as Us}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as de}from"../../chunks/CodeBlock-hf-doc-builder.js";function ia(we){let u,E,d,m,j;return{c(){u=l("p"),E=r("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=l("a"),m=r("node tutorial"),j=r("."),this.h()},l(w){u=o(w,"P",{});var y=n(u);E=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 I=n(d);m=i(I,"node tutorial"),I.forEach(s),j=i(y,"."),y.forEach(s),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),t(u,E),t(u,d),t(d,m),t(u,j)},d(w){w&&s(u)}}}function pa(we){let u,E,d,m,j,w,y,I;return{c(){u=l("p"),E=r("Remember to add "),d=l("code"),m=r('"type": "module"'),j=r(" to your "),w=l("code"),y=r("package.json"),I=r(" to indicate that your project uses ECMAScript modules.")},l(A){u=o(A,"P",{});var v=n(u);E=i(v,"Remember to add "),d=o(v,"CODE",{});var k=n(d);m=i(k,'"type": "module"'),k.forEach(s),j=i(v," to your "),w=o(v,"CODE",{});var me=n(w);y=i(me,"package.json"),me.forEach(s),I=i(v," to indicate that your project uses ECMAScript modules."),v.forEach(s)},m(A,v){p(A,u,v),t(u,E),t(u,d),t(d,m),t(u,j),t(u,w),t(w,y),t(u,I)},d(A){A&&s(u)}}}function ca(we){let u,E,d,m,j,w,y,I,A,v,k,me,z,$s,Es,Qe,_,Is,H,_s,ks,D,Ee,Cs,gs,Ie,As,Ns,Fe,G,Ve,ye,_e,Bs,Pe,S,ke,L,Zs,Gs,Ce,q,Ss,ze,N,W,ge,K,Ws,Ae,xs,He,x,je,O,Ys,Rs,Xs,ve,ee,Qs,Fs,De,B,Y,Ne,se,Vs,Be,Ps,Le,R,zs,te,Hs,Ds,qe,ae,Ke,X,Oe,C,Ls,le,Ze,qs,Ks,Ge,Os,et,es,oe,ss,Z,Q,Se,ne,st,We,tt,ts,F,at,xe,lt,ot,as,re,ls,g,nt,Ye,rt,it,ie,pt,ct,os,pe,ns,Je,ht,rs,ce,is,Me,ft,ps,he,cs,V,ut,Re,dt,wt,hs,Te,mt,fs,fe,us,be,yt,ds;return w=new Us({}),G=new ta({props:{$$slots:{default:[ia]},$$scope:{ctx:we}}}),K=new Us({}),se=new Us({}),ae=new de({props:{code:"bnBtJTIwaW5pdCUyMC15JTBBbnBtJTIwaSUyMCU0MHhlbm92YSUyRnRyYW5zZm9ybWVycw==",highlighted:`npm init -y
npm i @xenova/transformers`}}),X=new ta({props:{$$slots:{default:[pa]},$$scope:{ctx:we}}}),oe=new de({props:{code:"bnBtJTIwaSUyMHdhdmVmaWxl",highlighted:"npm i wavefile"}}),ne=new Us({}),re=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:"JTJGJTJGJTIwTG9hZCUyMGF1ZGlvJTIwZGF0YSUwQWxldCUyMHVybCUyMCUzRCUyMCdodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZYZW5vdmElMkZ0cmFuc2Zvcm1lcnMuanMtZG9jcyUyRnJlc29sdmUlMkZtYWluJTJGamZrLndhdiclM0IlMEFsZXQlMjBidWZmZXIlMjAlM0QlMjBCdWZmZXIuZnJvbShhd2FpdCUyMGZldGNoKHVybCkudGhlbih4JTIwJTNEJTNFJTIweC5hcnJheUJ1ZmZlcigpKSklMEElMEElMkYlMkYlMjBSZWFkJTIwLndhdiUyMGZpbGUlMjBhbmQlMjBjb252ZXJ0JTIwaXQlMjB0byUyMHJlcXVpcmVkJTIwZm9ybWF0JTBBbGV0JTIwd2F2JTIwJTNEJTIwbmV3JTIwd2F2ZWZpbGUuV2F2ZUZpbGUoYnVmZmVyKSUzQiUwQXdhdi50b0JpdERlcHRoKCczMmYnKSUzQiUyMCUyRiUyRiUyMFBpcGVsaW5lJTIwZXhwZWN0cyUyMGlucHV0JTIwYXMlMjBhJTIwRmxvYXQzMkFycmF5JTBBd2F2LnRvU2FtcGxlUmF0ZSgxNjAwMCklM0IlMjAlMkYlMkYlMjBXaGlzcGVyJTIwZXhwZWN0cyUyMGF1ZGlvJTIwd2l0aCUyMGElMjBzYW1wbGluZyUyMHJhdGUlMjBvZiUyMDE2MDAwJTBBbGV0JTIwYXVkaW9EYXRhJTIwJTNEJTIwd2F2LmdldFNhbXBsZXMoKSUzQiUwQWlmJTIwKEFycmF5LmlzQXJyYXkoYXVkaW9EYXRhKSklMjAlN0IlMEElMjAlMjBpZiUyMChhdWRpb0RhdGEubGVuZ3RoJTIwJTNFJTIwMSklMjAlN0IlMEElMjAlMjAlMjAlMjBjb25zdCUyMFNDQUxJTkdfRkFDVE9SJTIwJTNEJTIwTWF0aC5zcXJ0KDIpJTNCJTBBJTBBJTIwJTIwJTIwJTIwJTJGJTJGJTIwTWVyZ2UlMjBjaGFubmVscyUyMChpbnRvJTIwZmlyc3QlMjBjaGFubmVsJTIwdG8lMjBzYXZlJTIwbWVtb3J5KSUwQSUyMCUyMCUyMCUyMGZvciUyMChsZXQlMjBpJTIwJTNEJTIwMCUzQiUyMGklMjAlM0MlMjBhdWRpb0RhdGElNUIwJTVELmxlbmd0aCUzQiUyMCUyQiUyQmkpJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwYXVkaW9EYXRhJTVCMCU1RCU1QmklNUQlMjAlM0QlMjBTQ0FMSU5HX0ZBQ1RPUiUyMColMjAoYXVkaW9EYXRhJTVCMCU1RCU1QmklNUQlMjAlMkIlMjBhdWRpb0RhdGElNUIxJTVEJTVCaSU1RCklMjAlMkYlMjAyJTNCJTBBJTIwJTIwJTIwJTIwJTdEJTBBJTIwJTIwJTdEJTBBJTBBJTIwJTIwJTJGJTJGJTIwU2VsZWN0JTIwZmlyc3QlMjBjaGFubmVsJTBBJTIwJTIwYXVkaW9EYXRhJTIwJTNEJTIwYXVkaW9EYXRhJTVCMCU1RCUzQiUwQSU3RA==",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-keyword">if</span> (audioData.<span class="hljs-property">length</span> &gt; <span class="hljs-number">1</span>) {
    <span class="hljs-keyword">const</span> <span class="hljs-variable constant_">SCALING_FACTOR</span> = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">sqrt</span>(<span class="hljs-number">2</span>);

    <span class="hljs-comment">// Merge channels (into first channel to save memory)</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; audioData[<span class="hljs-number">0</span>].<span class="hljs-property">length</span>; ++i) {
      audioData[<span class="hljs-number">0</span>][i] = <span class="hljs-variable constant_">SCALING_FACTOR</span> * (audioData[<span class="hljs-number">0</span>][i] + audioData[<span class="hljs-number">1</span>][i]) / <span class="hljs-number">2</span>;
    }
  }

  <span class="hljs-comment">// Select first channel</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=l("meta"),E=h(),d=l("h1"),m=l("a"),j=l("span"),J(w.$$.fragment),y=h(),I=l("span"),A=r("Server-side Audio Processing in Node.js"),v=h(),k=l("p"),me=r("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=l("a"),$s=r("Whisper"),Es=r(", and in the process, learn how to process audio on the server."),Qe=h(),_=l("p"),Is=r("The main problem we need to solve is that the "),H=l("a"),_s=r("Web Audio API"),ks=r(" is not available in Node.js, meaning we can\u2019t use the "),D=l("a"),Ee=l("code"),Cs=r("AudioContext"),gs=r(" 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 "),Ie=l("code"),As=r(".wav"),Ns=r(" files, but the same principles apply to other audio formats."),Fe=h(),J(G.$$.fragment),Ve=h(),ye=l("p"),_e=l("strong"),Bs=r("Useful links:"),Pe=h(),S=l("ul"),ke=l("li"),L=l("a"),Zs=r("Source code"),Gs=h(),Ce=l("li"),q=l("a"),Ss=r("Documentation"),ze=h(),N=l("h2"),W=l("a"),ge=l("span"),J(K.$$.fragment),Ws=h(),Ae=l("span"),xs=r("Prerequisites"),He=h(),x=l("ul"),je=l("li"),O=l("a"),Ys=r("Node.js"),Rs=r(" version 16+"),Xs=h(),ve=l("li"),ee=l("a"),Qs=r("npm"),Fs=r(" version 7+"),De=h(),B=l("h2"),Y=l("a"),Ne=l("span"),J(se.$$.fragment),Vs=h(),Be=l("span"),Ps=r("Getting started"),Le=h(),R=l("p"),zs=r("Let\u2019s start by creating a new Node.js project and installing Transformers.js via "),te=l("a"),Hs=r("NPM"),Ds=r(":"),qe=h(),J(ae.$$.fragment),Ke=h(),J(X.$$.fragment),Oe=h(),C=l("p"),Ls=r("Next, let\u2019s install the "),le=l("a"),Ze=l("code"),qs=r("wavefile"),Ks=r(" package, which we will use for loading "),Ge=l("code"),Os=r(".wav"),et=r(" files:"),es=h(),J(oe.$$.fragment),ss=h(),Z=l("h2"),Q=l("a"),Se=l("span"),J(ne.$$.fragment),st=h(),We=l("span"),tt=r("Creating the application"),ts=h(),F=l("p"),at=r("Start by creating a new file called "),xe=l("code"),lt=r("index.js"),ot=r(", which will be the entry point for our application. Let\u2019s also import the necessary modules:"),as=h(),J(re.$$.fragment),ls=h(),g=l("p"),nt=r("For this tutorial, we will use the "),Ye=l("code"),rt=r("Xenova/whisper-tiny.en"),it=r(" model, but feel free to choose one of the other whisper models from the "),ie=l("a"),pt=r("Hugging Face Hub"),ct=r(". Let\u2019s create our pipeline with:"),os=h(),J(pe.$$.fragment),ns=h(),Je=l("p"),ht=r("Next, let\u2019s load an audio file and convert it to the format required by Transformers.js:"),rs=h(),J(ce.$$.fragment),is=h(),Me=l("p"),ft=r("Finally, let\u2019s run the model and measure execution duration."),ps=h(),J(he.$$.fragment),cs=h(),V=l("p"),ut=r("You can now run the application with "),Re=l("code"),dt=r("node index.js"),wt=r(". 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."),hs=h(),Te=l("p"),mt=r("You should see output similar to:"),fs=h(),J(fe.$$.fragment),us=h(),be=l("p"),yt=r("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 a=na('[data-svelte="svelte-1phssyn"]',document.head);u=o(a,"META",{name:!0,content:!0}),a.forEach(s),E=f(e),d=o(e,"H1",{class:!0});var ue=n(d);m=o(ue,"A",{id:!0,class:!0,href:!0});var Xe=n(m);j=o(Xe,"SPAN",{});var Jt=n(j);M(w.$$.fragment,Jt),Jt.forEach(s),Xe.forEach(s),y=f(ue),I=o(ue,"SPAN",{});var Mt=n(I);A=i(Mt,"Server-side Audio Processing in Node.js"),Mt.forEach(s),ue.forEach(s),v=f(e),k=o(e,"P",{});var ws=n(k);me=i(ws,"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(ws,"A",{href:!0,rel:!0});var Tt=n(z);$s=i(Tt,"Whisper"),Tt.forEach(s),Es=i(ws,", and in the process, learn how to process audio on the server."),ws.forEach(s),Qe=f(e),_=o(e,"P",{});var P=n(_);Is=i(P,"The main problem we need to solve is that the "),H=o(P,"A",{href:!0,rel:!0});var bt=n(H);_s=i(bt,"Web Audio API"),bt.forEach(s),ks=i(P," is not available in Node.js, meaning we can\u2019t use the "),D=o(P,"A",{href:!0,rel:!0});var Ut=n(D);Ee=o(Ut,"CODE",{});var $t=n(Ee);Cs=i($t,"AudioContext"),$t.forEach(s),Ut.forEach(s),gs=i(P," 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 "),Ie=o(P,"CODE",{});var Et=n(Ie);As=i(Et,".wav"),Et.forEach(s),Ns=i(P," files, but the same principles apply to other audio formats."),P.forEach(s),Fe=f(e),M(G.$$.fragment,e),Ve=f(e),ye=o(e,"P",{});var It=n(ye);_e=o(It,"STRONG",{});var _t=n(_e);Bs=i(_t,"Useful links:"),_t.forEach(s),It.forEach(s),Pe=f(e),S=o(e,"UL",{});var ms=n(S);ke=o(ms,"LI",{});var kt=n(ke);L=o(kt,"A",{href:!0,rel:!0});var Ct=n(L);Zs=i(Ct,"Source code"),Ct.forEach(s),kt.forEach(s),Gs=f(ms),Ce=o(ms,"LI",{});var gt=n(Ce);q=o(gt,"A",{href:!0,rel:!0});var At=n(q);Ss=i(At,"Documentation"),At.forEach(s),gt.forEach(s),ms.forEach(s),ze=f(e),N=o(e,"H2",{class:!0});var ys=n(N);W=o(ys,"A",{id:!0,class:!0,href:!0});var Nt=n(W);ge=o(Nt,"SPAN",{});var Bt=n(ge);M(K.$$.fragment,Bt),Bt.forEach(s),Nt.forEach(s),Ws=f(ys),Ae=o(ys,"SPAN",{});var Zt=n(Ae);xs=i(Zt,"Prerequisites"),Zt.forEach(s),ys.forEach(s),He=f(e),x=o(e,"UL",{});var js=n(x);je=o(js,"LI",{});var jt=n(je);O=o(jt,"A",{href:!0,rel:!0});var Gt=n(O);Ys=i(Gt,"Node.js"),Gt.forEach(s),Rs=i(jt," version 16+"),jt.forEach(s),Xs=f(js),ve=o(js,"LI",{});var vt=n(ve);ee=o(vt,"A",{href:!0,rel:!0});var St=n(ee);Qs=i(St,"npm"),St.forEach(s),Fs=i(vt," version 7+"),vt.forEach(s),js.forEach(s),De=f(e),B=o(e,"H2",{class:!0});var vs=n(B);Y=o(vs,"A",{id:!0,class:!0,href:!0});var Wt=n(Y);Ne=o(Wt,"SPAN",{});var xt=n(Ne);M(se.$$.fragment,xt),xt.forEach(s),Wt.forEach(s),Vs=f(vs),Be=o(vs,"SPAN",{});var Yt=n(Be);Ps=i(Yt,"Getting started"),Yt.forEach(s),vs.forEach(s),Le=f(e),R=o(e,"P",{});var Js=n(R);zs=i(Js,"Let\u2019s start by creating a new Node.js project and installing Transformers.js via "),te=o(Js,"A",{href:!0,rel:!0});var Rt=n(te);Hs=i(Rt,"NPM"),Rt.forEach(s),Ds=i(Js,":"),Js.forEach(s),qe=f(e),M(ae.$$.fragment,e),Ke=f(e),M(X.$$.fragment,e),Oe=f(e),C=o(e,"P",{});var Ue=n(C);Ls=i(Ue,"Next, let\u2019s install the "),le=o(Ue,"A",{href:!0,rel:!0});var Xt=n(le);Ze=o(Xt,"CODE",{});var Qt=n(Ze);qs=i(Qt,"wavefile"),Qt.forEach(s),Xt.forEach(s),Ks=i(Ue," package, which we will use for loading "),Ge=o(Ue,"CODE",{});var Ft=n(Ge);Os=i(Ft,".wav"),Ft.forEach(s),et=i(Ue," files:"),Ue.forEach(s),es=f(e),M(oe.$$.fragment,e),ss=f(e),Z=o(e,"H2",{class:!0});var Ms=n(Z);Q=o(Ms,"A",{id:!0,class:!0,href:!0});var Vt=n(Q);Se=o(Vt,"SPAN",{});var Pt=n(Se);M(ne.$$.fragment,Pt),Pt.forEach(s),Vt.forEach(s),st=f(Ms),We=o(Ms,"SPAN",{});var zt=n(We);tt=i(zt,"Creating the application"),zt.forEach(s),Ms.forEach(s),ts=f(e),F=o(e,"P",{});var Ts=n(F);at=i(Ts,"Start by creating a new file called "),xe=o(Ts,"CODE",{});var Ht=n(xe);lt=i(Ht,"index.js"),Ht.forEach(s),ot=i(Ts,", which will be the entry point for our application. Let\u2019s also import the necessary modules:"),Ts.forEach(s),as=f(e),M(re.$$.fragment,e),ls=f(e),g=o(e,"P",{});var $e=n(g);nt=i($e,"For this tutorial, we will use the "),Ye=o($e,"CODE",{});var Dt=n(Ye);rt=i(Dt,"Xenova/whisper-tiny.en"),Dt.forEach(s),it=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 Lt=n(ie);pt=i(Lt,"Hugging Face Hub"),Lt.forEach(s),ct=i($e,". Let\u2019s create our pipeline with:"),$e.forEach(s),os=f(e),M(pe.$$.fragment,e),ns=f(e),Je=o(e,"P",{});var qt=n(Je);ht=i(qt,"Next, let\u2019s load an audio file and convert it to the format required by Transformers.js:"),qt.forEach(s),rs=f(e),M(ce.$$.fragment,e),is=f(e),Me=o(e,"P",{});var Kt=n(Me);ft=i(Kt,"Finally, let\u2019s run the model and measure execution duration."),Kt.forEach(s),ps=f(e),M(he.$$.fragment,e),cs=f(e),V=o(e,"P",{});var bs=n(V);ut=i(bs,"You can now run the application with "),Re=o(bs,"CODE",{});var Ot=n(Re);dt=i(Ot,"node index.js"),Ot.forEach(s),wt=i(bs,". 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."),bs.forEach(s),hs=f(e),Te=o(e,"P",{});var ea=n(Te);mt=i(ea,"You should see output similar to:"),ea.forEach(s),fs=f(e),M(fe.$$.fragment,e),us=f(e),be=o(e,"P",{});var sa=n(be);yt=i(sa,"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."),sa.forEach(s),this.h()},h(){c(u,"name","hf:doc:metadata"),c(u,"content",JSON.stringify(ha)),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(D,"href","https://developer.mozilla.org/en-US/docs/Web/API/AudioContext"),c(D,"rel","nofollow"),c(L,"href","https://github.com/xenova/transformers.js/tree/main/examples/node-audio-processing"),c(L,"rel","nofollow"),c(q,"href","https://huggingface.co/docs/transformers.js"),c(q,"rel","nofollow"),c(W,"id","prerequisites"),c(W,"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(W,"href","#prerequisites"),c(N,"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(B,"class","relative group"),c(te,"href","https://www.npmjs.com/package/@xenova/transformers"),c(te,"rel","nofollow"),c(le,"href","https://www.npmjs.com/package/wavefile"),c(le,"rel","nofollow"),c(Q,"id","creating-the-application"),c(Q,"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(Q,"href","#creating-the-application"),c(Z,"class","relative group"),c(ie,"href","https://huggingface.co/models?library=transformers.js&search=whisper"),c(ie,"rel","nofollow")},m(e,a){t(document.head,u),p(e,E,a),p(e,d,a),t(d,m),t(m,j),T(w,j,null),t(d,y),t(d,I),t(I,A),p(e,v,a),p(e,k,a),t(k,me),t(k,z),t(z,$s),t(k,Es),p(e,Qe,a),p(e,_,a),t(_,Is),t(_,H),t(H,_s),t(_,ks),t(_,D),t(D,Ee),t(Ee,Cs),t(_,gs),t(_,Ie),t(Ie,As),t(_,Ns),p(e,Fe,a),T(G,e,a),p(e,Ve,a),p(e,ye,a),t(ye,_e),t(_e,Bs),p(e,Pe,a),p(e,S,a),t(S,ke),t(ke,L),t(L,Zs),t(S,Gs),t(S,Ce),t(Ce,q),t(q,Ss),p(e,ze,a),p(e,N,a),t(N,W),t(W,ge),T(K,ge,null),t(N,Ws),t(N,Ae),t(Ae,xs),p(e,He,a),p(e,x,a),t(x,je),t(je,O),t(O,Ys),t(je,Rs),t(x,Xs),t(x,ve),t(ve,ee),t(ee,Qs),t(ve,Fs),p(e,De,a),p(e,B,a),t(B,Y),t(Y,Ne),T(se,Ne,null),t(B,Vs),t(B,Be),t(Be,Ps),p(e,Le,a),p(e,R,a),t(R,zs),t(R,te),t(te,Hs),t(R,Ds),p(e,qe,a),T(ae,e,a),p(e,Ke,a),T(X,e,a),p(e,Oe,a),p(e,C,a),t(C,Ls),t(C,le),t(le,Ze),t(Ze,qs),t(C,Ks),t(C,Ge),t(Ge,Os),t(C,et),p(e,es,a),T(oe,e,a),p(e,ss,a),p(e,Z,a),t(Z,Q),t(Q,Se),T(ne,Se,null),t(Z,st),t(Z,We),t(We,tt),p(e,ts,a),p(e,F,a),t(F,at),t(F,xe),t(xe,lt),t(F,ot),p(e,as,a),T(re,e,a),p(e,ls,a),p(e,g,a),t(g,nt),t(g,Ye),t(Ye,rt),t(g,it),t(g,ie),t(ie,pt),t(g,ct),p(e,os,a),T(pe,e,a),p(e,ns,a),p(e,Je,a),t(Je,ht),p(e,rs,a),T(ce,e,a),p(e,is,a),p(e,Me,a),t(Me,ft),p(e,ps,a),T(he,e,a),p(e,cs,a),p(e,V,a),t(V,ut),t(V,Re),t(Re,dt),t(V,wt),p(e,hs,a),p(e,Te,a),t(Te,mt),p(e,fs,a),T(fe,e,a),p(e,us,a),p(e,be,a),t(be,yt),ds=!0},p(e,[a]){const ue={};a&2&&(ue.$$scope={dirty:a,ctx:e}),G.$set(ue);const Xe={};a&2&&(Xe.$$scope={dirty:a,ctx:e}),X.$set(Xe)},i(e){ds||(b(w.$$.fragment,e),b(G.$$.fragment,e),b(K.$$.fragment,e),b(se.$$.fragment,e),b(ae.$$.fragment,e),b(X.$$.fragment,e),b(oe.$$.fragment,e),b(ne.$$.fragment,e),b(re.$$.fragment,e),b(pe.$$.fragment,e),b(ce.$$.fragment,e),b(he.$$.fragment,e),b(fe.$$.fragment,e),ds=!0)},o(e){U(w.$$.fragment,e),U(G.$$.fragment,e),U(K.$$.fragment,e),U(se.$$.fragment,e),U(ae.$$.fragment,e),U(X.$$.fragment,e),U(oe.$$.fragment,e),U(ne.$$.fragment,e),U(re.$$.fragment,e),U(pe.$$.fragment,e),U(ce.$$.fragment,e),U(he.$$.fragment,e),U(fe.$$.fragment,e),ds=!1},d(e){s(u),e&&s(E),e&&s(d),$(w),e&&s(v),e&&s(k),e&&s(Qe),e&&s(_),e&&s(Fe),$(G,e),e&&s(Ve),e&&s(ye),e&&s(Pe),e&&s(S),e&&s(ze),e&&s(N),$(K),e&&s(He),e&&s(x),e&&s(De),e&&s(B),$(se),e&&s(Le),e&&s(R),e&&s(qe),$(ae,e),e&&s(Ke),$(X,e),e&&s(Oe),e&&s(C),e&&s(es),$(oe,e),e&&s(ss),e&&s(Z),$(ne),e&&s(ts),e&&s(F),e&&s(as),$(re,e),e&&s(ls),e&&s(g),e&&s(os),$(pe,e),e&&s(ns),e&&s(Je),e&&s(rs),$(ce,e),e&&s(is),e&&s(Me),e&&s(ps),$(he,e),e&&s(cs),e&&s(V),e&&s(hs),e&&s(Te),e&&s(fs),$(fe,e),e&&s(us),e&&s(be)}}}const ha={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 fa(we){return ra(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ya extends aa{constructor(u){super();la(this,u,fa,ca,oa,{})}}export{ya as default,ha as metadata};
