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