import{s as At,n as Qt,o as Dt}from"../chunks/scheduler.f7e1785c.js";import{S as Ot,i as Kt,g as a,s as l,r,A as te,h as p,f as s,c as i,j as Xt,u as m,x as o,k as Yt,y as ee,a as n,v as u,d as f,t as y,w as c}from"../chunks/index.9f8f0838.js";import{C as h}from"../chunks/CodeBlock.b3510e34.js";import{H as se,E as ne}from"../chunks/EditOnGithub.5a9bb8c5.js";function le(jt){let d,A,X,Q,M,D,g,kt=`Automatic Speech Recognition (ASR) is a task that involves transcribing speech audio recording into text.
This task has numerous practical applications, from creating closed captions for videos to enabling voice commands
for virtual assistants like Siri and Alexa.`,O,w,It=`In this section, we’ll use the <code>automatic-speech-recognition</code> pipeline to transcribe an audio recording of a person
asking a question about paying a bill using the same MINDS-14 dataset as before.`,K,U,Gt=`To get started, load the dataset and upsample it to 16kHz as described in <a href="audio_classification_pipeline">Audio classification with a pipeline</a>,
if you haven’t done that yet.`,tt,$,Zt=`To transcribe an audio recording, we can use the <code>automatic-speech-recognition</code> pipeline from 🤗 Transformers. Let’s
instantiate the pipeline:`,et,b,st,T,Wt="Next, we’ll take an example from the dataset and pass its raw data to the pipeline:",nt,v,lt,C,qt="<strong>Output:</strong>",it,J,at,x,St="Let’s compare this output to what the actual transcription for this example is:",pt,j,ot,k,_t="<strong>Output:</strong>",rt,I,mt,G,Rt=`The model seems to have done a pretty good job at transcribing the audio! It only got one word wrong (“card”) compared
to the original transcription, which is pretty good considering the speaker has an Australian accent, where the letter “r”
is often silent. Having said that, I wouldn’t recommend trying to pay your next electricity bill with a fish!`,ut,Z,Bt=`By default, this pipeline uses a model trained for automatic speech recognition for English language, which is fine in
this example. If you’d like to try transcribing other subsets of MINDS-14 in different language, you can find a pre-trained
ASR model <a href="https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&amp;language=fr&amp;sort=downloads" rel="nofollow">on the 🤗 Hub</a>.
You can filter the models list by task first, then by language. Once you have found the model you like, pass it’s name as
the <code>model</code> argument to the pipeline.`,ft,W,Ht="Let’s try this for the German split of the MINDS-14. Load the “de-DE” subset:",yt,q,ct,S,Vt="Get an example and see what the transcription is supposed to be:",ht,_,dt,R,Lt="<strong>Output:</strong>",Mt,B,gt,H,Ft="Find a pre-trained ASR model for German language on the 🤗 Hub, instantiate a pipeline, and transcribe the example:",wt,V,Ut,L,Nt="<strong>Output:</strong>",$t,F,bt,N,zt="Also, stimmt’s!",Tt,z,Et=`When working on solving your own task, starting with a simple pipeline like the ones we’ve shown in this unit is a valuable
tool that offers several benefits:`,vt,E,Pt=`<li>a pre-trained model may exist that already solves your task really well, saving you plenty of time</li> <li>pipeline() takes care of all the pre/post-processing for you, so you don’t have to worry about getting the data into
the right format for a model</li> <li>if the result isn’t ideal, this still gives you a quick baseline for future fine-tuning</li> <li>once you fine-tune a model on your custom data and share it on Hub, the whole community will be able to use it quickly
and effortlessly via the <code>pipeline()</code> method making AI more accessible.</li>`,Ct,P,Jt,Y,xt;return M=new se({props:{title:"Automatic speech recognition with a pipeline",local:"automatic-speech-recognition-with-a-pipeline",headingTag:"h1"}}),b=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBYXNyJTIwJTNEJTIwcGlwZWxpbmUoJTIyYXV0b21hdGljLXNwZWVjaC1yZWNvZ25pdGlvbiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

asr = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>)`,wrap:!1}}),v=new h({props:{code:"ZXhhbXBsZSUyMCUzRCUyMG1pbmRzJTVCMCU1RCUwQWFzcihleGFtcGxlJTVCJTIyYXVkaW8lMjIlNUQlNUIlMjJhcnJheSUyMiU1RCk=",highlighted:`example = minds[<span class="hljs-number">0</span>]
asr(example[<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>])`,wrap:!1}}),J=new h({props:{code:"JTdCJTIydGV4dCUyMiUzQSUyMCUyMkklMjBXT1VMRCUyMExJS0UlMjBUTyUyMFBBWSUyME1ZJTIwRUxFQ1RSSUNJVFklMjBCSUxMJTIwVVNJTkclMjBNWSUyMENPRCUyMENBTiUyMFlPVSUyMFBMRUFTRSUyMEFTU0lTVCUyMiU3RA==",highlighted:'<span class="hljs-comment">{&quot;text&quot;: &quot;I WOULD LIKE TO PAY MY ELECTRICITY BILL USING MY COD CAN YOU PLEASE ASSIST&quot;}</span>',wrap:!1}}),j=new h({props:{code:"ZXhhbXBsZSU1QiUyMmVuZ2xpc2hfdHJhbnNjcmlwdGlvbiUyMiU1RA==",highlighted:'example[<span class="hljs-string">&quot;english_transcription&quot;</span>]',wrap:!1}}),I=new h({props:{code:"JTIySSUyMHdvdWxkJTIwbGlrZSUyMHRvJTIwcGF5JTIwbXklMjBlbGVjdHJpY2l0eSUyMGJpbGwlMjB1c2luZyUyMG15JTIwY2FyZCUyMGNhbiUyMHlvdSUyMHBsZWFzZSUyMGFzc2lzdCUyMg==",highlighted:'<span class="hljs-comment">&quot;I would like to pay my electricity bill using my card can you please assist&quot;</span>',wrap:!1}}),q=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwQXVkaW8lMEElMEFtaW5kcyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJQb2x5QUklMkZtaW5kczE0JTIyJTJDJTIwbmFtZSUzRCUyMmRlLURFJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEFtaW5kcyUyMCUzRCUyMG1pbmRzLmNhc3RfY29sdW1uKCUyMmF1ZGlvJTIyJTJDJTIwQXVkaW8oc2FtcGxpbmdfcmF0ZSUzRDE2XzAwMCkp",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Audio

minds = load_dataset(<span class="hljs-string">&quot;PolyAI/minds14&quot;</span>, name=<span class="hljs-string">&quot;de-DE&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
minds = minds.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=<span class="hljs-number">16_000</span>))`,wrap:!1}}),_=new h({props:{code:"ZXhhbXBsZSUyMCUzRCUyMG1pbmRzJTVCMCU1RCUwQWV4YW1wbGUlNUIlMjJ0cmFuc2NyaXB0aW9uJTIyJTVE",highlighted:`example = minds[<span class="hljs-number">0</span>]
example[<span class="hljs-string">&quot;transcription&quot;</span>]`,wrap:!1}}),B=new h({props:{code:"JTIyaWNoJTIwbSVDMyVCNmNodGUlMjBnZXJuZSUyMEdlbGQlMjBhdWYlMjBtZWluJTIwS29udG8lMjBlaW56YWhsZW4lMjI=",highlighted:'<span class="hljs-comment">&quot;ich möchte gerne Geld auf mein Konto einzahlen&quot;</span>',wrap:!1}}),V=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBYXNyJTIwJTNEJTIwcGlwZWxpbmUoJTIyYXV0b21hdGljLXNwZWVjaC1yZWNvZ25pdGlvbiUyMiUyQyUyMG1vZGVsJTNEJTIybWF4aWRsJTJGd2F2MnZlYzItbGFyZ2UteGxzci1nZXJtYW4lMjIpJTBBYXNyKGV4YW1wbGUlNUIlMjJhdWRpbyUyMiU1RCU1QiUyMmFycmF5JTIyJTVEKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

