import{s as _e,n as qe,o as Qe}from"../chunks/scheduler.f7e1785c.js";import{S as ze,i as Re,g as i,s,r as p,A as Xe,h as o,f as n,c as a,j as Ze,u,x as r,k as He,y as Fe,a as l,v as m,d,t as c,w as y}from"../chunks/index.9f8f0838.js";import{C as f}from"../chunks/CodeBlock.b3510e34.js";import{H as Ue,E as Se}from"../chunks/EditOnGithub.5a9bb8c5.js";function Ne($e){let h,N,F,Y,M,P,w,be=`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.`,E,g,Je=`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.`,A,U,Ce="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.",L,$,Te="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:",D,b,K,J,O,C,xe=`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:`,ee,T,te,x,ke="The next step is as simple as passing some text through the pipeline. All the preprocessing will be done for us under the hood:",ne,k,le,j,je="In a notebook, we can use the following code snippet to listen to the result:",se,G,ae,v,Ge=`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:`,ie,B,oe,V,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:`,pe,W,ue,I,Be=`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!`,re,Z,me,H,Ve='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>',de,_,ce,q,We="Let’s create a text description of the music we’d like to generate:",ye,Q,he,z,Ie="We can control the length of the generated output by passing an additional <code>max_new_tokens</code> parameter to the model.",fe,R,Me,X,we,S,ge;return M=new Ue({props:{title:"Audio generation with a pipeline",local:"audio-generation-with-a-pipeline",headingTag:"h1"}}),b=new f({props:{code:"cGlwJTIwaW5zdGFsbCUyMC0tdXBncmFkZSUyMHRyYW5zZm9ybWVycw==",highlighted:"pip install --upgrade transformers",wrap:!1}}),J=new Ue({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}}),k=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}}),G=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}}),B=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}}),W=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}}),Z=new Ue({props:{title:"Generating music",local:"generating-music",headingTag:"h2"}}),_=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}}),R=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}}),X=new Se({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/en/chapter2/tts_pipeline.mdx"}}),{c(){h=i("meta"),N=s(),F=i("p"),Y=s(),p(M.$$.fragment),P=s(),w=i("p"),w.textContent=be,E=s(),g=i("p"),g.innerHTML=Je,A=s(),U=i("p"),U.textContent=Ce,L=s(),$=i("p"),$.textContent=Te,D=s(),p(b.$$.fragment),K=s(),p(J.$$.fragment),O=s(),C=i("p"),C.innerHTML=xe,ee=s(),p(T.$$.fragment),te=s(),x=i("p"),x.textContent=ke,ne=s(),p(k.$$.fragment),le=s(),j=i("p"),j.textContent=je,se=s(),p(G.$$.fragment),ae=s(),v=i("p"),v.textContent=Ge,ie=s(),p(B.$$.fragment),oe=s(),V=i("p"),V.textContent=ve,pe=s(),p(W.$$.fragment),ue=s(),I=i("p"),I.textContent=Be,re=s(),p(Z.$$.fragment),me=s(),H=i("p"),H.innerHTML=Ve,de=s(),p(_.$$.fragment),ce=s(),q=i("p"),q.textContent=We,ye=s(),p(Q.$$.fragment),he=s(),z=i("p"),z.innerHTML=Ie,fe=s(),p(R.$$.fragment),Me=s(),p(X.$$.fragment),we=s(),S=i("p"),this.h()},l(e){const t=Xe("svelte-u9bgzb",document.head);h=o(t,"META",{name:!0,content:!0}),t.forEach(n),N=a(e),F=o(e,"P",{}),Ze(F).forEach(n),Y=a(e),u(M.$$.fragment,e),P=a(e),w=o(e,"P",{"data-svelte-h":!0}),r(w)!=="svelte-1dtkcul"&&(w.textContent=be),E=a(e),g=o(e,"P",{"data-svelte-h":!0}),r(g)!=="svelte-f44taj"&&(g.innerHTML=Je),A=a(e),U=o(e,"P",{"data-svelte-h":!0}),r(U)!=="svelte-1x3quri"&&(U.textContent=Ce),L=a(e),$=o(e,"P",{"data-svelte-h":!0}),r($)!=="svelte-1iuie69"&&($.textContent=Te),D=a(e),u(b.$$.fragment,e),K=a(e),u(J.$$.fragment,e),O=a(e),C=o(e,"P",{"data-svelte-h":!0}),r(C)!=="svelte-anq3st"&&(C.innerHTML=xe),ee=a(e),u(T.$$.fragment,e),te=a(e),x=o(e,"P",{"data-svelte-h":!0}),r(x)!=="svelte-6b8wyl"&&(x.textContent=ke),ne=a(e),u(k.$$.fragment,e),le=a(e),j=o(e,"P",{"data-svelte-h":!0}),r(j)!=="svelte-1w6x0gz"&&(j.textContent=je),se=a(e),u(G.$$.fragment,e),ae=a(e),v=o(e,"P",{"data-svelte-h":!0}),r(v)!=="svelte-16u7g8g"&&(v.textContent=Ge),ie=a(e),u(B.$$.fragment,e),oe=a(e),V=o(e,"P",{"data-svelte-h":!0}),r(V)!=="svelte-ags8tg"&&(V.textContent=ve),pe=a(e),u(W.$$.fragment,e),ue=a(e),I=o(e,"P",{"data-svelte-h":!0}),r(I)!=="svelte-b3wsq0"&&(I.textContent=Be),re=a(e),u(Z.$$.fragment,e),me=a(e),H=o(e,"P",{"data-svelte-h":!0}),r(H)!=="svelte-kuejmv"&&(H.innerHTML=Ve),de=a(e),u(_.$$.fragment,e),ce=a(e),q=o(e,"P",{"data-svelte-h":!0}),r(q)!=="svelte-1xd5ix4"&&(q.textContent=We),ye=a(e),u(Q.$$.fragment,e),he=a(e),z=o(e,"P",{"data-svelte-h":!0}),r(z)!=="svelte-le5gn"&&(z.innerHTML=Ie),fe=a(e),u(R.$$.fragment,e),Me=a(e),u(X.$$.fragment,e),we=a(e),S=o(e,"P",{}),Ze(S).forEach(n),this.h()},h(){He(h,"name","hf:doc:metadata"),He(h,"content",Ye)},m(e,t){Fe(document.head,h),l(e,N,t),l(e,F,t),l(e,Y,t),m(M,e,t),l(e,P,t),l(e,w,t),l(e,E,t),l(e,g,t),l(e,A,t),l(e,U,t),l(e,L,t),l(e,$,t),l(e,D,t),m(b,e,t),l(e,K,t),m(J,e,t),l(e,O,t),l(e,C,t),l(e,ee,t),m(T,e,t),l(e,te,t),l(e,x,t),l(e,ne,t),m(k,e,t),l(e,le,t),l(e,j,t),l(e,se,t),m(G,e,t),l(e,ae,t),l(e,v,t),l(e,ie,t),m(B,e,t),l(e,oe,t),l(e,V,t),l(e,pe,t),m(W,e,t),l(e,ue,t),l(e,I,t),l(e,re,t),m(Z,e,t),l(e,me,t),l(e,H,t),l(e,de,t),m(_,e,t),l(e,ce,t),l(e,q,t),l(e,ye,t),m(Q,e,t),l(e,he,t),l(e,z,t),l(e,fe,t),m(R,e,t),l(e,Me,t),m(X,e,t),l(e,we,t),l(e,S,t),ge=!0},p:qe,i(e){ge||(d(M.$$.fragment,e),d(b.$$.fragment,e),d(J.$$.fragment,e),d(T.$$.fragment,e),d(k.$$.fragment,e),d(G.$$.fragment,e),d(B.$$.fragment,e),d(W.$$.fragment,e),d(Z.$$.fragment,e),d(_.$$.fragment,e),d(Q.$$.fragment,e),d(R.$$.fragment,e),d(X.$$.fragment,e),ge=!0)},o(e){c(M.$$.fragment,e),c(b.$$.fragment,e),c(J.$$.fragment,e),c(T.$$.fragment,e),c(k.$$.fragment,e),c(G.$$.fragment,e),c(B.$$.fragment,e),c(W.$$.fragment,e),c(Z.$$.fragment,e),c(_.$$.fragment,e),c(Q.$$.fragment,e),c(R.$$.fragment,e),c(X.$$.fragment,e),ge=!1},d(e){e&&(n(N),n(F),n(Y),n(P),n(w),n(E),n(g),n(A),n(U),n(L),n($),n(D),n(K),n(O),n(C),n(ee),n(te),n(x),n(ne),n(le),n(j),n(se),n(ae),n(v),n(ie),n(oe),n(V),n(pe),n(ue),n(I),n(re),n(me),n(H),n(de),n(ce),n(q),n(ye),n(he),n(z),n(fe),n(Me),n(we),n(S)),n(h),y(M,e),y(b,e),y(J,e),y(T,e),y(k,e),y(G,e),y(B,e),y(W,e),y(Z,e),y(_,e),y(Q,e),y(R,e),y(X,e)}}}const Ye='{"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 Pe($e){return Qe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ke extends ze{constructor(h){super(),Re(this,h,Pe,Ne,_e,{})}}export{Ke as component};
