import{s as Dt,n as Ot,o as Kt}from"../chunks/scheduler.cd324960.js";import{S as te,i as ee,e as a,s as l,c as r,h as se,a as p,d as s,b as i,f as At,g as m,j as o,k as Qt,l as ne,m as n,n as u,t as f,o as y,p as c}from"../chunks/index.d5c3adcc.js";import{C as le,H as ie,E as ae}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.481f2bec.js";import{C as h}from"../chunks/CodeBlock.a252a8e7.js";function pe(It){let d,Q,Y,D,M,O,$,K,g,Gt=`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.`,tt,w,Zt=`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.`,et,U,St=`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.`,st,b,Wt=`To transcribe an audio recording, we can use the <code>automatic-speech-recognition</code> pipeline from 🤗 Transformers. Let’s
instantiate the pipeline:`,nt,T,lt,v,qt="Next, we’ll take an example from the dataset and pass its raw data to the pipeline:",it,C,at,J,_t="<strong>Output:</strong>",pt,x,ot,j,Rt="Let’s compare this output to what the actual transcription for this example is:",rt,k,mt,I,Bt="<strong>Output:</strong>",ut,G,ft,Z,Ht=`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!`,yt,S,Lt=`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.`,ct,W,Vt="Let’s try this for the German split of the MINDS-14. Load the “de-DE” subset:",ht,q,dt,_,zt="Get an example and see what the transcription is supposed to be:",Mt,R,$t,B,Ft="<strong>Output:</strong>",gt,H,wt,L,Nt="Find a pre-trained ASR model for German language on the 🤗 Hub, instantiate a pipeline, and transcribe the example:",Ut,V,bt,z,Et="<strong>Output:</strong>",Tt,F,vt,N,Pt="Also, stimmt’s!",Ct,E,Xt=`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:`,Jt,P,Yt=`<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>`,xt,X,jt,A,kt;return M=new le({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),$=new ie({props:{title:"Automatic speech recognition with a pipeline",local:"automatic-speech-recognition-with-a-pipeline",headingTag:"h1"}}),T=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}}),C=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}}),x=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}}),k=new h({props:{code:"ZXhhbXBsZSU1QiUyMmVuZ2xpc2hfdHJhbnNjcmlwdGlvbiUyMiU1RA==",highlighted:'example[<span class="hljs-string">&quot;english_transcription&quot;</span>]',wrap:!1}}),G=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}}),R=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}}),H=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}}),X=new ae({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/en/chapter2/asr_pipeline.mdx"}}),{c(){d=a("meta"),Q=l(),Y=a("p"),D=l(),r(M.$$.fragment),O=l(),r($.$$.fragment),K=l(),g=a("p"),g.textContent=Gt,tt=l(),w=a("p"),w.innerHTML=Zt,et=l(),U=a("p"),U.innerHTML=St,st=l(),b=a("p"),b.innerHTML=Wt,nt=l(),r(T.$$.fragment),lt=l(),v=a("p"),v.textContent=qt,it=l(),r(C.$$.fragment),at=l(),J=a("p"),J.innerHTML=_t,pt=l(),r(x.$$.fragment),ot=l(),j=a("p"),j.textContent=Rt,rt=l(),r(k.$$.fragment),mt=l(),I=a("p"),I.innerHTML=Bt,ut=l(),r(G.$$.fragment),ft=l(),Z=a("p"),Z.textContent=Ht,yt=l(),S=a("p"),S.innerHTML=Lt,ct=l(),W=a("p"),W.textContent=Vt,ht=l(),r(q.$$.fragment),dt=l(),_=a("p"),_.textContent=zt,Mt=l(),r(R.$$.fragment),$t=l(),B=a("p"),B.innerHTML=Ft,gt=l(),r(H.$$.fragment),wt=l(),L=a("p"),L.textContent=Nt,Ut=l(),r(V.$$.fragment),bt=l(),z=a("p"),z.innerHTML=Et,Tt=l(),r(F.$$.fragment),vt=l(),N=a("p"),N.textContent=Pt,Ct=l(),E=a("p"),E.textContent=Xt,Jt=l(),P=a("ul"),P.innerHTML=Yt,xt=l(),r(X.$$.fragment),jt=l(),A=a("p"),this.h()},l(t){const e=se("svelte-u9bgzb",document.head);d=p(e,"META",{name:!0,content:!0}),e.forEach(s),Q=i(t),Y=p(t,"P",{}),At(Y).forEach(s),D=i(t),m(M.$$.fragment,t),O=i(t),m($.$$.fragment,t),K=i(t),g=p(t,"P",{"data-svelte-h":!0}),o(g)!=="svelte-15e8vhg"&&(g.textContent=Gt),tt=i(t),w=p(t,"P",{"data-svelte-h":!0}),o(w)!=="svelte-1idfyxz"&&(w.innerHTML=Zt),et=i(t),U=p(t,"P",{"data-svelte-h":!0}),o(U)!=="svelte-quk603"&&(U.innerHTML=St),st=i(t),b=p(t,"P",{"data-svelte-h":!0}),o(b)!=="svelte-1eb02q"&&(b.innerHTML=Wt),nt=i(t),m(T.$$.fragment,t),lt=i(t),v=p(t,"P",{"data-svelte-h":!0}),o(v)!=="svelte-stg8a5"&&(v.textContent=qt),it=i(t),m(C.$$.fragment,t),at=i(t),J=p(t,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1mvdyro"&&(J.innerHTML=_t),pt=i(t),m(x.$$.fragment,t),ot=i(t),j=p(t,"P",{"data-svelte-h":!0}),o(j)!=="svelte-9775ou"&&(j.textContent=Rt),rt=i(t),m(k.$$.fragment,t),mt=i(t),I=p(t,"P",{"data-svelte-h":!0}),o(I)!=="svelte-1mvdyro"&&(I.innerHTML=Bt),ut=i(t),m(G.$$.fragment,t),ft=i(t),Z=p(t,"P",{"data-svelte-h":!0}),o(Z)!=="svelte-1svug7g"&&(Z.textContent=Ht),yt=i(t),S=p(t,"P",{"data-svelte-h":!0}),o(S)!=="svelte-1mg2emn"&&(S.innerHTML=Lt),ct=i(t),W=p(t,"P",{"data-svelte-h":!0}),o(W)!=="svelte-nvy5i8"&&(W.textContent=Vt),ht=i(t),m(q.$$.fragment,t),dt=i(t),_=p(t,"P",{"data-svelte-h":!0}),o(_)!=="svelte-173pifj"&&(_.textContent=zt),Mt=i(t),m(R.$$.fragment,t),$t=i(t),B=p(t,"P",{"data-svelte-h":!0}),o(B)!=="svelte-1mvdyro"&&(B.innerHTML=Ft),gt=i(t),m(H.$$.fragment,t),wt=i(t),L=p(t,"P",{"data-svelte-h":!0}),o(L)!=="svelte-1903dzv"&&(L.textContent=Nt),Ut=i(t),m(V.$$.fragment,t),bt=i(t),z=p(t,"P",{"data-svelte-h":!0}),o(z)!=="svelte-1mvdyro"&&(z.innerHTML=Et),Tt=i(t),m(F.$$.fragment,t),vt=i(t),N=p(t,"P",{"data-svelte-h":!0}),o(N)!=="svelte-4aj2v6"&&(N.textContent=Pt),Ct=i(t),E=p(t,"P",{"data-svelte-h":!0}),o(E)!=="svelte-18ll1qj"&&(E.textContent=Xt),Jt=i(t),P=p(t,"UL",{"data-svelte-h":!0}),o(P)!=="svelte-1kd9vrj"&&(P.innerHTML=Yt),xt=i(t),m(X.$$.fragment,t),jt=i(t),A=p(t,"P",{}),At(A).forEach(s),this.h()},h(){Qt(d,"name","hf:doc:metadata"),Qt(d,"content",oe)},m(t,e){ne(document.head,d),n(t,Q,e),n(t,Y,e),n(t,D,e),u(M,t,e),n(t,O,e),u($,t,e),n(t,K,e),n(t,g,e),n(t,tt,e),n(t,w,e),n(t,et,e),n(t,U,e),n(t,st,e),n(t,b,e),n(t,nt,e),u(T,t,e),n(t,lt,e),n(t,v,e),n(t,it,e),u(C,t,e),n(t,at,e),n(t,J,e),n(t,pt,e),u(x,t,e),n(t,ot,e),n(t,j,e),n(t,rt,e),u(k,t,e),n(t,mt,e),n(t,I,e),n(t,ut,e),u(G,t,e),n(t,ft,e),n(t,Z,e),n(t,yt,e),n(t,S,e),n(t,ct,e),n(t,W,e),n(t,ht,e),u(q,t,e),n(t,dt,e),n(t,_,e),n(t,Mt,e),u(R,t,e),n(t,$t,e),n(t,B,e),n(t,gt,e),u(H,t,e),n(t,wt,e),n(t,L,e),n(t,Ut,e),u(V,t,e),n(t,bt,e),n(t,z,e),n(t,Tt,e),u(F,t,e),n(t,vt,e),n(t,N,e),n(t,Ct,e),n(t,E,e),n(t,Jt,e),n(t,P,e),n(t,xt,e),u(X,t,e),n(t,jt,e),n(t,A,e),kt=!0},p:Ot,i(t){kt||(f(M.$$.fragment,t),f($.$$.fragment,t),f(T.$$.fragment,t),f(C.$$.fragment,t),f(x.$$.fragment,t),f(k.$$.fragment,t),f(G.$$.fragment,t),f(q.$$.fragment,t),f(R.$$.fragment,t),f(H.$$.fragment,t),f(V.$$.fragment,t),f(F.$$.fragment,t),f(X.$$.fragment,t),kt=!0)},o(t){y(M.$$.fragment,t),y($.$$.fragment,t),y(T.$$.fragment,t),y(C.$$.fragment,t),y(x.$$.fragment,t),y(k.$$.fragment,t),y(G.$$.fragment,t),y(q.$$.fragment,t),y(R.$$.fragment,t),y(H.$$.fragment,t),y(V.$$.fragment,t),y(F.$$.fragment,t),y(X.$$.fragment,t),kt=!1},d(t){t&&(s(Q),s(Y),s(D),s(O),s(K),s(g),s(tt),s(w),s(et),s(U),s(st),s(b),s(nt),s(lt),s(v),s(it),s(at),s(J),s(pt),s(ot),s(j),s(rt),s(mt),s(I),s(ut),s(ft),s(Z),s(yt),s(S),s(ct),s(W),s(ht),s(dt),s(_),s(Mt),s($t),s(B),s(gt),s(wt),s(L),s(Ut),s(bt),s(z),s(Tt),s(vt),s(N),s(Ct),s(E),s(Jt),s(P),s(xt),s(jt),s(A)),s(d),c(M,t),c($,t),c(T,t),c(C,t),c(x,t),c(k,t),c(G,t),c(q,t),c(R,t),c(H,t),c(V,t),c(F,t),c(X,t)}}}const oe='{"title":"Automatic speech recognition with a pipeline","local":"automatic-speech-recognition-with-a-pipeline","sections":[],"depth":1}';function re(It){return Kt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ce extends te{constructor(d){super(),ee(this,d,re,pe,Dt,{})}}export{ce as component};
