import{s as ze,n as Qe,o as Re}from"../chunks/scheduler.cd324960.js";import{S as Xe,i as Fe,e as a,s,c as p,h as Se,a as o,d as n,b as i,f as _e,g as u,j as y,k as qe,l as Ne,m as l,n as r,t as m,o as d,p as c}from"../chunks/index.d5c3adcc.js";import{C as Ye,H as be,E as Pe}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.9176019f.js";import{C as f}from"../chunks/CodeBlock.7fb24222.js";function Ee(Je){let h,Y,S,P,M,E,g,A,w,Ce=`Audio generation encompasses a versatile set of tasks that involve producing an audio output. The tasks
that we will look into here are speech generation (aka “text-to-speech”) and music generation. In text-to-speech, a
model transforms a piece of text into lifelike spoken language sound, opening the door to applications such as virtual assistants,
accessibility tools for the visually impaired, and personalized audiobooks.
On the other hand, music generation can enable creative expression, and finds its use mostly in entertainment and game
development industries.`,L,U,xe=`In 🤗 Transformers, you’ll find a pipeline that covers both of these tasks. This pipeline is called <code>&quot;text-to-audio&quot;</code>,
but for convenience, it also has a <code>&quot;text-to-speech&quot;</code> alias. Here we’ll use both, and you are free to pick whichever
seems more applicable for your task.`,D,$,Te="Let’s explore how you can use this pipeline to start generating audio narration for texts, and music with just a few lines of code.",K,b,ke="This pipeline is new to 🤗 Transformers and comes part of the version 4.32 release. Thus you’ll need to upgrade the library to the latest version to get the feature:",O,J,ee,C,te,x,je=`Let’s begin by exploring text-to-speech generation. First, just as it was the case with audio classification and automatic
speech recognition, we’ll need to define the pipeline. We’ll define a text-to-speech pipeline since it best describes our task, and use the <a href="https://huggingface.co/suno/bark-small" rel="nofollow"><code>suno/bark-small</code></a> checkpoint:`,ne,T,le,k,Ge="The next step is as simple as passing some text through the pipeline. All the preprocessing will be done for us under the hood:",se,j,ie,G,ve="In a notebook, we can use the following code snippet to listen to the result:",ae,v,oe,B,Be=`The model that we’re using with the pipeline, Bark, is actually multilingual, so we can easily substitute the initial
text with a text in, say, French, and use the pipeline in the exact same way. It will pick up on the language all by itself:`,pe,V,ue,W,Ve=`Not only is this model multilingual, it can also generate audio with non-verbal communications and singing. Here’s how
you can make it sing:`,re,I,me,Z,We=`We’ll dive deeper into Bark specifics in the later unit dedicated to Text-to-speech, and will also show how you can use
other models for this task. Now, let’s generate some music!`,de,H,ce,_,Ie='Just as before, we’ll begin by instantiating a pipeline. For music generation, we’ll define a text-to-audio pipeline, and initialise it with the pretrained checkpoint <a href="https://huggingface.co/facebook/musicgen-small" rel="nofollow"><code>facebook/musicgen-small</code></a>',ye,q,he,z,Ze="Let’s create a text description of the music we’d like to generate:",fe,Q,Me,R,He="We can control the length of the generated output by passing an additional <code>max_new_tokens</code> parameter to the model.",ge,X,we,F,Ue,N,$e;return M=new Ye({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new be({props:{title:"Audio generation with a pipeline",local:"audio-generation-with-a-pipeline",headingTag:"h1"}}),J=new f({props:{code:"cGlwJTIwaW5zdGFsbCUyMC0tdXBncmFkZSUyMHRyYW5zZm9ybWVycw==",highlighted:"pip install --upgrade transformers",wrap:!1}}),C=new be({props:{title:"Generating speech",local:"generating-speech",headingTag:"h2"}}),T=new f({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMHBpcGVsaW5lKCUyMnRleHQtdG8tc3BlZWNoJTIyJTJDJTIwbW9kZWwlM0QlMjJzdW5vJTJGYmFyay1zbWFsbCUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

pipe = pipeline(<span class="hljs-string">&quot;text-to-speech&quot;</span>, model=<span class="hljs-string">&quot;suno/bark-small&quot;</span>)`,wrap:!1}}),j=new f({props:{code:"dGV4dCUyMCUzRCUyMCUyMkxhZHlidWdzJTIwaGF2ZSUyMGhhZCUyMGltcG9ydGFudCUyMHJvbGVzJTIwaW4lMjBjdWx0dXJlJTIwYW5kJTIwcmVsaWdpb24lMkMlMjBiZWluZyUyMGFzc29jaWF0ZWQlMjB3aXRoJTIwbHVjayUyQyUyMGxvdmUlMkMlMjBmZXJ0aWxpdHklMjBhbmQlMjBwcm9waGVjeS4lMjAlMjIlMEFvdXRwdXQlMjAlM0QlMjBwaXBlKHRleHQp",highlighted:`text = <span class="hljs-string">&quot;Ladybugs have had important roles in culture and religion, being associated with luck, love, fertility and prophecy. &quot;</span>
output = pipe(text)`,wrap:!1}}),v=new f({props:{code:"ZnJvbSUyMElQeXRob24uZGlzcGxheSUyMGltcG9ydCUyMEF1ZGlvJTBBJTBBQXVkaW8ob3V0cHV0JTVCJTIyYXVkaW8lMjIlNUQlMkMlMjByYXRlJTNEb3V0cHV0JTVCJTIyc2FtcGxpbmdfcmF0ZSUyMiU1RCk=",highlighted:`<span class="hljs-keyword">from</span> IPython.display <span class="hljs-keyword">import</span> Audio

Audio(output[<span class="hljs-string">&quot;audio&quot;</span>], rate=output[<span class="hljs-string">&quot;sampling_rate&quot;</span>])`,wrap:!1}}),V=new f({props:{code:"ZnJfdGV4dCUyMCUzRCUyMCUyMkNvbnRyYWlyZW1lbnQlMjAlQzMlQTAlMjB1bmUlMjBpZCVDMyVBOWUlMjByJUMzJUE5cGFuZHVlJTJDJTIwbGUlMjBub21icmUlMjBkZSUyMHBvaW50cyUyMHN1ciUyMGxlcyUyMCVDMyVBOWx5dHJlcyUyMGQndW5lJTIwY29jY2luZWxsZSUyMG5lJTIwY29ycmVzcG9uZCUyMHBhcyUyMCVDMyVBMCUyMHNvbiUyMCVDMyVBMmdlJTJDJTIwbmklMjBlbiUyMG5vbWJyZSUyMGQnYW5uJUMzJUE5ZXMlMkMlMjBuaSUyMGVuJTIwbm9tYnJlJTIwZGUlMjBtb2lzLiUyMCUyMiUwQW91dHB1dCUyMCUzRCUyMHBpcGUoZnJfdGV4dCklMEFBdWRpbyhvdXRwdXQlNUIlMjJhdWRpbyUyMiU1RCUyQyUyMHJhdGUlM0RvdXRwdXQlNUIlMjJzYW1wbGluZ19yYXRlJTIyJTVEKQ==",highlighted:`fr_text = <span class="hljs-string">&quot;Contrairement à une idée répandue, le nombre de points sur les élytres d&#x27;une coccinelle ne correspond pas à son âge, ni en nombre d&#x27;années, ni en nombre de mois. &quot;</span>
output = pipe(fr_text)
Audio(output[<span class="hljs-string">&quot;audio&quot;</span>], rate=output[<span class="hljs-string">&quot;sampling_rate&quot;</span>])`,wrap:!1}}),I=new f({props:{code:"c29uZyUyMCUzRCUyMCUyMiVFMiU5OSVBQSUyMEluJTIwdGhlJTIwanVuZ2xlJTJDJTIwdGhlJTIwbWlnaHR5JTIwanVuZ2xlJTJDJTIwdGhlJTIwbGFkeWJ1ZyUyMHdhcyUyMHNlZW4uJTIwJUUyJTk5JUFBJTIwJTIyJTBBb3V0cHV0JTIwJTNEJTIwcGlwZShzb25nKSUwQUF1ZGlvKG91dHB1dCU1QiUyMmF1ZGlvJTIyJTVEJTJDJTIwcmF0ZSUzRG91dHB1dCU1QiUyMnNhbXBsaW5nX3JhdGUlMjIlNUQp",highlighted:`song = <span class="hljs-string">&quot;♪ In the jungle, the mighty jungle, the ladybug was seen. ♪ &quot;</span>
output = pipe(song)
Audio(output[<span class="hljs-string">&quot;audio&quot;</span>], rate=output[<span class="hljs-string">&quot;sampling_rate&quot;</span>])`,wrap:!1}}),H=new be({props:{title:"Generating music",local:"generating-music",headingTag:"h2"}}),q=new f({props:{code:"bXVzaWNfcGlwZSUyMCUzRCUyMHBpcGVsaW5lKCUyMnRleHQtdG8tYXVkaW8lMjIlMkMlMjBtb2RlbCUzRCUyMmZhY2Vib29rJTJGbXVzaWNnZW4tc21hbGwlMjIp",highlighted:'music_pipe = pipeline(<span class="hljs-string">&quot;text-to-audio&quot;</span>, model=<span class="hljs-string">&quot;facebook/musicgen-small&quot;</span>)',wrap:!1}}),Q=new f({props:{code:"dGV4dCUyMCUzRCUyMCUyMjkwcyUyMHJvY2slMjBzb25nJTIwd2l0aCUyMGVsZWN0cmljJTIwZ3VpdGFyJTIwYW5kJTIwaGVhdnklMjBkcnVtcyUyMg==",highlighted:'text = <span class="hljs-string">&quot;90s rock song with electric guitar and heavy drums&quot;</span>',wrap:!1}}),X=new f({props:{code:"Zm9yd2FyZF9wYXJhbXMlMjAlM0QlMjAlN0IlMjJtYXhfbmV3X3Rva2VucyUyMiUzQSUyMDUxMiU3RCUwQSUwQW91dHB1dCUyMCUzRCUyMG11c2ljX3BpcGUodGV4dCUyQyUyMGZvcndhcmRfcGFyYW1zJTNEZm9yd2FyZF9wYXJhbXMpJTBBQXVkaW8ob3V0cHV0JTVCJTIyYXVkaW8lMjIlNUQlNUIwJTVEJTJDJTIwcmF0ZSUzRG91dHB1dCU1QiUyMnNhbXBsaW5nX3JhdGUlMjIlNUQp",highlighted:`forward_params = {<span class="hljs-string">&quot;max_new_tokens&quot;</span>: <span class="hljs-number">512</span>}

output = music_pipe(text, forward_params=forward_params)
Audio(output[<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-number">0</span>], rate=output[<span class="hljs-string">&quot;sampling_rate&quot;</span>])`,wrap:!1}}),F=new Pe({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/en/chapter2/tts_pipeline.mdx"}}),{c(){h=a("meta"),Y=s(),S=a("p"),P=s(),p(M.$$.fragment),E=s(),p(g.$$.fragment),A=s(),w=a("p"),w.textContent=Ce,L=s(),U=a("p"),U.innerHTML=xe,D=s(),$=a("p"),$.textContent=Te,K=s(),b=a("p"),b.textContent=ke,O=s(),p(J.$$.fragment),ee=s(),p(C.$$.fragment),te=s(),x=a("p"),x.innerHTML=je,ne=s(),p(T.$$.fragment),le=s(),k=a("p"),k.textContent=Ge,se=s(),p(j.$$.fragment),ie=s(),G=a("p"),G.textContent=ve,ae=s(),p(v.$$.fragment),oe=s(),B=a("p"),B.textContent=Be,pe=s(),p(V.$$.fragment),ue=s(),W=a("p"),W.textContent=Ve,re=s(),p(I.$$.fragment),me=s(),Z=a("p"),Z.textContent=We,de=s(),p(H.$$.fragment),ce=s(),_=a("p"),_.innerHTML=Ie,ye=s(),p(q.$$.fragment),he=s(),z=a("p"),z.textContent=Ze,fe=s(),p(Q.$$.fragment),Me=s(),R=a("p"),R.innerHTML=He,ge=s(),p(X.$$.fragment),we=s(),p(F.$$.fragment),Ue=s(),N=a("p"),this.h()},l(e){const t=Se("svelte-u9bgzb",document.head);h=o(t,"META",{name:!0,content:!0}),t.forEach(n),Y=i(e),S=o(e,"P",{}),_e(S).forEach(n),P=i(e),u(M.$$.fragment,e),E=i(e),u(g.$$.fragment,e),A=i(e),w=o(e,"P",{"data-svelte-h":!0}),y(w)!=="svelte-1dtkcul"&&(w.textContent=Ce),L=i(e),U=o(e,"P",{"data-svelte-h":!0}),y(U)!=="svelte-f44taj"&&(U.innerHTML=xe),D=i(e),$=o(e,"P",{"data-svelte-h":!0}),y($)!=="svelte-1x3quri"&&($.textContent=Te),K=i(e),b=o(e,"P",{"data-svelte-h":!0}),y(b)!=="svelte-1iuie69"&&(b.textContent=ke),O=i(e),u(J.$$.fragment,e),ee=i(e),u(C.$$.fragment,e),te=i(e),x=o(e,"P",{"data-svelte-h":!0}),y(x)!=="svelte-anq3st"&&(x.innerHTML=je),ne=i(e),u(T.$$.fragment,e),le=i(e),k=o(e,"P",{"data-svelte-h":!0}),y(k)!=="svelte-6b8wyl"&&(k.textContent=Ge),se=i(e),u(j.$$.fragment,e),ie=i(e),G=o(e,"P",{"data-svelte-h":!0}),y(G)!=="svelte-1w6x0gz"&&(G.textContent=ve),ae=i(e),u(v.$$.fragment,e),oe=i(e),B=o(e,"P",{"data-svelte-h":!0}),y(B)!=="svelte-16u7g8g"&&(B.textContent=Be),pe=i(e),u(V.$$.fragment,e),ue=i(e),W=o(e,"P",{"data-svelte-h":!0}),y(W)!=="svelte-ags8tg"&&(W.textContent=Ve),re=i(e),u(I.$$.fragment,e),me=i(e),Z=o(e,"P",{"data-svelte-h":!0}),y(Z)!=="svelte-b3wsq0"&&(Z.textContent=We),de=i(e),u(H.$$.fragment,e),ce=i(e),_=o(e,"P",{"data-svelte-h":!0}),y(_)!=="svelte-kuejmv"&&(_.innerHTML=Ie),ye=i(e),u(q.$$.fragment,e),he=i(e),z=o(e,"P",{"data-svelte-h":!0}),y(z)!=="svelte-1xd5ix4"&&(z.textContent=Ze),fe=i(e),u(Q.$$.fragment,e),Me=i(e),R=o(e,"P",{"data-svelte-h":!0}),y(R)!=="svelte-le5gn"&&(R.innerHTML=He),ge=i(e),u(X.$$.fragment,e),we=i(e),u(F.$$.fragment,e),Ue=i(e),N=o(e,"P",{}),_e(N).forEach(n),this.h()},h(){qe(h,"name","hf:doc:metadata"),qe(h,"content",Ae)},m(e,t){Ne(document.head,h),l(e,Y,t),l(e,S,t),l(e,P,t),r(M,e,t),l(e,E,t),r(g,e,t),l(e,A,t),l(e,w,t),l(e,L,t),l(e,U,t),l(e,D,t),l(e,$,t),l(e,K,t),l(e,b,t),l(e,O,t),r(J,e,t),l(e,ee,t),r(C,e,t),l(e,te,t),l(e,x,t),l(e,ne,t),r(T,e,t),l(e,le,t),l(e,k,t),l(e,se,t),r(j,e,t),l(e,ie,t),l(e,G,t),l(e,ae,t),r(v,e,t),l(e,oe,t),l(e,B,t),l(e,pe,t),r(V,e,t),l(e,ue,t),l(e,W,t),l(e,re,t),r(I,e,t),l(e,me,t),l(e,Z,t),l(e,de,t),r(H,e,t),l(e,ce,t),l(e,_,t),l(e,ye,t),r(q,e,t),l(e,he,t),l(e,z,t),l(e,fe,t),r(Q,e,t),l(e,Me,t),l(e,R,t),l(e,ge,t),r(X,e,t),l(e,we,t),r(F,e,t),l(e,Ue,t),l(e,N,t),$e=!0},p:Qe,i(e){$e||(m(M.$$.fragment,e),m(g.$$.fragment,e),m(J.$$.fragment,e),m(C.$$.fragment,e),m(T.$$.fragment,e),m(j.$$.fragment,e),m(v.$$.fragment,e),m(V.$$.fragment,e),m(I.$$.fragment,e),m(H.$$.fragment,e),m(q.$$.fragment,e),m(Q.$$.fragment,e),m(X.$$.fragment,e),m(F.$$.fragment,e),$e=!0)},o(e){d(M.$$.fragment,e),d(g.$$.fragment,e),d(J.$$.fragment,e),d(C.$$.fragment,e),d(T.$$.fragment,e),d(j.$$.fragment,e),d(v.$$.fragment,e),d(V.$$.fragment,e),d(I.$$.fragment,e),d(H.$$.fragment,e),d(q.$$.fragment,e),d(Q.$$.fragment,e),d(X.$$.fragment,e),d(F.$$.fragment,e),$e=!1},d(e){e&&(n(Y),n(S),n(P),n(E),n(A),n(w),n(L),n(U),n(D),n($),n(K),n(b),n(O),n(ee),n(te),n(x),n(ne),n(le),n(k),n(se),n(ie),n(G),n(ae),n(oe),n(B),n(pe),n(ue),n(W),n(re),n(me),n(Z),n(de),n(ce),n(_),n(ye),n(he),n(z),n(fe),n(Me),n(R),n(ge),n(we),n(Ue),n(N)),n(h),c(M,e),c(g,e),c(J,e),c(C,e),c(T,e),c(j,e),c(v,e),c(V,e),c(I,e),c(H,e),c(q,e),c(Q,e),c(X,e),c(F,e)}}}const Ae='{"title":"Audio generation with a pipeline","local":"audio-generation-with-a-pipeline","sections":[{"title":"Generating speech","local":"generating-speech","sections":[],"depth":2},{"title":"Generating music","local":"generating-music","sections":[],"depth":2}],"depth":1}';function Le(Je){return Re(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class tt extends Xe{constructor(h){super(),Fe(this,h,Le,Ee,ze,{})}}export{tt as component};