asr = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>, model=<span class="hljs-string">&quot;maxidl/wav2vec2-large-xlsr-german&quot;</span>)
asr(example[<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>])`,wrap:!1}}),F=new h({props:{code:"JTdCJTIydGV4dCUyMiUzQSUyMCUyMmljaCUyMG0lQzMlQjZjaHRlJTIwZ2VybmUlMjBnZWxkJTIwYXVmJTIwbWVpbiUyMGtvbnRvJTIwZWluemFsbGVuJTIyJTdE",highlighted:'{<span class="hljs-comment">&quot;text&quot;</span>: <span class="hljs-comment">&quot;ich möchte gerne geld auf mein konto einzallen&quot;</span>}',wrap:!1}}),P=new ne({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/en/chapter2/asr_pipeline.mdx"}}),{c(){d=a("meta"),A=l(),X=a("p"),Q=l(),r(M.$$.fragment),D=l(),g=a("p"),g.textContent=kt,O=l(),w=a("p"),w.innerHTML=It,K=l(),U=a("p"),U.innerHTML=Gt,tt=l(),$=a("p"),$.innerHTML=Zt,et=l(),r(b.$$.fragment),st=l(),T=a("p"),T.textContent=Wt,nt=l(),r(v.$$.fragment),lt=l(),C=a("p"),C.innerHTML=qt,it=l(),r(J.$$.fragment),at=l(),x=a("p"),x.textContent=St,pt=l(),r(j.$$.fragment),ot=l(),k=a("p"),k.innerHTML=_t,rt=l(),r(I.$$.fragment),mt=l(),G=a("p"),G.textContent=Rt,ut=l(),Z=a("p"),Z.innerHTML=Bt,ft=l(),W=a("p"),W.textContent=Ht,yt=l(),r(q.$$.fragment),ct=l(),S=a("p"),S.textContent=Vt,ht=l(),r(_.$$.fragment),dt=l(),R=a("p"),R.innerHTML=Lt,Mt=l(),r(B.$$.fragment),gt=l(),H=a("p"),H.textContent=Ft,wt=l(),r(V.$$.fragment),Ut=l(),L=a("p"),L.innerHTML=Nt,$t=l(),r(F.$$.fragment),bt=l(),N=a("p"),N.textContent=zt,Tt=l(),z=a("p"),z.textContent=Et,vt=l(),E=a("ul"),E.innerHTML=Pt,Ct=l(),r(P.$$.fragment),Jt=l(),Y=a("p"),this.h()},l(t){const e=te("svelte-u9bgzb",document.head);d=p(e,"META",{name:!0,content:!0}),e.forEach(s),A=i(t),X=p(t,"P",{}),Xt(X).forEach(s),Q=i(t),m(M.$$.fragment,t),D=i(t),g=p(t,"P",{"data-svelte-h":!0}),o(g)!=="svelte-15e8vhg"&&(g.textContent=kt),O=i(t),w=p(t,"P",{"data-svelte-h":!0}),o(w)!=="svelte-1idfyxz"&&(w.innerHTML=It),K=i(t),U=p(t,"P",{"data-svelte-h":!0}),o(U)!=="svelte-quk603"&&(U.innerHTML=Gt),tt=i(t),$=p(t,"P",{"data-svelte-h":!0}),o($)!=="svelte-1eb02q"&&($.innerHTML=Zt),et=i(t),m(b.$$.fragment,t),st=i(t),T=p(t,"P",{"data-svelte-h":!0}),o(T)!=="svelte-stg8a5"&&(T.textContent=Wt),nt=i(t),m(v.$$.fragment,t),lt=i(t),C=p(t,"P",{"data-svelte-h":!0}),o(C)!=="svelte-1mvdyro"&&(C.innerHTML=qt),it=i(t),m(J.$$.fragment,t),at=i(t),x=p(t,"P",{"data-svelte-h":!0}),o(x)!=="svelte-9775ou"&&(x.textContent=St),pt=i(t),m(j.$$.fragment,t),ot=i(t),k=p(t,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1mvdyro"&&(k.innerHTML=_t),rt=i(t),m(I.$$.fragment,t),mt=i(t),G=p(t,"P",{"data-svelte-h":!0}),o(G)!=="svelte-1svug7g"&&(G.textContent=Rt),ut=i(t),Z=p(t,"P",{"data-svelte-h":!0}),o(Z)!=="svelte-1mg2emn"&&(Z.innerHTML=Bt),ft=i(t),W=p(t,"P",{"data-svelte-h":!0}),o(W)!=="svelte-nvy5i8"&&(W.textContent=Ht),yt=i(t),m(q.$$.fragment,t),ct=i(t),S=p(t,"P",{"data-svelte-h":!0}),o(S)!=="svelte-173pifj"&&(S.textContent=Vt),ht=i(t),m(_.$$.fragment,t),dt=i(t),R=p(t,"P",{"data-svelte-h":!0}),o(R)!=="svelte-1mvdyro"&&(R.innerHTML=Lt),Mt=i(t),m(B.$$.fragment,t),gt=i(t),H=p(t,"P",{"data-svelte-h":!0}),o(H)!=="svelte-1903dzv"&&(H.textContent=Ft),wt=i(t),m(V.$$.fragment,t),Ut=i(t),L=p(t,"P",{"data-svelte-h":!0}),o(L)!=="svelte-1mvdyro"&&(L.innerHTML=Nt),$t=i(t),m(F.$$.fragment,t),bt=i(t),N=p(t,"P",{"data-svelte-h":!0}),o(N)!=="svelte-4aj2v6"&&(N.textContent=zt),Tt=i(t),z=p(t,"P",{"data-svelte-h":!0}),o(z)!=="svelte-18ll1qj"&&(z.textContent=Et),vt=i(t),E=p(t,"UL",{"data-svelte-h":!0}),o(E)!=="svelte-1kd9vrj"&&(E.innerHTML=Pt),Ct=i(t),m(P.$$.fragment,t),Jt=i(t),Y=p(t,"P",{}),Xt(Y).forEach(s),this.h()},h(){Yt(d,"name","hf:doc:metadata"),Yt(d,"content",ie)},m(t,e){ee(document.head,d),n(t,A,e),n(t,X,e),n(t,Q,e),u(M,t,e),n(t,D,e),n(t,g,e),n(t,O,e),n(t,w,e),n(t,K,e),n(t,U,e),n(t,tt,e),n(t,$,e),n(t,et,e),u(b,t,e),n(t,st,e),n(t,T,e),n(t,nt,e),u(v,t,e),n(t,lt,e),n(t,C,e),n(t,it,e),u(J,t,e),n(t,at,e),n(t,x,e),n(t,pt,e),u(j,t,e),n(t,ot,e),n(t,k,e),n(t,rt,e),u(I,t,e),n(t,mt,e),n(t,G,e),n(t,ut,e),n(t,Z,e),n(t,ft,e),n(t,W,e),n(t,yt,e),u(q,t,e),n(t,ct,e),n(t,S,e),n(t,ht,e),u(_,t,e),n(t,dt,e),n(t,R,e),n(t,Mt,e),u(B,t,e),n(t,gt,e),n(t,H,e),n(t,wt,e),u(V,t,e),n(t,Ut,e),n(t,L,e),n(t,$t,e),u(F,t,e),n(t,bt,e),n(t,N,e),n(t,Tt,e),n(t,z,e),n(t,vt,e),n(t,E,e),n(t,Ct,e),u(P,t,e),n(t,Jt,e),n(t,Y,e),xt=!0},p:Qt,i(t){xt||(f(M.$$.fragment,t),f(b.$$.fragment,t),f(v.$$.fragment,t),f(J.$$.fragment,t),f(j.$$.fragment,t),f(I.$$.fragment,t),f(q.$$.fragment,t),f(_.$$.fragment,t),f(B.$$.fragment,t),f(V.$$.fragment,t),f(F.$$.fragment,t),f(P.$$.fragment,t),xt=!0)},o(t){y(M.$$.fragment,t),y(b.$$.fragment,t),y(v.$$.fragment,t),y(J.$$.fragment,t),y(j.$$.fragment,t),y(I.$$.fragment,t),y(q.$$.fragment,t),y(_.$$.fragment,t),y(B.$$.fragment,t),y(V.$$.fragment,t),y(F.$$.fragment,t),y(P.$$.fragment,t),xt=!1},d(t){t&&(s(A),s(X),s(Q),s(D),s(g),s(O),s(w),s(K),s(U),s(tt),s($),s(et),s(st),s(T),s(nt),s(lt),s(C),s(it),s(at),s(x),s(pt),s(ot),s(k),s(rt),s(mt),s(G),s(ut),s(Z),s(ft),s(W),s(yt),s(ct),s(S),s(ht),s(dt),s(R),s(Mt),s(gt),s(H),s(wt),s(Ut),s(L),s($t),s(bt),s(N),s(Tt),s(z),s(vt),s(E),s(Ct),s(Jt),s(Y)),s(d),c(M,t),c(b,t),c(v,t),c(J,t),c(j,t),c(I,t),c(q,t),c(_,t),c(B,t),c(V,t),c(F,t),c(P,t)}}}const ie='{"title":"Automatic speech recognition with a pipeline","local":"automatic-speech-recognition-with-a-pipeline","sections":[],"depth":1}';function ae(jt){return Dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ue extends Ot{constructor(d){super(),Kt(this,d,ae,le,At,{})}}export{ue as component};
