import{s as Qt,n as At,o as Dt}from"../chunks/scheduler.f7e1785c.js";import{S as Kt,i as Ot,g as i,s as n,r as o,A as te,h as a,f as l,c as p,j as Xt,u,x as m,k as Yt,y as ee,a as s,v as r,d as y,t as f,w as M}from"../chunks/index.9f8f0838.js";import{C as c}from"../chunks/CodeBlock.4baef5d7.js";import{H as le,E as se}from"../chunks/getInferenceSnippets.ba5f4cd0.js";function ne(It){let U,Q,X,A,$,D,T,Gt="自动语音识别（Automatic Speech Recognition, ASR）是一个将录音转录为文字的任务。该任务有许多非常实用的应用，包括生成视频字幕、语音助手（Siri、Alexa等）的语音指令功能等等。",K,d,gt="本小节中，我们将使用<code>automatic-speech-recognition</code> pipeline来转录MINDS-14数据集中一段用户询问账单信息的录音。",O,J,Zt='首先，我们根据<a href="audio_classification_pipeline.mdx">利用pipeline进行音频分类</a>一节的方法加载数据并上采样至16千赫兹。',tt,C,kt="接下来，我们利用🤗 Transformers中的<code>automatic-speech-recognition</code> pipeline来构建自动语音识别的任务：",et,w,lt,h,St="下面，我们从数据集中选取一个样本，并将该样本的原始音频数据传递给pipeline：",st,b,nt,x,Wt="<strong>输出</strong>",pt,j,it,v,_t="我们可以将模型转录的结果和该样本标签中真实的转录文字进行对比：",at,I,mt,G,Rt="<strong>输出：</strong>",ot,g,ut,Z,qt="看起来模型在文字转录上的效果还不错！和原始转录相比，仅有一个词（card）转录错误。考虑到用户使用的澳大利亚方言中“r”通常不发音，这个结果已经很不错了。 不过我并不推荐用一条鱼来支付你的下一张电费账单就是了！（译注：cod为鳕鱼）",rt,k,Bt='在默认条件下，该pipeline使用的是一个针对英语语言的自动语音识别模型，这在本例中是可以的。如果你想尝试转录MINDS-14数据集中其他语言的子集，你可以在<a href="https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&amp;language=fr&amp;sort=downloads" rel="nofollow">🤗 Hub</a>上找到一个预训练的ASR模型。你可以首先按任务过滤模型列表，然后再按语言过滤。一旦你找到了喜欢的模型，将其名称作为<code>model</code>参数传递给pipeline即可。',yt,S,Ht="让我们尝试一下MINDS-14数据集中德语子集的转录。首先加载<code>de-DE</code>子集：",ft,W,Mt,_,Vt="接下来，我们获取一个样本并查看其转录：",ct,R,Ut,q,zt="<strong>输出</strong>",$t,B,Tt,H,Nt="接下来，我们在🤗 Hub上找到一个针对德语语言的预训练ASR模型，然后将其名称传递给pipeline，并对样本进行转录：",dt,V,Jt,z,Ft="<strong>输出</strong>",Ct,N,wt,F,Lt="德语也没问题！",ht,L,Et="当你在解决自己的任务时，从本单元中展示的简单pipeline开始是一个非常有价值的工具，它有以下几个好处：",bt,E,Pt="<li>预训练模型可能已经能够很好地解决你的任务，从而节省了大量时间</li> <li><code>pipeline()</code>会为你进行所有的预处理和后处理操作，因此你不必再花时间将数据转换为模型正确的格式</li> <li>如果结果不理想，pipeline仍然可以为你提供一个快速实现的基线，以便在未来对其进行微调</li> <li>如果你在自己的数据集上微调了一个模型并将其分享到Hub上，整个社区都可以通过<code>pipeline()</code>方法快速轻松地使用它，从而使AI更加易于使用。</li>",xt,P,jt,Y,vt;return $=new le({props:{title:"利用pipeline进行自动语音识别",local:"利用pipeline进行自动语音识别",headingTag:"h1"}}),w=new c({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}}),b=new c({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 c({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}}),I=new c({props:{code:"ZXhhbXBsZSU1QiUyMmVuZ2xpc2hfdHJhbnNjcmlwdGlvbiUyMiU1RA==",highlighted:'example[<span class="hljs-string">&quot;english_transcription&quot;</span>]',wrap:!1}}),g=new c({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}}),W=new c({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 c({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 c({props:{code:"JTIyaWNoJTIwbSVDMyVCNmNodGUlMjBnZXJuZSUyMEdlbGQlMjBhdWYlMjBtZWluJTIwS29udG8lMjBlaW56YWhsZW4lMjI=",highlighted:'<span class="hljs-comment">&quot;ich möchte gerne Geld auf mein Konto einzahlen&quot;</span>',wrap:!1}}),V=new c({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}}),N=new c({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 se({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/zh-CN/chapter2/asr_pipeline.mdx"}}),{c(){U=i("meta"),Q=n(),X=i("p"),A=n(),o($.$$.fragment),D=n(),T=i("p"),T.textContent=Gt,K=n(),d=i("p"),d.innerHTML=gt,O=n(),J=i("p"),J.innerHTML=Zt,tt=n(),C=i("p"),C.innerHTML=kt,et=n(),o(w.$$.fragment),lt=n(),h=i("p"),h.textContent=St,st=n(),o(b.$$.fragment),nt=n(),x=i("p"),x.innerHTML=Wt,pt=n(),o(j.$$.fragment),it=n(),v=i("p"),v.textContent=_t,at=n(),o(I.$$.fragment),mt=n(),G=i("p"),G.innerHTML=Rt,ot=n(),o(g.$$.fragment),ut=n(),Z=i("p"),Z.textContent=qt,rt=n(),k=i("p"),k.innerHTML=Bt,yt=n(),S=i("p"),S.innerHTML=Ht,ft=n(),o(W.$$.fragment),Mt=n(),_=i("p"),_.textContent=Vt,ct=n(),o(R.$$.fragment),Ut=n(),q=i("p"),q.innerHTML=zt,$t=n(),o(B.$$.fragment),Tt=n(),H=i("p"),H.textContent=Nt,dt=n(),o(V.$$.fragment),Jt=n(),z=i("p"),z.innerHTML=Ft,Ct=n(),o(N.$$.fragment),wt=n(),F=i("p"),F.textContent=Lt,ht=n(),L=i("p"),L.textContent=Et,bt=n(),E=i("ul"),E.innerHTML=Pt,xt=n(),o(P.$$.fragment),jt=n(),Y=i("p"),this.h()},l(t){const e=te("svelte-u9bgzb",document.head);U=a(e,"META",{name:!0,content:!0}),e.forEach(l),Q=p(t),X=a(t,"P",{}),Xt(X).forEach(l),A=p(t),u($.$$.fragment,t),D=p(t),T=a(t,"P",{"data-svelte-h":!0}),m(T)!=="svelte-sxf65u"&&(T.textContent=Gt),K=p(t),d=a(t,"P",{"data-svelte-h":!0}),m(d)!=="svelte-95xo54"&&(d.innerHTML=gt),O=p(t),J=a(t,"P",{"data-svelte-h":!0}),m(J)!=="svelte-mwzxm9"&&(J.innerHTML=Zt),tt=p(t),C=a(t,"P",{"data-svelte-h":!0}),m(C)!=="svelte-12b0xpy"&&(C.innerHTML=kt),et=p(t),u(w.$$.fragment,t),lt=p(t),h=a(t,"P",{"data-svelte-h":!0}),m(h)!=="svelte-d8hk8"&&(h.textContent=St),st=p(t),u(b.$$.fragment,t),nt=p(t),x=a(t,"P",{"data-svelte-h":!0}),m(x)!=="svelte-1n6w44y"&&(x.innerHTML=Wt),pt=p(t),u(j.$$.fragment,t),it=p(t),v=a(t,"P",{"data-svelte-h":!0}),m(v)!=="svelte-ja0s69"&&(v.textContent=_t),at=p(t),u(I.$$.fragment,t),mt=p(t),G=a(t,"P",{"data-svelte-h":!0}),m(G)!=="svelte-1yevus4"&&(G.innerHTML=Rt),ot=p(t),u(g.$$.fragment,t),ut=p(t),Z=a(t,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-1dd3ehc"&&(Z.textContent=qt),rt=p(t),k=a(t,"P",{"data-svelte-h":!0}),m(k)!=="svelte-1bm2d89"&&(k.innerHTML=Bt),yt=p(t),S=a(t,"P",{"data-svelte-h":!0}),m(S)!=="svelte-ofnezj"&&(S.innerHTML=Ht),ft=p(t),u(W.$$.fragment,t),Mt=p(t),_=a(t,"P",{"data-svelte-h":!0}),m(_)!=="svelte-nqlcab"&&(_.textContent=Vt),ct=p(t),u(R.$$.fragment,t),Ut=p(t),q=a(t,"P",{"data-svelte-h":!0}),m(q)!=="svelte-1n6w44y"&&(q.innerHTML=zt),$t=p(t),u(B.$$.fragment,t),Tt=p(t),H=a(t,"P",{"data-svelte-h":!0}),m(H)!=="svelte-6e6lzm"&&(H.textContent=Nt),dt=p(t),u(V.$$.fragment,t),Jt=p(t),z=a(t,"P",{"data-svelte-h":!0}),m(z)!=="svelte-1n6w44y"&&(z.innerHTML=Ft),Ct=p(t),u(N.$$.fragment,t),wt=p(t),F=a(t,"P",{"data-svelte-h":!0}),m(F)!=="svelte-sjgcl5"&&(F.textContent=Lt),ht=p(t),L=a(t,"P",{"data-svelte-h":!0}),m(L)!=="svelte-1w38qnc"&&(L.textContent=Et),bt=p(t),E=a(t,"UL",{"data-svelte-h":!0}),m(E)!=="svelte-4kj8k8"&&(E.innerHTML=Pt),xt=p(t),u(P.$$.fragment,t),jt=p(t),Y=a(t,"P",{}),Xt(Y).forEach(l),this.h()},h(){Yt(U,"name","hf:doc:metadata"),Yt(U,"content",pe)},m(t,e){ee(document.head,U),s(t,Q,e),s(t,X,e),s(t,A,e),r($,t,e),s(t,D,e),s(t,T,e),s(t,K,e),s(t,d,e),s(t,O,e),s(t,J,e),s(t,tt,e),s(t,C,e),s(t,et,e),r(w,t,e),s(t,lt,e),s(t,h,e),s(t,st,e),r(b,t,e),s(t,nt,e),s(t,x,e),s(t,pt,e),r(j,t,e),s(t,it,e),s(t,v,e),s(t,at,e),r(I,t,e),s(t,mt,e),s(t,G,e),s(t,ot,e),r(g,t,e),s(t,ut,e),s(t,Z,e),s(t,rt,e),s(t,k,e),s(t,yt,e),s(t,S,e),s(t,ft,e),r(W,t,e),s(t,Mt,e),s(t,_,e),s(t,ct,e),r(R,t,e),s(t,Ut,e),s(t,q,e),s(t,$t,e),r(B,t,e),s(t,Tt,e),s(t,H,e),s(t,dt,e),r(V,t,e),s(t,Jt,e),s(t,z,e),s(t,Ct,e),r(N,t,e),s(t,wt,e),s(t,F,e),s(t,ht,e),s(t,L,e),s(t,bt,e),s(t,E,e),s(t,xt,e),r(P,t,e),s(t,jt,e),s(t,Y,e),vt=!0},p:At,i(t){vt||(y($.$$.fragment,t),y(w.$$.fragment,t),y(b.$$.fragment,t),y(j.$$.fragment,t),y(I.$$.fragment,t),y(g.$$.fragment,t),y(W.$$.fragment,t),y(R.$$.fragment,t),y(B.$$.fragment,t),y(V.$$.fragment,t),y(N.$$.fragment,t),y(P.$$.fragment,t),vt=!0)},o(t){f($.$$.fragment,t),f(w.$$.fragment,t),f(b.$$.fragment,t),f(j.$$.fragment,t),f(I.$$.fragment,t),f(g.$$.fragment,t),f(W.$$.fragment,t),f(R.$$.fragment,t),f(B.$$.fragment,t),f(V.$$.fragment,t),f(N.$$.fragment,t),f(P.$$.fragment,t),vt=!1},d(t){t&&(l(Q),l(X),l(A),l(D),l(T),l(K),l(d),l(O),l(J),l(tt),l(C),l(et),l(lt),l(h),l(st),l(nt),l(x),l(pt),l(it),l(v),l(at),l(mt),l(G),l(ot),l(ut),l(Z),l(rt),l(k),l(yt),l(S),l(ft),l(Mt),l(_),l(ct),l(Ut),l(q),l($t),l(Tt),l(H),l(dt),l(Jt),l(z),l(Ct),l(wt),l(F),l(ht),l(L),l(bt),l(E),l(xt),l(jt),l(Y)),l(U),M($,t),M(w,t),M(b,t),M(j,t),M(I,t),M(g,t),M(W,t),M(R,t),M(B,t),M(V,t),M(N,t),M(P,t)}}}const pe='{"title":"利用pipeline进行自动语音识别","local":"利用pipeline进行自动语音识别","sections":[],"depth":1}';function ie(It){return Dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class re extends Kt{constructor(U){super(),Ot(this,U,ie,ne,Qt,{})}}export{re as component};
