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