import{S as Wi,i as Gi,s as Bi,e as l,k as h,w as u,t as p,M as Mi,c as r,d as s,m as c,a as o,x as f,h as i,b as m,N as Bo,G as a,g as n,y as d,q as g,o as _,B as b,v as Ri,L as Yi}from"../../chunks/vendor-hf-doc-builder.js";import{T as Xi}from"../../chunks/Tip-hf-doc-builder.js";import{I}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as k}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Ji}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function Ki(Kt){let j,G,y,$,S;return $=new k({props:{code:"!nvidia-smi",highlighted:"!nvidia-smi"}}),{c(){j=l("p"),G=p("To follow this guide you will need a GPU. If you\u2019re working in a notebook, run the following line to check if a GPU is available:"),y=h(),u($.$$.fragment)},l(v){j=r(v,"P",{});var P=o(j);G=i(P,"To follow this guide you will need a GPU. If you\u2019re working in a notebook, run the following line to check if a GPU is available:"),P.forEach(s),y=c(v),f($.$$.fragment,v)},m(v,P){n(v,j,P),a(j,G),n(v,y,P),d($,v,P),S=!0},p:Yi,i(v){S||(g($.$$.fragment,v),S=!0)},o(v){_($.$$.fragment,v),S=!1},d(v){v&&s(j),v&&s(y),b($,v)}}}function Qi(Kt){let j,G,y,$,S,v,P,ot,bl,Qt,ue,Zt,B,kl,ds,vl,jl,ea,gs,$l,sa,M,E,wl,_s,yl,xl,pt,ql,Tl,fe,El,Sl,Pl,it,zl,ta,bs,Dl,aa,de,na,ks,Al,la,ge,ra,R,oa,vs,Il,pa,_e,ia,C,Y,ht,be,Cl,ct,Nl,ha,ke,ve,Fl,Ol,ca,js,Hl,ma,$s,Ll,ua,je,fa,ws,Ul,da,$e,ga,N,X,mt,we,Vl,ut,Wl,_a,ys,Gl,ba,ye,ka,F,J,ft,xe,Bl,dt,Ml,va,xs,Rl,ja,qe,$a,x,Yl,gt,Xl,Jl,_t,Kl,Ql,bt,Zl,er,kt,sr,tr,wa,q,ar,vt,nr,lr,jt,rr,or,$t,pr,ir,ya,w,hr,wt,cr,mr,yt,ur,fr,xt,dr,gr,qt,_r,br,Tt,kr,vr,xa,Te,qa,qs,jr,Ta,Ee,Ea,K,$r,Et,wr,yr,Sa,Se,Pa,Ts,xr,za,O,Q,St,Pe,qr,Pt,Tr,Da,Es,Er,Aa,ze,Ia,Ss,Sr,Ca,De,Na,Ae,Ps,Mo,Fa,zs,Pr,Oa,Ie,Ha,Ds,zr,La,Ce,Ua,As,Dr,Va,Ne,Wa,Is,Ar,Ga,Cs,Ir,Ba,H,Z,zt,Fe,Cr,Dt,Nr,Ma,ee,Fr,Oe,Or,Hr,Ra,se,Lr,At,Ur,Vr,Ya,He,Xa,te,Wr,It,Gr,Br,Ja,Ns,Mr,Ka,L,ae,Ct,Le,Rr,Nt,Yr,Qa,z,Xr,Ft,Jr,Kr,Ot,Qr,Zr,Za,Ue,en,Fs,eo,sn,Ve,tn,Os,so,an,We,nn,Hs,to,ln,Ge,rn,Be,Ls,Ro,on,Us,ao,pn,Vs,no,hn,Me,cn,Ws,lo,mn,Re,un,Gs,ro,fn,Ye,dn,U,ne,Ht,Xe,oo,Lt,po,gn,le,io,Ut,ho,co,_n,Je,bn,Bs,mo,kn,Ke,vn,V,re,Vt,Qe,uo,Wt,fo,jn,Ms,go,$n,Ze,wn,oe,_o,Gt,bo,ko,yn,es,xn,Rs,vo,qn,ss,Tn,pe,jo,Bt,$o,wo,En,ts,Sn,D,yo,Mt,xo,qo,Rt,To,Eo,Pn,as,zn,Ys,So,Dn,ns,An,W,ie,Yt,ls,Po,Xt,zo,In,Xs,Do,Cn,rs,Nn,Js,Ao,Fn,os,On,Ks,Io,Hn,ps,Ln,Qs,Co,Un,is,Vn,Zs,No,Wn,hs,Gn,et,Fo,Bn,cs,Mn,ms,st,Yo,Rn,tt,Oo,Yn,us,Xn,at,Ho,Jn,he,Lo,Jt,Uo,Vo,Kn,nt,Wo,Qn;return v=new I({}),ue=new Ji({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/text-to-speech.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/text-to-speech.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/text-to-speech.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/text-to-speech.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/text-to-speech.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/text-to-speech.ipynb"}]}}),de=new k({props:{code:"pip install datasets soundfile speechbrain accelerate",highlighted:"pip install datasets soundfile speechbrain accelerate"}}),ge=new k({props:{code:"pip install git+https://github.com/huggingface/transformers.git",highlighted:"pip install git+https://github.com/huggingface/transformers.git"}}),R=new Xi({props:{$$slots:{default:[Ki]},$$scope:{ctx:Kt}}}),_e=new k({props:{code:`from huggingface_hub import notebook_login

notebook_login()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`}}),be=new I({}),je=new k({props:{code:`from datasets import load_dataset, Audio

dataset = load_dataset("facebook/voxpopuli", "nl", split="train")
len(dataset)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset, Audio

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;facebook/voxpopuli&quot;</span>, <span class="hljs-string">&quot;nl&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">len</span>(dataset)
<span class="hljs-number">20968</span>`}}),$e=new k({props:{code:'dataset = dataset.cast_column("audio", Audio(sampling_rate=16000))',highlighted:'dataset = dataset.cast_column(<span class="hljs-string">&quot;audio&quot;</span>, Audio(sampling_rate=<span class="hljs-number">16000</span>))'}}),we=new I({}),ye=new k({props:{code:`from transformers import SpeechT5Processor

checkpoint = "microsoft/speecht5_tts"
processor = SpeechT5Processor.from_pretrained(checkpoint)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> SpeechT5Processor

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;microsoft/speecht5_tts&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = SpeechT5Processor.from_pretrained(checkpoint)`}}),xe=new I({}),qe=new k({props:{code:"tokenizer = processor.tokenizer",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = processor.tokenizer'}}),Te=new k({props:{code:`def extract_all_chars(batch):
    all_text = " ".join(batch["normalized_text"])
    vocab = list(set(all_text))
    return {"vocab": [vocab], "all_text": [all_text]}


vocabs = dataset.map(
    extract_all_chars,
    batched=True,
    batch_size=-1,
    keep_in_memory=True,
    remove_columns=dataset.column_names,
)

dataset_vocab = set(vocabs["vocab"][0])
tokenizer_vocab = {k for k, _ in tokenizer.get_vocab().items()}`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">extract_all_chars</span>(<span class="hljs-params">batch</span>):
<span class="hljs-meta">... </span>    all_text = <span class="hljs-string">&quot; &quot;</span>.join(batch[<span class="hljs-string">&quot;normalized_text&quot;</span>])
<span class="hljs-meta">... </span>    vocab = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">set</span>(all_text))
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;vocab&quot;</span>: [vocab], <span class="hljs-string">&quot;all_text&quot;</span>: [all_text]}


<span class="hljs-meta">&gt;&gt;&gt; </span>vocabs = dataset.<span class="hljs-built_in">map</span>(
<span class="hljs-meta">... </span>    extract_all_chars,
<span class="hljs-meta">... </span>    batched=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    batch_size=-<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>    keep_in_memory=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    remove_columns=dataset.column_names,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset_vocab = <span class="hljs-built_in">set</span>(vocabs[<span class="hljs-string">&quot;vocab&quot;</span>][<span class="hljs-number">0</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer_vocab = {k <span class="hljs-keyword">for</span> k, _ <span class="hljs-keyword">in</span> tokenizer.get_vocab().items()}`}}),Ee=new k({props:{code:"dataset_vocab - tokenizer_vocab",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>dataset_vocab - tokenizer_vocab
{<span class="hljs-string">&#x27; &#x27;</span>, <span class="hljs-string">&#x27;\xE0&#x27;</span>, <span class="hljs-string">&#x27;\xE7&#x27;</span>, <span class="hljs-string">&#x27;\xE8&#x27;</span>, <span class="hljs-string">&#x27;\xEB&#x27;</span>, <span class="hljs-string">&#x27;\xED&#x27;</span>, <span class="hljs-string">&#x27;\xEF&#x27;</span>, <span class="hljs-string">&#x27;\xF6&#x27;</span>, <span class="hljs-string">&#x27;\xFC&#x27;</span>}`}}),Se=new k({props:{code:`replacements = [
    ("\xE0", "a"),
    ("\xE7", "c"),
    ("\xE8", "e"),
    ("\xEB", "e"),
    ("\xED", "i"),
    ("\xEF", "i"),
    ("\xF6", "o"),
    ("\xFC", "u"),
]


def cleanup_text(inputs):
    for src, dst in replacements:
        inputs["normalized_text"] = inputs["normalized_text"].replace(src, dst)
    return inputs


dataset = dataset.map(cleanup_text)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>replacements = [
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xE0&quot;</span>, <span class="hljs-string">&quot;a&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xE7&quot;</span>, <span class="hljs-string">&quot;c&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xE8&quot;</span>, <span class="hljs-string">&quot;e&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xEB&quot;</span>, <span class="hljs-string">&quot;e&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xED&quot;</span>, <span class="hljs-string">&quot;i&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xEF&quot;</span>, <span class="hljs-string">&quot;i&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xF6&quot;</span>, <span class="hljs-string">&quot;o&quot;</span>),
<span class="hljs-meta">... </span>    (<span class="hljs-string">&quot;\xFC&quot;</span>, <span class="hljs-string">&quot;u&quot;</span>),
<span class="hljs-meta">... </span>]


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">cleanup_text</span>(<span class="hljs-params">inputs</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> src, dst <span class="hljs-keyword">in</span> replacements:
<span class="hljs-meta">... </span>        inputs[<span class="hljs-string">&quot;normalized_text&quot;</span>] = inputs[<span class="hljs-string">&quot;normalized_text&quot;</span>].replace(src, dst)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs


<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">map</span>(cleanup_text)`}}),Pe=new I({}),ze=new k({props:{code:`from collections import defaultdict

speaker_counts = defaultdict(int)

for speaker_id in dataset["speaker_id"]:
    speaker_counts[speaker_id] += 1`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> defaultdict

<span class="hljs-meta">&gt;&gt;&gt; </span>speaker_counts = defaultdict(<span class="hljs-built_in">int</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> speaker_id <span class="hljs-keyword">in</span> dataset[<span class="hljs-string">&quot;speaker_id&quot;</span>]:
<span class="hljs-meta">... </span>    speaker_counts[speaker_id] += <span class="hljs-number">1</span>`}}),De=new k({props:{code:`import matplotlib.pyplot as plt

plt.figure()
plt.hist(speaker_counts.values(), bins=20)
plt.ylabel("Speakers")
plt.xlabel("Examples")
plt.show()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

<span class="hljs-meta">&gt;&gt;&gt; </span>plt.figure()
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.hist(speaker_counts.values(), bins=<span class="hljs-number">20</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.ylabel(<span class="hljs-string">&quot;Speakers&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.xlabel(<span class="hljs-string">&quot;Examples&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.show()`}}),Ie=new k({props:{code:`def select_speaker(speaker_id):
    return 100 <= speaker_counts[speaker_id] <= 400


dataset = dataset.filter(select_speaker, input_columns=["speaker_id"])`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">select_speaker</span>(<span class="hljs-params">speaker_id</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> <span class="hljs-number">100</span> &lt;= speaker_counts[speaker_id] &lt;= <span class="hljs-number">400</span>


<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">filter</span>(select_speaker, input_columns=[<span class="hljs-string">&quot;speaker_id&quot;</span>])`}}),Ce=new k({props:{code:'len(set(dataset["speaker_id"]))',highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">len</span>(<span class="hljs-built_in">set</span>(dataset[<span class="hljs-string">&quot;speaker_id&quot;</span>]))
<span class="hljs-number">42</span>`}}),Ne=new k({props:{code:"len(dataset)",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">len</span>(dataset)
<span class="hljs-number">9973</span>`}}),Fe=new I({}),He=new k({props:{code:`import os
import torch
from speechbrain.pretrained import EncoderClassifier

spk_model_name = "speechbrain/spkrec-xvect-voxceleb"

device = "cuda" if torch.cuda.is_available() else "cpu"
speaker_model = EncoderClassifier.from_hparams(
    source=spk_model_name,
    run_opts={"device": device},
    savedir=os.path.join("/tmp", spk_model_name),
)


def create_speaker_embedding(waveform):
    with torch.no_grad():
        speaker_embeddings = speaker_model.encode_batch(torch.tensor(waveform))
        speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=2)
        speaker_embeddings = speaker_embeddings.squeeze().cpu().numpy()
    return speaker_embeddings`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> os
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> speechbrain.pretrained <span class="hljs-keyword">import</span> EncoderClassifier

<span class="hljs-meta">&gt;&gt;&gt; </span>spk_model_name = <span class="hljs-string">&quot;speechbrain/spkrec-xvect-voxceleb&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>speaker_model = EncoderClassifier.from_hparams(
<span class="hljs-meta">... </span>    source=spk_model_name,
<span class="hljs-meta">... </span>    run_opts={<span class="hljs-string">&quot;device&quot;</span>: device},
<span class="hljs-meta">... </span>    savedir=os.path.join(<span class="hljs-string">&quot;/tmp&quot;</span>, spk_model_name),
<span class="hljs-meta">... </span>)


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">create_speaker_embedding</span>(<span class="hljs-params">waveform</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>        speaker_embeddings = speaker_model.encode_batch(torch.tensor(waveform))
<span class="hljs-meta">... </span>        speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=<span class="hljs-number">2</span>)
<span class="hljs-meta">... </span>        speaker_embeddings = speaker_embeddings.squeeze().cpu().numpy()
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> speaker_embeddings`}}),Le=new I({}),Ue=new k({props:{code:`def prepare_dataset(example):
    audio = example["audio"]

    example = processor(
        text=example["normalized_text"],
        audio_target=audio["array"],
        sampling_rate=audio["sampling_rate"],
        return_attention_mask=False,
    )

    # strip off the batch dimension
    example["labels"] = example["labels"][0]

    # use SpeechBrain to obtain x-vector
    example["speaker_embeddings"] = create_speaker_embedding(audio["array"])

    return example`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">prepare_dataset</span>(<span class="hljs-params">example</span>):
<span class="hljs-meta">... </span>    audio = example[<span class="hljs-string">&quot;audio&quot;</span>]

<span class="hljs-meta">... </span>    example = processor(
<span class="hljs-meta">... </span>        text=example[<span class="hljs-string">&quot;normalized_text&quot;</span>],
<span class="hljs-meta">... </span>        audio_target=audio[<span class="hljs-string">&quot;array&quot;</span>],
<span class="hljs-meta">... </span>        sampling_rate=audio[<span class="hljs-string">&quot;sampling_rate&quot;</span>],
<span class="hljs-meta">... </span>        return_attention_mask=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    )

<span class="hljs-meta">... </span>    <span class="hljs-comment"># strip off the batch dimension</span>
<span class="hljs-meta">... </span>    example[<span class="hljs-string">&quot;labels&quot;</span>] = example[<span class="hljs-string">&quot;labels&quot;</span>][<span class="hljs-number">0</span>]

<span class="hljs-meta">... </span>    <span class="hljs-comment"># use SpeechBrain to obtain x-vector</span>
<span class="hljs-meta">... </span>    example[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>] = create_speaker_embedding(audio[<span class="hljs-string">&quot;array&quot;</span>])

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> example`}}),Ve=new k({props:{code:`processed_example = prepare_dataset(dataset[0])
list(processed_example.keys())`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>processed_example = prepare_dataset(dataset[<span class="hljs-number">0</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">list</span>(processed_example.keys())
[<span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;stop_labels&#x27;</span>, <span class="hljs-string">&#x27;speaker_embeddings&#x27;</span>]`}}),We=new k({props:{code:'processed_example["speaker_embeddings"].shape',highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>processed_example[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>].shape
(<span class="hljs-number">512</span>,)`}}),Ge=new k({props:{code:`import matplotlib.pyplot as plt

plt.figure()
plt.imshow(processed_example["labels"].T)
plt.show()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

<span class="hljs-meta">&gt;&gt;&gt; </span>plt.figure()
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.imshow(processed_example[<span class="hljs-string">&quot;labels&quot;</span>].T)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.show()`}}),Me=new k({props:{code:"dataset = dataset.map(prepare_dataset, remove_columns=dataset.column_names)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">map</span>(prepare_dataset, remove_columns=dataset.column_names)'}}),Re=new k({props:{code:`def is_not_too_long(input_ids):
    input_length = len(input_ids)
    return input_length < 200


dataset = dataset.filter(is_not_too_long, input_columns=["input_ids"])
len(dataset)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">is_not_too_long</span>(<span class="hljs-params">input_ids</span>):
<span class="hljs-meta">... </span>    input_length = <span class="hljs-built_in">len</span>(input_ids)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> input_length &lt; <span class="hljs-number">200</span>


<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">filter</span>(is_not_too_long, input_columns=[<span class="hljs-string">&quot;input_ids&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">len</span>(dataset)
<span class="hljs-number">8259</span>`}}),Ye=new k({props:{code:"dataset = dataset.train_test_split(test_size=0.1)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.train_test_split(test_size=<span class="hljs-number">0.1</span>)'}}),Xe=new I({}),Je=new k({props:{code:`from dataclasses import dataclass
from typing import Any, Dict, List, Union


@dataclass
class TTSDataCollatorWithPadding:
    processor: Any

    def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:
        input_ids = [{"input_ids": feature["input_ids"]} for feature in features]
        label_features = [{"input_values": feature["labels"]} for feature in features]
        speaker_features = [feature["speaker_embeddings"] for feature in features]

        # collate the inputs and targets into a batch
        batch = processor.pad(input_ids=input_ids, labels=label_features, return_tensors="pt")

        # replace padding with -100 to ignore loss correctly
        batch["labels"] = batch["labels"].masked_fill(batch.decoder_attention_mask.unsqueeze(-1).ne(1), -100)

        # not used during fine-tuning
        del batch["decoder_attention_mask"]

        # round down target lengths to multiple of reduction factor
        if model.config.reduction_factor > 1:
            target_lengths = torch.tensor([len(feature["input_values"]) for feature in label_features])
            target_lengths = target_lengths.new(
                [length - length % model.config.reduction_factor for length in target_lengths]
            )
            max_length = max(target_lengths)
            batch["labels"] = batch["labels"][:, :max_length]

        # also add in the speaker embeddings
        batch["speaker_embeddings"] = torch.tensor(speaker_features)

        return batch`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">Any</span>, <span class="hljs-type">Dict</span>, <span class="hljs-type">List</span>, <span class="hljs-type">Union</span>


<span class="hljs-meta">&gt;&gt;&gt; </span>@dataclass
<span class="hljs-meta">... </span><span class="hljs-keyword">class</span> <span class="hljs-title class_">TTSDataCollatorWithPadding</span>:
<span class="hljs-meta">... </span>    processor: <span class="hljs-type">Any</span>

<span class="hljs-meta">... </span>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, features: <span class="hljs-type">List</span>[<span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Union</span>[<span class="hljs-type">List</span>[<span class="hljs-built_in">int</span>], torch.Tensor]]]</span>) -&gt; <span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor]:
<span class="hljs-meta">... </span>        input_ids = [{<span class="hljs-string">&quot;input_ids&quot;</span>: feature[<span class="hljs-string">&quot;input_ids&quot;</span>]} <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]
<span class="hljs-meta">... </span>        label_features = [{<span class="hljs-string">&quot;input_values&quot;</span>: feature[<span class="hljs-string">&quot;labels&quot;</span>]} <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]
<span class="hljs-meta">... </span>        speaker_features = [feature[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>] <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features]

<span class="hljs-meta">... </span>        <span class="hljs-comment"># collate the inputs and targets into a batch</span>
<span class="hljs-meta">... </span>        batch = processor.pad(input_ids=input_ids, labels=label_features, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">... </span>        <span class="hljs-comment"># replace padding with -100 to ignore loss correctly</span>
<span class="hljs-meta">... </span>        batch[<span class="hljs-string">&quot;labels&quot;</span>] = batch[<span class="hljs-string">&quot;labels&quot;</span>].masked_fill(batch.decoder_attention_mask.unsqueeze(-<span class="hljs-number">1</span>).ne(<span class="hljs-number">1</span>), -<span class="hljs-number">100</span>)

<span class="hljs-meta">... </span>        <span class="hljs-comment"># not used during fine-tuning</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">del</span> batch[<span class="hljs-string">&quot;decoder_attention_mask&quot;</span>]

<span class="hljs-meta">... </span>        <span class="hljs-comment"># round down target lengths to multiple of reduction factor</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">if</span> model.config.reduction_factor &gt; <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>            target_lengths = torch.tensor([<span class="hljs-built_in">len</span>(feature[<span class="hljs-string">&quot;input_values&quot;</span>]) <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> label_features])
<span class="hljs-meta">... </span>            target_lengths = target_lengths.new(
<span class="hljs-meta">... </span>                [length - length % model.config.reduction_factor <span class="hljs-keyword">for</span> length <span class="hljs-keyword">in</span> target_lengths]
<span class="hljs-meta">... </span>            )
<span class="hljs-meta">... </span>            max_length = <span class="hljs-built_in">max</span>(target_lengths)
<span class="hljs-meta">... </span>            batch[<span class="hljs-string">&quot;labels&quot;</span>] = batch[<span class="hljs-string">&quot;labels&quot;</span>][:, :max_length]

<span class="hljs-meta">... </span>        <span class="hljs-comment"># also add in the speaker embeddings</span>
<span class="hljs-meta">... </span>        batch[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>] = torch.tensor(speaker_features)

<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> batch`}}),Ke=new k({props:{code:"data_collator = TTSDataCollatorWithPadding(processor=processor)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = TTSDataCollatorWithPadding(processor=processor)'}}),Qe=new I({}),Ze=new k({props:{code:`from transformers import SpeechT5ForTextToSpeech

model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> SpeechT5ForTextToSpeech

<span class="hljs-meta">&gt;&gt;&gt; </span>model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)`}}),es=new k({props:{code:"model.config.use_cache = False",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.use_cache = <span class="hljs-literal">False</span>'}}),ss=new k({props:{code:`from transformers import Seq2SeqTrainingArguments

training_args = Seq2SeqTrainingArguments(
    output_dir="speecht5_finetuned_voxpopuli_nl",  # change to a repo name of your choice
    per_device_train_batch_size=4,
    gradient_accumulation_steps=8,
    learning_rate=1e-5,
    warmup_steps=500,
    max_steps=4000,
    gradient_checkpointing=True,
    fp16=True,
    evaluation_strategy="steps",
    per_device_eval_batch_size=2,
    save_steps=1000,
    eval_steps=1000,
    logging_steps=25,
    report_to=["tensorboard"],
    load_best_model_at_end=True,
    greater_is_better=False,
    label_names=["labels"],
    push_to_hub=True,
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainingArguments

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = Seq2SeqTrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;speecht5_finetuned_voxpopuli_nl&quot;</span>,  <span class="hljs-comment"># change to a repo name of your choice</span>
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    gradient_accumulation_steps=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">1e-5</span>,
<span class="hljs-meta">... </span>    warmup_steps=<span class="hljs-number">500</span>,
<span class="hljs-meta">... </span>    max_steps=<span class="hljs-number">4000</span>,
<span class="hljs-meta">... </span>    gradient_checkpointing=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    fp16=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    save_steps=<span class="hljs-number">1000</span>,
<span class="hljs-meta">... </span>    eval_steps=<span class="hljs-number">1000</span>,
<span class="hljs-meta">... </span>    logging_steps=<span class="hljs-number">25</span>,
<span class="hljs-meta">... </span>    report_to=[<span class="hljs-string">&quot;tensorboard&quot;</span>],
<span class="hljs-meta">... </span>    load_best_model_at_end=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    greater_is_better=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    label_names=[<span class="hljs-string">&quot;labels&quot;</span>],
<span class="hljs-meta">... </span>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`}}),ts=new k({props:{code:`from transformers import Seq2SeqTrainer

trainer = Seq2SeqTrainer(
    args=training_args,
    model=model,
    train_dataset=dataset["train"],
    eval_dataset=dataset["test"],
    data_collator=data_collator,
    tokenizer=processor.tokenizer,
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainer

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Seq2SeqTrainer(
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    train_dataset=dataset[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=dataset[<span class="hljs-string">&quot;test&quot;</span>],
<span class="hljs-meta">... </span>    data_collator=data_collator,
<span class="hljs-meta">... </span>    tokenizer=processor.tokenizer,
<span class="hljs-meta">... </span>)`}}),as=new k({props:{code:"trainer.train()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()'}}),ns=new k({props:{code:"trainer.push_to_hub()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),ls=new I({}),rs=new k({props:{code:'model = SpeechT5ForTextToSpeech.from_pretrained("YOUR_ACCOUNT/speecht5_finetuned_voxpopuli_nl")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model = SpeechT5ForTextToSpeech.from_pretrained(<span class="hljs-string">&quot;YOUR_ACCOUNT/speecht5_finetuned_voxpopuli_nl&quot;</span>)'}}),os=new k({props:{code:`example = dataset["test"][304]
speaker_embeddings = torch.tensor(example["speaker_embeddings"]).unsqueeze(0)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = dataset[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-number">304</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>speaker_embeddings = torch.tensor(example[<span class="hljs-string">&quot;speaker_embeddings&quot;</span>]).unsqueeze(<span class="hljs-number">0</span>)`}}),ps=new k({props:{code:'text = "hallo allemaal, ik praat nederlands. groetjes aan iedereen!"',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;hallo allemaal, ik praat nederlands. groetjes aan iedereen!&quot;</span>'}}),is=new k({props:{code:'inputs = processor(text=text, return_tensors="pt")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = processor(text=text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)'}}),hs=new k({props:{code:'spectrogram = model.generate_speech(inputs["input_ids"], speaker_embeddings)',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>spectrogram = model.generate_speech(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>], speaker_embeddings)'}}),cs=new k({props:{code:`plt.figure()
plt.imshow(spectrogram.T)
plt.show()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>plt.figure()
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.imshow(spectrogram.T)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.show()`}}),us=new k({props:{code:`with torch.no_grad():
    speech = vocoder(spectrogram)

from IPython.display import Audio

Audio(speech.numpy(), rate=16000)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    speech = vocoder(spectrogram)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> IPython.display <span class="hljs-keyword">import</span> Audio

<span class="hljs-meta">&gt;&gt;&gt; </span>Audio(speech.numpy(), rate=<span class="hljs-number">16000</span>)`}}),{c(){j=l("meta"),G=h(),y=l("h1"),$=l("a"),S=l("span"),u(v.$$.fragment),P=h(),ot=l("span"),bl=p("Text to speech"),Qt=h(),u(ue.$$.fragment),Zt=h(),B=l("p"),kl=p(`Text-to-speech (TTS) is the task of creating natural-sounding speech from text, where the speech can be generated in multiple
languages and for multiple speakers. The only text-to-speech model currently available in \u{1F917} Transformers
is `),ds=l("a"),vl=p("SpeechT5"),jl=p(`, though more will be added in the future. SpeechT5 is pre-trained on a combination of
speech-to-text and text-to-speech data, allowing it to learn a unified space of hidden representations shared by both text
and speech. This means that the same pre-trained model can be fine-tuned for different tasks. Furthermore, SpeechT5
supports multiple speakers through x-vector speaker embeddings.`),ea=h(),gs=l("p"),$l=p("This guide illustrates how to:"),sa=h(),M=l("ol"),E=l("li"),wl=p("Fine-tune "),_s=l("a"),yl=p("SpeechT5"),xl=p(" that was originally trained on English speech on the Dutch ("),pt=l("code"),ql=p("nl"),Tl=p(") language subset of the "),fe=l("a"),El=p("VoxPopuli"),Sl=p(" dataset."),Pl=h(),it=l("li"),zl=p("Use your fine-tuned model for inference."),ta=h(),bs=l("p"),Dl=p("Before you begin, make sure you have all the necessary libraries installed:"),aa=h(),u(de.$$.fragment),na=h(),ks=l("p"),Al=p("Install \u{1F917}Transformers from source as not all the SpeechT5 features have been merged into an official release yet:"),la=h(),u(ge.$$.fragment),ra=h(),u(R.$$.fragment),oa=h(),vs=l("p"),Il=p("We encourage you to log in to your Hugging Face account to upload and share your model with the community. When prompted, enter your token to log in:"),pa=h(),u(_e.$$.fragment),ia=h(),C=l("h2"),Y=l("a"),ht=l("span"),u(be.$$.fragment),Cl=h(),ct=l("span"),Nl=p("Load the dataset"),ha=h(),ke=l("p"),ve=l("a"),Fl=p("VoxPopuli"),Ol=p(` is a large-scale multilingual speech corpus consisting of
data sourced from 2009-2020 European Parliament event recordings. It contains labelled audio-transcription data for 15
European languages. In this guide, we are using the Dutch language subset, feel free to pick another subset.`),ca=h(),js=l("p"),Hl=p(`Note that VoxPopuli or any other automated speech recognition (ASR) dataset may not be the most suitable
option for training TTS models. The features that make it beneficial for ASR, such as excessive background noise, are
typically undesirable in TTS. However, finding top-quality, multilingual, and multi-speaker TTS datasets can be quite
challenging.`),ma=h(),$s=l("p"),Ll=p("Let\u2019s load the data:"),ua=h(),u(je.$$.fragment),fa=h(),ws=l("p"),Ul=p(`20968 examples should be sufficient for fine-tuning. SpeechT5 expects audio data to have a sampling rate of 16 kHz, so
make sure the examples in the dataset meet this requirement:`),da=h(),u($e.$$.fragment),ga=h(),N=l("h2"),X=l("a"),mt=l("span"),u(we.$$.fragment),Vl=h(),ut=l("span"),Wl=p("Preprocess the data"),_a=h(),ys=l("p"),Gl=p("Let\u2019s begin by defining the model checkpoint to use and loading the appropriate processor:"),ba=h(),u(ye.$$.fragment),ka=h(),F=l("h3"),J=l("a"),ft=l("span"),u(xe.$$.fragment),Bl=h(),dt=l("span"),Ml=p("Text cleanup for SpeechT5 tokenization"),va=h(),xs=l("p"),Rl=p("Start by cleaning up the text data. You\u2019ll need the tokenizer part of the processor to process the text:"),ja=h(),u(qe.$$.fragment),$a=h(),x=l("p"),Yl=p("The dataset examples contain "),gt=l("code"),Xl=p("raw_text"),Jl=p(" and "),_t=l("code"),Kl=p("normalized_text"),Ql=p(` features. When deciding which feature to use as the text input,
consider that the SpeechT5 tokenizer doesn\u2019t have any tokens for numbers. In `),bt=l("code"),Zl=p("normalized_text"),er=p(` the numbers are written
out as text. Thus, it is a better fit, and we recommend using    `),kt=l("code"),sr=p("normalized_text"),tr=p(" as input text."),wa=h(),q=l("p"),ar=p(`Because SpeechT5 was trained on the English language, it may not recognize certain characters in the Dutch dataset. If
left as is, these characters will be converted to `),vt=l("code"),nr=p("<unk>"),lr=p(" tokens. However, in Dutch, certain characters like "),jt=l("code"),rr=p("\xE0"),or=p(` are
used to stress syllables. In order to preserve the meaning of the text, we can replace this character with a regular `),$t=l("code"),pr=p("a"),ir=p("."),ya=h(),w=l("p"),hr=p("To identify unsupported tokens, extract all unique characters in the dataset using the "),wt=l("code"),cr=p("SpeechT5Tokenizer"),mr=p(` which
works with characters as tokens. To do this, write the `),yt=l("code"),ur=p("extract_all_chars"),fr=p(` mapping function that concatenates
the transcriptions from all examples into one string and converts it to a set of characters.
Make sure to set `),xt=l("code"),dr=p("batched=True"),gr=p(" and "),qt=l("code"),_r=p("batch_size=-1"),br=p(" in "),Tt=l("code"),kr=p("dataset.map()"),vr=p(` so that all transcriptions are available at once for
the mapping function.`),xa=h(),u(Te.$$.fragment),qa=h(),qs=l("p"),jr=p(`Now you have two sets of characters: one with the vocabulary from the dataset and one with the vocabulary from the tokenizer.
To identify any unsupported characters in the dataset, you can take the difference between these two sets. The resulting
set will contain the characters that are in the dataset but not in the tokenizer.`),Ta=h(),u(Ee.$$.fragment),Ea=h(),K=l("p"),$r=p(`To handle the unsupported characters identified in the previous step, define a function that maps these characters to
valid tokens. Note that spaces are already replaced by `),Et=l("code"),wr=p("\u2581"),yr=p(" in the tokenizer and don\u2019t need to be handled separately."),Sa=h(),u(Se.$$.fragment),Pa=h(),Ts=l("p"),xr=p("Now that you have dealt with special characters in the text, it\u2019s time to shift focus to the audio data."),za=h(),O=l("h3"),Q=l("a"),St=l("span"),u(Pe.$$.fragment),qr=h(),Pt=l("span"),Tr=p("Speakers"),Da=h(),Es=l("p"),Er=p(`The VoxPopuli dataset includes speech from multiple speakers, but how many speakers are represented in the dataset? To
determine this, we can count the number of unique speakers and the number of examples each speaker contributes to the dataset.
With a total of 20,968 examples in the dataset, this information will give us a better understanding of the distribution of
speakers and examples in the data.`),Aa=h(),u(ze.$$.fragment),Ia=h(),Ss=l("p"),Sr=p("By plotting a histogram you can get a sense of how much data there is for each speaker."),Ca=h(),u(De.$$.fragment),Na=h(),Ae=l("div"),Ps=l("img"),Fa=h(),zs=l("p"),Pr=p(`The histogram reveals that approximately one-third of the speakers in the dataset have fewer than 100 examples, while
around ten speakers have more than 500 examples. To improve training efficiency and balance the dataset, we can limit
the data to speakers with between 100 and 400 examples.`),Oa=h(),u(Ie.$$.fragment),Ha=h(),Ds=l("p"),zr=p("Let\u2019s check how many speakers remain:"),La=h(),u(Ce.$$.fragment),Ua=h(),As=l("p"),Dr=p("Let\u2019s see how many examples are left:"),Va=h(),u(Ne.$$.fragment),Wa=h(),Is=l("p"),Ar=p("You are left with just under 10,000 examples from approximately 40 unique speakers, which should be sufficient."),Ga=h(),Cs=l("p"),Ir=p(`Note that some speakers with few examples may actually have more audio available if the examples are long. However,
determining the total amount of audio for each speaker requires scanning through the entire dataset, which is a
time-consuming process that involves loading and decoding each audio file. As such, we have chosen to skip this step here.`),Ba=h(),H=l("h3"),Z=l("a"),zt=l("span"),u(Fe.$$.fragment),Cr=h(),Dt=l("span"),Nr=p("Speaker embeddings"),Ma=h(),ee=l("p"),Fr=p(`To enable the TTS model to differentiate between multiple speakers, you\u2019ll need to create a speaker embedding for each example.
The speaker embedding is an additional input into the model that captures a particular speaker\u2019s voice characteristics.
To generate these speaker embeddings, use the pre-trained `),Oe=l("a"),Or=p("spkrec-xvect-voxceleb"),Hr=p(`
model from SpeechBrain.`),Ra=h(),se=l("p"),Lr=p("Create a function "),At=l("code"),Ur=p("create_speaker_embedding()"),Vr=p(` that takes an input audio waveform and outputs a 512-element vector
containing the corresponding speaker embedding.`),Ya=h(),u(He.$$.fragment),Xa=h(),te=l("p"),Wr=p("It\u2019s important to note that the "),It=l("code"),Gr=p("speechbrain/spkrec-xvect-voxceleb"),Br=p(` model was trained on English speech from the VoxCeleb
dataset, whereas the training examples in this guide are in Dutch. While we believe that this model will still generate
reasonable speaker embeddings for our Dutch dataset, this assumption may not hold true in all cases.`),Ja=h(),Ns=l("p"),Mr=p(`For optimal results, we recommend training an X-vector model on the target speech first. This will ensure that the model
is better able to capture the unique voice characteristics present in the Dutch language.`),Ka=h(),L=l("h3"),ae=l("a"),Ct=l("span"),u(Le.$$.fragment),Rr=h(),Nt=l("span"),Yr=p("Processing the dataset"),Qa=h(),z=l("p"),Xr=p("Finally, let\u2019s process the data into the format the model expects. Create a "),Ft=l("code"),Jr=p("prepare_dataset"),Kr=p(` function that takes in a
single example and uses the `),Ot=l("code"),Qr=p("SpeechT5Processor"),Zr=p(` object to tokenize the input text and load the target audio into a log-mel spectrogram.
It should also add the speaker embeddings as an additional input.`),Za=h(),u(Ue.$$.fragment),en=h(),Fs=l("p"),eo=p("Verify the processing is correct by looking at a single example:"),sn=h(),u(Ve.$$.fragment),tn=h(),Os=l("p"),so=p("Speaker embeddings should be a 512-element vector:"),an=h(),u(We.$$.fragment),nn=h(),Hs=l("p"),to=p("The labels should be a log-mel spectrogram with 80 mel bins."),ln=h(),u(Ge.$$.fragment),rn=h(),Be=l("div"),Ls=l("img"),on=h(),Us=l("p"),ao=p(`Side note: If you find this spectrogram confusing, it may be due to your familiarity with the convention of placing low frequencies
at the bottom and high frequencies at the top of a plot. However, when plotting spectrograms as an image using the matplotlib library,
the y-axis is flipped and the spectrograms appear upside down.`),pn=h(),Vs=l("p"),no=p("Now apply the processing function to the entire dataset. This will take between 5 and 10 minutes."),hn=h(),u(Me.$$.fragment),cn=h(),Ws=l("p"),lo=p(`You\u2019ll see a warning saying that some examples in the dataset are longer than the maximum input length the model can handle (600 tokens).
Remove those examples from the dataset. Here we go even further and to allow for larger batch sizes we remove anything over 200 tokens.`),mn=h(),u(Re.$$.fragment),un=h(),Gs=l("p"),ro=p("Next, create a basic train/test split:"),fn=h(),u(Ye.$$.fragment),dn=h(),U=l("h3"),ne=l("a"),Ht=l("span"),u(Xe.$$.fragment),oo=h(),Lt=l("span"),po=p("Data collator"),gn=h(),le=l("p"),io=p(`In order to combine multiple examples into a batch, you need to define a custom data collator. This collator will pad shorter sequences with padding
tokens, ensuring that all examples have the same length. For the spectrogram labels, the padded portions are replaced with the special value `),Ut=l("code"),ho=p("-100"),co=p(`. This special value
instructs the model to ignore that part of the spectrogram when calculating the spectrogram loss.`),_n=h(),u(Je.$$.fragment),bn=h(),Bs=l("p"),mo=p(`In SpeechT5, the input to the decoder part of the model is reduced by a factor 2. In other words, it throws away every
other timestep from the target sequence. The decoder then predicts a sequence that is twice as long. Since the original
target sequence length may be odd, the data collator makes sure to round the maximum length of the batch down to be a
multiple of 2.`),kn=h(),u(Ke.$$.fragment),vn=h(),V=l("h2"),re=l("a"),Vt=l("span"),u(Qe.$$.fragment),uo=h(),Wt=l("span"),fo=p("Train the model"),jn=h(),Ms=l("p"),go=p("Load the pre-trained model from the same checkpoint as you used for loading the processor:"),$n=h(),u(Ze.$$.fragment),wn=h(),oe=l("p"),_o=p("The "),Gt=l("code"),bo=p("use_cache=True"),ko=p(" option is incompatible with gradient checkpointing. Disable it for training."),yn=h(),u(es.$$.fragment),xn=h(),Rs=l("p"),vo=p(`Define the training arguments. Here we are not computing any evaluation metrics during the training process. Instead, we\u2019ll
only look at the loss:`),qn=h(),u(ss.$$.fragment),Tn=h(),pe=l("p"),jo=p("Instantiate the "),Bt=l("code"),$o=p("Trainer"),wo=p(" object  and pass the model, dataset, and data collator to it."),En=h(),u(ts.$$.fragment),Sn=h(),D=l("p"),yo=p(`And with that, you\u2019re ready to start training! Training will take several hours. Depending on your GPU,
it is possible that you will encounter a CUDA \u201Cout-of-memory\u201D error when you start training. In this case, you can reduce
the `),Mt=l("code"),xo=p("per_device_train_batch_size"),qo=p(" incrementally by factors of 2 and increase "),Rt=l("code"),To=p("gradient_accumulation_steps"),Eo=p(" by 2x to compensate."),Pn=h(),u(as.$$.fragment),zn=h(),Ys=l("p"),So=p("Push the final model to the \u{1F917} Hub:"),Dn=h(),u(ns.$$.fragment),An=h(),W=l("h2"),ie=l("a"),Yt=l("span"),u(ls.$$.fragment),Po=h(),Xt=l("span"),zo=p("Inference"),In=h(),Xs=l("p"),Do=p(`Great, now that you\u2019ve fine-tuned a model, you can use it for inference!
Load the model from the \u{1F917} Hub (make sure to use your account name in the following code snippet):`),Cn=h(),u(rs.$$.fragment),Nn=h(),Js=l("p"),Ao=p("Pick an example, here we\u2019ll take one from the test dataset. Obtain a speaker embedding."),Fn=h(),u(os.$$.fragment),On=h(),Ks=l("p"),Io=p("Define some input text and tokenize it."),Hn=h(),u(ps.$$.fragment),Ln=h(),Qs=l("p"),Co=p("Preprocess the input text:"),Un=h(),u(is.$$.fragment),Vn=h(),Zs=l("p"),No=p("Create a spectrogram with your model:"),Wn=h(),u(hs.$$.fragment),Gn=h(),et=l("p"),Fo=p("Visualize the spectrogram, if you\u2019d like to:"),Bn=h(),u(cs.$$.fragment),Mn=h(),ms=l("div"),st=l("img"),Rn=h(),tt=l("p"),Oo=p("Finally, use the vocoder to turn the spectrogram into sound."),Yn=h(),u(us.$$.fragment),Xn=h(),at=l("p"),Ho=p(`In our experience, obtaining satisfactory results from this model can be challenging. The quality of the speaker
embeddings appears to be a significant factor. Since SpeechT5 was pre-trained with English x-vectors, it performs best
when using English speaker embeddings. If the synthesized speech sounds poor, try using a different speaker embedding.`),Jn=h(),he=l("p"),Lo=p(`Increasing the training duration is also likely to enhance the quality of the results. Even so, the speech clearly is Dutch instead of English, and it does
capture the voice characteristics of the speaker (compare to the original audio in the example).
Another thing to experiment with is the model\u2019s configuration. For example, try using `),Jt=l("code"),Uo=p("config.reduction_factor = 1"),Vo=p(` to
see if this improves the results.`),Kn=h(),nt=l("p"),Wo=p(`Finally, it is essential to consider ethical considerations. Although TTS technology has numerous useful applications, it
may also be used for malicious purposes, such as impersonating someone\u2019s voice without their knowledge or consent. Please
use TTS judiciously and responsibly.`),this.h()},l(e){const t=Mi('[data-svelte="svelte-1phssyn"]',document.head);j=r(t,"META",{name:!0,content:!0}),t.forEach(s),G=c(e),y=r(e,"H1",{class:!0});var fs=o(y);$=r(fs,"A",{id:!0,class:!0,href:!0});var Xo=o($);S=r(Xo,"SPAN",{});var Jo=o(S);f(v.$$.fragment,Jo),Jo.forEach(s),Xo.forEach(s),P=c(fs),ot=r(fs,"SPAN",{});var Ko=o(ot);bl=i(Ko,"Text to speech"),Ko.forEach(s),fs.forEach(s),Qt=c(e),f(ue.$$.fragment,e),Zt=c(e),B=r(e,"P",{});var Zn=o(B);kl=i(Zn,`Text-to-speech (TTS) is the task of creating natural-sounding speech from text, where the speech can be generated in multiple
languages and for multiple speakers. The only text-to-speech model currently available in \u{1F917} Transformers
is `),ds=r(Zn,"A",{href:!0});var Qo=o(ds);vl=i(Qo,"SpeechT5"),Qo.forEach(s),jl=i(Zn,`, though more will be added in the future. SpeechT5 is pre-trained on a combination of
speech-to-text and text-to-speech data, allowing it to learn a unified space of hidden representations shared by both text
and speech. This means that the same pre-trained model can be fine-tuned for different tasks. Furthermore, SpeechT5
supports multiple speakers through x-vector speaker embeddings.`),Zn.forEach(s),ea=c(e),gs=r(e,"P",{});var Zo=o(gs);$l=i(Zo,"This guide illustrates how to:"),Zo.forEach(s),sa=c(e),M=r(e,"OL",{});var el=o(M);E=r(el,"LI",{});var ce=o(E);wl=i(ce,"Fine-tune "),_s=r(ce,"A",{href:!0});var ep=o(_s);yl=i(ep,"SpeechT5"),ep.forEach(s),xl=i(ce," that was originally trained on English speech on the Dutch ("),pt=r(ce,"CODE",{});var sp=o(pt);ql=i(sp,"nl"),sp.forEach(s),Tl=i(ce,") language subset of the "),fe=r(ce,"A",{href:!0,rel:!0});var tp=o(fe);El=i(tp,"VoxPopuli"),tp.forEach(s),Sl=i(ce," dataset."),ce.forEach(s),Pl=c(el),it=r(el,"LI",{});var ap=o(it);zl=i(ap,"Use your fine-tuned model for inference."),ap.forEach(s),el.forEach(s),ta=c(e),bs=r(e,"P",{});var np=o(bs);Dl=i(np,"Before you begin, make sure you have all the necessary libraries installed:"),np.forEach(s),aa=c(e),f(de.$$.fragment,e),na=c(e),ks=r(e,"P",{});var lp=o(ks);Al=i(lp,"Install \u{1F917}Transformers from source as not all the SpeechT5 features have been merged into an official release yet:"),lp.forEach(s),la=c(e),f(ge.$$.fragment,e),ra=c(e),f(R.$$.fragment,e),oa=c(e),vs=r(e,"P",{});var rp=o(vs);Il=i(rp,"We encourage you to log in to your Hugging Face account to upload and share your model with the community. When prompted, enter your token to log in:"),rp.forEach(s),pa=c(e),f(_e.$$.fragment,e),ia=c(e),C=r(e,"H2",{class:!0});var sl=o(C);Y=r(sl,"A",{id:!0,class:!0,href:!0});var op=o(Y);ht=r(op,"SPAN",{});var pp=o(ht);f(be.$$.fragment,pp),pp.forEach(s),op.forEach(s),Cl=c(sl),ct=r(sl,"SPAN",{});var ip=o(ct);Nl=i(ip,"Load the dataset"),ip.forEach(s),sl.forEach(s),ha=c(e),ke=r(e,"P",{});var Go=o(ke);ve=r(Go,"A",{href:!0,rel:!0});var hp=o(ve);Fl=i(hp,"VoxPopuli"),hp.forEach(s),Ol=i(Go,` is a large-scale multilingual speech corpus consisting of
data sourced from 2009-2020 European Parliament event recordings. It contains labelled audio-transcription data for 15
European languages. In this guide, we are using the Dutch language subset, feel free to pick another subset.`),Go.forEach(s),ca=c(e),js=r(e,"P",{});var cp=o(js);Hl=i(cp,`Note that VoxPopuli or any other automated speech recognition (ASR) dataset may not be the most suitable
option for training TTS models. The features that make it beneficial for ASR, such as excessive background noise, are
typically undesirable in TTS. However, finding top-quality, multilingual, and multi-speaker TTS datasets can be quite
challenging.`),cp.forEach(s),ma=c(e),$s=r(e,"P",{});var mp=o($s);Ll=i(mp,"Let\u2019s load the data:"),mp.forEach(s),ua=c(e),f(je.$$.fragment,e),fa=c(e),ws=r(e,"P",{});var up=o(ws);Ul=i(up,`20968 examples should be sufficient for fine-tuning. SpeechT5 expects audio data to have a sampling rate of 16 kHz, so
make sure the examples in the dataset meet this requirement:`),up.forEach(s),da=c(e),f($e.$$.fragment,e),ga=c(e),N=r(e,"H2",{class:!0});var tl=o(N);X=r(tl,"A",{id:!0,class:!0,href:!0});var fp=o(X);mt=r(fp,"SPAN",{});var dp=o(mt);f(we.$$.fragment,dp),dp.forEach(s),fp.forEach(s),Vl=c(tl),ut=r(tl,"SPAN",{});var gp=o(ut);Wl=i(gp,"Preprocess the data"),gp.forEach(s),tl.forEach(s),_a=c(e),ys=r(e,"P",{});var _p=o(ys);Gl=i(_p,"Let\u2019s begin by defining the model checkpoint to use and loading the appropriate processor:"),_p.forEach(s),ba=c(e),f(ye.$$.fragment,e),ka=c(e),F=r(e,"H3",{class:!0});var al=o(F);J=r(al,"A",{id:!0,class:!0,href:!0});var bp=o(J);ft=r(bp,"SPAN",{});var kp=o(ft);f(xe.$$.fragment,kp),kp.forEach(s),bp.forEach(s),Bl=c(al),dt=r(al,"SPAN",{});var vp=o(dt);Ml=i(vp,"Text cleanup for SpeechT5 tokenization"),vp.forEach(s),al.forEach(s),va=c(e),xs=r(e,"P",{});var jp=o(xs);Rl=i(jp,"Start by cleaning up the text data. You\u2019ll need the tokenizer part of the processor to process the text:"),jp.forEach(s),ja=c(e),f(qe.$$.fragment,e),$a=c(e),x=r(e,"P",{});var A=o(x);Yl=i(A,"The dataset examples contain "),gt=r(A,"CODE",{});var $p=o(gt);Xl=i($p,"raw_text"),$p.forEach(s),Jl=i(A," and "),_t=r(A,"CODE",{});var wp=o(_t);Kl=i(wp,"normalized_text"),wp.forEach(s),Ql=i(A,` features. When deciding which feature to use as the text input,
consider that the SpeechT5 tokenizer doesn\u2019t have any tokens for numbers. In `),bt=r(A,"CODE",{});var yp=o(bt);Zl=i(yp,"normalized_text"),yp.forEach(s),er=i(A,` the numbers are written
out as text. Thus, it is a better fit, and we recommend using    `),kt=r(A,"CODE",{});var xp=o(kt);sr=i(xp,"normalized_text"),xp.forEach(s),tr=i(A," as input text."),A.forEach(s),wa=c(e),q=r(e,"P",{});var me=o(q);ar=i(me,`Because SpeechT5 was trained on the English language, it may not recognize certain characters in the Dutch dataset. If
left as is, these characters will be converted to `),vt=r(me,"CODE",{});var qp=o(vt);nr=i(qp,"<unk>"),qp.forEach(s),lr=i(me," tokens. However, in Dutch, certain characters like "),jt=r(me,"CODE",{});var Tp=o(jt);rr=i(Tp,"\xE0"),Tp.forEach(s),or=i(me,` are
used to stress syllables. In order to preserve the meaning of the text, we can replace this character with a regular `),$t=r(me,"CODE",{});var Ep=o($t);pr=i(Ep,"a"),Ep.forEach(s),ir=i(me,"."),me.forEach(s),ya=c(e),w=r(e,"P",{});var T=o(w);hr=i(T,"To identify unsupported tokens, extract all unique characters in the dataset using the "),wt=r(T,"CODE",{});var Sp=o(wt);cr=i(Sp,"SpeechT5Tokenizer"),Sp.forEach(s),mr=i(T,` which
works with characters as tokens. To do this, write the `),yt=r(T,"CODE",{});var Pp=o(yt);ur=i(Pp,"extract_all_chars"),Pp.forEach(s),fr=i(T,` mapping function that concatenates
the transcriptions from all examples into one string and converts it to a set of characters.
Make sure to set `),xt=r(T,"CODE",{});var zp=o(xt);dr=i(zp,"batched=True"),zp.forEach(s),gr=i(T," and "),qt=r(T,"CODE",{});var Dp=o(qt);_r=i(Dp,"batch_size=-1"),Dp.forEach(s),br=i(T," in "),Tt=r(T,"CODE",{});var Ap=o(Tt);kr=i(Ap,"dataset.map()"),Ap.forEach(s),vr=i(T,` so that all transcriptions are available at once for
the mapping function.`),T.forEach(s),xa=c(e),f(Te.$$.fragment,e),qa=c(e),qs=r(e,"P",{});var Ip=o(qs);jr=i(Ip,`Now you have two sets of characters: one with the vocabulary from the dataset and one with the vocabulary from the tokenizer.
To identify any unsupported characters in the dataset, you can take the difference between these two sets. The resulting
set will contain the characters that are in the dataset but not in the tokenizer.`),Ip.forEach(s),Ta=c(e),f(Ee.$$.fragment,e),Ea=c(e),K=r(e,"P",{});var nl=o(K);$r=i(nl,`To handle the unsupported characters identified in the previous step, define a function that maps these characters to
valid tokens. Note that spaces are already replaced by `),Et=r(nl,"CODE",{});var Cp=o(Et);wr=i(Cp,"\u2581"),Cp.forEach(s),yr=i(nl," in the tokenizer and don\u2019t need to be handled separately."),nl.forEach(s),Sa=c(e),f(Se.$$.fragment,e),Pa=c(e),Ts=r(e,"P",{});var Np=o(Ts);xr=i(Np,"Now that you have dealt with special characters in the text, it\u2019s time to shift focus to the audio data."),Np.forEach(s),za=c(e),O=r(e,"H3",{class:!0});var ll=o(O);Q=r(ll,"A",{id:!0,class:!0,href:!0});var Fp=o(Q);St=r(Fp,"SPAN",{});var Op=o(St);f(Pe.$$.fragment,Op),Op.forEach(s),Fp.forEach(s),qr=c(ll),Pt=r(ll,"SPAN",{});var Hp=o(Pt);Tr=i(Hp,"Speakers"),Hp.forEach(s),ll.forEach(s),Da=c(e),Es=r(e,"P",{});var Lp=o(Es);Er=i(Lp,`The VoxPopuli dataset includes speech from multiple speakers, but how many speakers are represented in the dataset? To
determine this, we can count the number of unique speakers and the number of examples each speaker contributes to the dataset.
With a total of 20,968 examples in the dataset, this information will give us a better understanding of the distribution of
speakers and examples in the data.`),Lp.forEach(s),Aa=c(e),f(ze.$$.fragment,e),Ia=c(e),Ss=r(e,"P",{});var Up=o(Ss);Sr=i(Up,"By plotting a histogram you can get a sense of how much data there is for each speaker."),Up.forEach(s),Ca=c(e),f(De.$$.fragment,e),Na=c(e),Ae=r(e,"DIV",{class:!0});var Vp=o(Ae);Ps=r(Vp,"IMG",{src:!0,alt:!0}),Vp.forEach(s),Fa=c(e),zs=r(e,"P",{});var Wp=o(zs);Pr=i(Wp,`The histogram reveals that approximately one-third of the speakers in the dataset have fewer than 100 examples, while
around ten speakers have more than 500 examples. To improve training efficiency and balance the dataset, we can limit
the data to speakers with between 100 and 400 examples.`),Wp.forEach(s),Oa=c(e),f(Ie.$$.fragment,e),Ha=c(e),Ds=r(e,"P",{});var Gp=o(Ds);zr=i(Gp,"Let\u2019s check how many speakers remain:"),Gp.forEach(s),La=c(e),f(Ce.$$.fragment,e),Ua=c(e),As=r(e,"P",{});var Bp=o(As);Dr=i(Bp,"Let\u2019s see how many examples are left:"),Bp.forEach(s),Va=c(e),f(Ne.$$.fragment,e),Wa=c(e),Is=r(e,"P",{});var Mp=o(Is);Ar=i(Mp,"You are left with just under 10,000 examples from approximately 40 unique speakers, which should be sufficient."),Mp.forEach(s),Ga=c(e),Cs=r(e,"P",{});var Rp=o(Cs);Ir=i(Rp,`Note that some speakers with few examples may actually have more audio available if the examples are long. However,
determining the total amount of audio for each speaker requires scanning through the entire dataset, which is a
time-consuming process that involves loading and decoding each audio file. As such, we have chosen to skip this step here.`),Rp.forEach(s),Ba=c(e),H=r(e,"H3",{class:!0});var rl=o(H);Z=r(rl,"A",{id:!0,class:!0,href:!0});var Yp=o(Z);zt=r(Yp,"SPAN",{});var Xp=o(zt);f(Fe.$$.fragment,Xp),Xp.forEach(s),Yp.forEach(s),Cr=c(rl),Dt=r(rl,"SPAN",{});var Jp=o(Dt);Nr=i(Jp,"Speaker embeddings"),Jp.forEach(s),rl.forEach(s),Ma=c(e),ee=r(e,"P",{});var ol=o(ee);Fr=i(ol,`To enable the TTS model to differentiate between multiple speakers, you\u2019ll need to create a speaker embedding for each example.
The speaker embedding is an additional input into the model that captures a particular speaker\u2019s voice characteristics.
To generate these speaker embeddings, use the pre-trained `),Oe=r(ol,"A",{href:!0,rel:!0});var Kp=o(Oe);Or=i(Kp,"spkrec-xvect-voxceleb"),Kp.forEach(s),Hr=i(ol,`
model from SpeechBrain.`),ol.forEach(s),Ra=c(e),se=r(e,"P",{});var pl=o(se);Lr=i(pl,"Create a function "),At=r(pl,"CODE",{});var Qp=o(At);Ur=i(Qp,"create_speaker_embedding()"),Qp.forEach(s),Vr=i(pl,` that takes an input audio waveform and outputs a 512-element vector
containing the corresponding speaker embedding.`),pl.forEach(s),Ya=c(e),f(He.$$.fragment,e),Xa=c(e),te=r(e,"P",{});var il=o(te);Wr=i(il,"It\u2019s important to note that the "),It=r(il,"CODE",{});var Zp=o(It);Gr=i(Zp,"speechbrain/spkrec-xvect-voxceleb"),Zp.forEach(s),Br=i(il,` model was trained on English speech from the VoxCeleb
dataset, whereas the training examples in this guide are in Dutch. While we believe that this model will still generate
reasonable speaker embeddings for our Dutch dataset, this assumption may not hold true in all cases.`),il.forEach(s),Ja=c(e),Ns=r(e,"P",{});var ei=o(Ns);Mr=i(ei,`For optimal results, we recommend training an X-vector model on the target speech first. This will ensure that the model
is better able to capture the unique voice characteristics present in the Dutch language.`),ei.forEach(s),Ka=c(e),L=r(e,"H3",{class:!0});var hl=o(L);ae=r(hl,"A",{id:!0,class:!0,href:!0});var si=o(ae);Ct=r(si,"SPAN",{});var ti=o(Ct);f(Le.$$.fragment,ti),ti.forEach(s),si.forEach(s),Rr=c(hl),Nt=r(hl,"SPAN",{});var ai=o(Nt);Yr=i(ai,"Processing the dataset"),ai.forEach(s),hl.forEach(s),Qa=c(e),z=r(e,"P",{});var lt=o(z);Xr=i(lt,"Finally, let\u2019s process the data into the format the model expects. Create a "),Ft=r(lt,"CODE",{});var ni=o(Ft);Jr=i(ni,"prepare_dataset"),ni.forEach(s),Kr=i(lt,` function that takes in a
single example and uses the `),Ot=r(lt,"CODE",{});var li=o(Ot);Qr=i(li,"SpeechT5Processor"),li.forEach(s),Zr=i(lt,` object to tokenize the input text and load the target audio into a log-mel spectrogram.
It should also add the speaker embeddings as an additional input.`),lt.forEach(s),Za=c(e),f(Ue.$$.fragment,e),en=c(e),Fs=r(e,"P",{});var ri=o(Fs);eo=i(ri,"Verify the processing is correct by looking at a single example:"),ri.forEach(s),sn=c(e),f(Ve.$$.fragment,e),tn=c(e),Os=r(e,"P",{});var oi=o(Os);so=i(oi,"Speaker embeddings should be a 512-element vector:"),oi.forEach(s),an=c(e),f(We.$$.fragment,e),nn=c(e),Hs=r(e,"P",{});var pi=o(Hs);to=i(pi,"The labels should be a log-mel spectrogram with 80 mel bins."),pi.forEach(s),ln=c(e),f(Ge.$$.fragment,e),rn=c(e),Be=r(e,"DIV",{class:!0});var ii=o(Be);Ls=r(ii,"IMG",{src:!0,alt:!0}),ii.forEach(s),on=c(e),Us=r(e,"P",{});var hi=o(Us);ao=i(hi,`Side note: If you find this spectrogram confusing, it may be due to your familiarity with the convention of placing low frequencies
at the bottom and high frequencies at the top of a plot. However, when plotting spectrograms as an image using the matplotlib library,
the y-axis is flipped and the spectrograms appear upside down.`),hi.forEach(s),pn=c(e),Vs=r(e,"P",{});var ci=o(Vs);no=i(ci,"Now apply the processing function to the entire dataset. This will take between 5 and 10 minutes."),ci.forEach(s),hn=c(e),f(Me.$$.fragment,e),cn=c(e),Ws=r(e,"P",{});var mi=o(Ws);lo=i(mi,`You\u2019ll see a warning saying that some examples in the dataset are longer than the maximum input length the model can handle (600 tokens).
Remove those examples from the dataset. Here we go even further and to allow for larger batch sizes we remove anything over 200 tokens.`),mi.forEach(s),mn=c(e),f(Re.$$.fragment,e),un=c(e),Gs=r(e,"P",{});var ui=o(Gs);ro=i(ui,"Next, create a basic train/test split:"),ui.forEach(s),fn=c(e),f(Ye.$$.fragment,e),dn=c(e),U=r(e,"H3",{class:!0});var cl=o(U);ne=r(cl,"A",{id:!0,class:!0,href:!0});var fi=o(ne);Ht=r(fi,"SPAN",{});var di=o(Ht);f(Xe.$$.fragment,di),di.forEach(s),fi.forEach(s),oo=c(cl),Lt=r(cl,"SPAN",{});var gi=o(Lt);po=i(gi,"Data collator"),gi.forEach(s),cl.forEach(s),gn=c(e),le=r(e,"P",{});var ml=o(le);io=i(ml,`In order to combine multiple examples into a batch, you need to define a custom data collator. This collator will pad shorter sequences with padding
tokens, ensuring that all examples have the same length. For the spectrogram labels, the padded portions are replaced with the special value `),Ut=r(ml,"CODE",{});var _i=o(Ut);ho=i(_i,"-100"),_i.forEach(s),co=i(ml,`. This special value
instructs the model to ignore that part of the spectrogram when calculating the spectrogram loss.`),ml.forEach(s),_n=c(e),f(Je.$$.fragment,e),bn=c(e),Bs=r(e,"P",{});var bi=o(Bs);mo=i(bi,`In SpeechT5, the input to the decoder part of the model is reduced by a factor 2. In other words, it throws away every
other timestep from the target sequence. The decoder then predicts a sequence that is twice as long. Since the original
target sequence length may be odd, the data collator makes sure to round the maximum length of the batch down to be a
multiple of 2.`),bi.forEach(s),kn=c(e),f(Ke.$$.fragment,e),vn=c(e),V=r(e,"H2",{class:!0});var ul=o(V);re=r(ul,"A",{id:!0,class:!0,href:!0});var ki=o(re);Vt=r(ki,"SPAN",{});var vi=o(Vt);f(Qe.$$.fragment,vi),vi.forEach(s),ki.forEach(s),uo=c(ul),Wt=r(ul,"SPAN",{});var ji=o(Wt);fo=i(ji,"Train the model"),ji.forEach(s),ul.forEach(s),jn=c(e),Ms=r(e,"P",{});var $i=o(Ms);go=i($i,"Load the pre-trained model from the same checkpoint as you used for loading the processor:"),$i.forEach(s),$n=c(e),f(Ze.$$.fragment,e),wn=c(e),oe=r(e,"P",{});var fl=o(oe);_o=i(fl,"The "),Gt=r(fl,"CODE",{});var wi=o(Gt);bo=i(wi,"use_cache=True"),wi.forEach(s),ko=i(fl," option is incompatible with gradient checkpointing. Disable it for training."),fl.forEach(s),yn=c(e),f(es.$$.fragment,e),xn=c(e),Rs=r(e,"P",{});var yi=o(Rs);vo=i(yi,`Define the training arguments. Here we are not computing any evaluation metrics during the training process. Instead, we\u2019ll
only look at the loss:`),yi.forEach(s),qn=c(e),f(ss.$$.fragment,e),Tn=c(e),pe=r(e,"P",{});var dl=o(pe);jo=i(dl,"Instantiate the "),Bt=r(dl,"CODE",{});var xi=o(Bt);$o=i(xi,"Trainer"),xi.forEach(s),wo=i(dl," object  and pass the model, dataset, and data collator to it."),dl.forEach(s),En=c(e),f(ts.$$.fragment,e),Sn=c(e),D=r(e,"P",{});var rt=o(D);yo=i(rt,`And with that, you\u2019re ready to start training! Training will take several hours. Depending on your GPU,
it is possible that you will encounter a CUDA \u201Cout-of-memory\u201D error when you start training. In this case, you can reduce
the `),Mt=r(rt,"CODE",{});var qi=o(Mt);xo=i(qi,"per_device_train_batch_size"),qi.forEach(s),qo=i(rt," incrementally by factors of 2 and increase "),Rt=r(rt,"CODE",{});var Ti=o(Rt);To=i(Ti,"gradient_accumulation_steps"),Ti.forEach(s),Eo=i(rt," by 2x to compensate."),rt.forEach(s),Pn=c(e),f(as.$$.fragment,e),zn=c(e),Ys=r(e,"P",{});var Ei=o(Ys);So=i(Ei,"Push the final model to the \u{1F917} Hub:"),Ei.forEach(s),Dn=c(e),f(ns.$$.fragment,e),An=c(e),W=r(e,"H2",{class:!0});var gl=o(W);ie=r(gl,"A",{id:!0,class:!0,href:!0});var Si=o(ie);Yt=r(Si,"SPAN",{});var Pi=o(Yt);f(ls.$$.fragment,Pi),Pi.forEach(s),Si.forEach(s),Po=c(gl),Xt=r(gl,"SPAN",{});var zi=o(Xt);zo=i(zi,"Inference"),zi.forEach(s),gl.forEach(s),In=c(e),Xs=r(e,"P",{});var Di=o(Xs);Do=i(Di,`Great, now that you\u2019ve fine-tuned a model, you can use it for inference!
Load the model from the \u{1F917} Hub (make sure to use your account name in the following code snippet):`),Di.forEach(s),Cn=c(e),f(rs.$$.fragment,e),Nn=c(e),Js=r(e,"P",{});var Ai=o(Js);Ao=i(Ai,"Pick an example, here we\u2019ll take one from the test dataset. Obtain a speaker embedding."),Ai.forEach(s),Fn=c(e),f(os.$$.fragment,e),On=c(e),Ks=r(e,"P",{});var Ii=o(Ks);Io=i(Ii,"Define some input text and tokenize it."),Ii.forEach(s),Hn=c(e),f(ps.$$.fragment,e),Ln=c(e),Qs=r(e,"P",{});var Ci=o(Qs);Co=i(Ci,"Preprocess the input text:"),Ci.forEach(s),Un=c(e),f(is.$$.fragment,e),Vn=c(e),Zs=r(e,"P",{});var Ni=o(Zs);No=i(Ni,"Create a spectrogram with your model:"),Ni.forEach(s),Wn=c(e),f(hs.$$.fragment,e),Gn=c(e),et=r(e,"P",{});var Fi=o(et);Fo=i(Fi,"Visualize the spectrogram, if you\u2019d like to:"),Fi.forEach(s),Bn=c(e),f(cs.$$.fragment,e),Mn=c(e),ms=r(e,"DIV",{class:!0});var Oi=o(ms);st=r(Oi,"IMG",{src:!0,alt:!0}),Oi.forEach(s),Rn=c(e),tt=r(e,"P",{});var Hi=o(tt);Oo=i(Hi,"Finally, use the vocoder to turn the spectrogram into sound."),Hi.forEach(s),Yn=c(e),f(us.$$.fragment,e),Xn=c(e),at=r(e,"P",{});var Li=o(at);Ho=i(Li,`In our experience, obtaining satisfactory results from this model can be challenging. The quality of the speaker
embeddings appears to be a significant factor. Since SpeechT5 was pre-trained with English x-vectors, it performs best
when using English speaker embeddings. If the synthesized speech sounds poor, try using a different speaker embedding.`),Li.forEach(s),Jn=c(e),he=r(e,"P",{});var _l=o(he);Lo=i(_l,`Increasing the training duration is also likely to enhance the quality of the results. Even so, the speech clearly is Dutch instead of English, and it does
capture the voice characteristics of the speaker (compare to the original audio in the example).
Another thing to experiment with is the model\u2019s configuration. For example, try using `),Jt=r(_l,"CODE",{});var Ui=o(Jt);Uo=i(Ui,"config.reduction_factor = 1"),Ui.forEach(s),Vo=i(_l,` to
see if this improves the results.`),_l.forEach(s),Kn=c(e),nt=r(e,"P",{});var Vi=o(nt);Wo=i(Vi,`Finally, it is essential to consider ethical considerations. Although TTS technology has numerous useful applications, it
may also be used for malicious purposes, such as impersonating someone\u2019s voice without their knowledge or consent. Please
use TTS judiciously and responsibly.`),Vi.forEach(s),this.h()},h(){m(j,"name","hf:doc:metadata"),m(j,"content",JSON.stringify(Zi)),m($,"id","text-to-speech"),m($,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m($,"href","#text-to-speech"),m(y,"class","relative group"),m(ds,"href","model_doc/speecht5"),m(_s,"href","model_doc/speecht5"),m(fe,"href","https://huggingface.co/datasets/facebook/voxpopuli"),m(fe,"rel","nofollow"),m(Y,"id","load-the-dataset"),m(Y,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(Y,"href","#load-the-dataset"),m(C,"class","relative group"),m(ve,"href","https://huggingface.co/datasets/facebook/voxpopuli"),m(ve,"rel","nofollow"),m(X,"id","preprocess-the-data"),m(X,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(X,"href","#preprocess-the-data"),m(N,"class","relative group"),m(J,"id","text-cleanup-for-speecht5-tokenization"),m(J,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(J,"href","#text-cleanup-for-speecht5-tokenization"),m(F,"class","relative group"),m(Q,"id","speakers"),m(Q,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(Q,"href","#speakers"),m(O,"class","relative group"),Bo(Ps.src,Mo="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/tts_speakers_histogram.png")||m(Ps,"src",Mo),m(Ps,"alt","Speakers histogram"),m(Ae,"class","flex justify-center"),m(Z,"id","speaker-embeddings"),m(Z,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(Z,"href","#speaker-embeddings"),m(H,"class","relative group"),m(Oe,"href","https://huggingface.co/speechbrain/spkrec-xvect-voxceleb"),m(Oe,"rel","nofollow"),m(ae,"id","processing-the-dataset"),m(ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ae,"href","#processing-the-dataset"),m(L,"class","relative group"),Bo(Ls.src,Ro="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/tts_logmelspectrogram_1.png")||m(Ls,"src",Ro),m(Ls,"alt","Log-mel spectrogram with 80 mel bins"),m(Be,"class","flex justify-center"),m(ne,"id","data-collator"),m(ne,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ne,"href","#data-collator"),m(U,"class","relative group"),m(re,"id","train-the-model"),m(re,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(re,"href","#train-the-model"),m(V,"class","relative group"),m(ie,"id","inference"),m(ie,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ie,"href","#inference"),m(W,"class","relative group"),Bo(st.src,Yo="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/tts_logmelspectrogram_2.png")||m(st,"src",Yo),m(st,"alt","Generated log-mel spectrogram"),m(ms,"class","flex justify-center")},m(e,t){a(document.head,j),n(e,G,t),n(e,y,t),a(y,$),a($,S),d(v,S,null),a(y,P),a(y,ot),a(ot,bl),n(e,Qt,t),d(ue,e,t),n(e,Zt,t),n(e,B,t),a(B,kl),a(B,ds),a(ds,vl),a(B,jl),n(e,ea,t),n(e,gs,t),a(gs,$l),n(e,sa,t),n(e,M,t),a(M,E),a(E,wl),a(E,_s),a(_s,yl),a(E,xl),a(E,pt),a(pt,ql),a(E,Tl),a(E,fe),a(fe,El),a(E,Sl),a(M,Pl),a(M,it),a(it,zl),n(e,ta,t),n(e,bs,t),a(bs,Dl),n(e,aa,t),d(de,e,t),n(e,na,t),n(e,ks,t),a(ks,Al),n(e,la,t),d(ge,e,t),n(e,ra,t),d(R,e,t),n(e,oa,t),n(e,vs,t),a(vs,Il),n(e,pa,t),d(_e,e,t),n(e,ia,t),n(e,C,t),a(C,Y),a(Y,ht),d(be,ht,null),a(C,Cl),a(C,ct),a(ct,Nl),n(e,ha,t),n(e,ke,t),a(ke,ve),a(ve,Fl),a(ke,Ol),n(e,ca,t),n(e,js,t),a(js,Hl),n(e,ma,t),n(e,$s,t),a($s,Ll),n(e,ua,t),d(je,e,t),n(e,fa,t),n(e,ws,t),a(ws,Ul),n(e,da,t),d($e,e,t),n(e,ga,t),n(e,N,t),a(N,X),a(X,mt),d(we,mt,null),a(N,Vl),a(N,ut),a(ut,Wl),n(e,_a,t),n(e,ys,t),a(ys,Gl),n(e,ba,t),d(ye,e,t),n(e,ka,t),n(e,F,t),a(F,J),a(J,ft),d(xe,ft,null),a(F,Bl),a(F,dt),a(dt,Ml),n(e,va,t),n(e,xs,t),a(xs,Rl),n(e,ja,t),d(qe,e,t),n(e,$a,t),n(e,x,t),a(x,Yl),a(x,gt),a(gt,Xl),a(x,Jl),a(x,_t),a(_t,Kl),a(x,Ql),a(x,bt),a(bt,Zl),a(x,er),a(x,kt),a(kt,sr),a(x,tr),n(e,wa,t),n(e,q,t),a(q,ar),a(q,vt),a(vt,nr),a(q,lr),a(q,jt),a(jt,rr),a(q,or),a(q,$t),a($t,pr),a(q,ir),n(e,ya,t),n(e,w,t),a(w,hr),a(w,wt),a(wt,cr),a(w,mr),a(w,yt),a(yt,ur),a(w,fr),a(w,xt),a(xt,dr),a(w,gr),a(w,qt),a(qt,_r),a(w,br),a(w,Tt),a(Tt,kr),a(w,vr),n(e,xa,t),d(Te,e,t),n(e,qa,t),n(e,qs,t),a(qs,jr),n(e,Ta,t),d(Ee,e,t),n(e,Ea,t),n(e,K,t),a(K,$r),a(K,Et),a(Et,wr),a(K,yr),n(e,Sa,t),d(Se,e,t),n(e,Pa,t),n(e,Ts,t),a(Ts,xr),n(e,za,t),n(e,O,t),a(O,Q),a(Q,St),d(Pe,St,null),a(O,qr),a(O,Pt),a(Pt,Tr),n(e,Da,t),n(e,Es,t),a(Es,Er),n(e,Aa,t),d(ze,e,t),n(e,Ia,t),n(e,Ss,t),a(Ss,Sr),n(e,Ca,t),d(De,e,t),n(e,Na,t),n(e,Ae,t),a(Ae,Ps),n(e,Fa,t),n(e,zs,t),a(zs,Pr),n(e,Oa,t),d(Ie,e,t),n(e,Ha,t),n(e,Ds,t),a(Ds,zr),n(e,La,t),d(Ce,e,t),n(e,Ua,t),n(e,As,t),a(As,Dr),n(e,Va,t),d(Ne,e,t),n(e,Wa,t),n(e,Is,t),a(Is,Ar),n(e,Ga,t),n(e,Cs,t),a(Cs,Ir),n(e,Ba,t),n(e,H,t),a(H,Z),a(Z,zt),d(Fe,zt,null),a(H,Cr),a(H,Dt),a(Dt,Nr),n(e,Ma,t),n(e,ee,t),a(ee,Fr),a(ee,Oe),a(Oe,Or),a(ee,Hr),n(e,Ra,t),n(e,se,t),a(se,Lr),a(se,At),a(At,Ur),a(se,Vr),n(e,Ya,t),d(He,e,t),n(e,Xa,t),n(e,te,t),a(te,Wr),a(te,It),a(It,Gr),a(te,Br),n(e,Ja,t),n(e,Ns,t),a(Ns,Mr),n(e,Ka,t),n(e,L,t),a(L,ae),a(ae,Ct),d(Le,Ct,null),a(L,Rr),a(L,Nt),a(Nt,Yr),n(e,Qa,t),n(e,z,t),a(z,Xr),a(z,Ft),a(Ft,Jr),a(z,Kr),a(z,Ot),a(Ot,Qr),a(z,Zr),n(e,Za,t),d(Ue,e,t),n(e,en,t),n(e,Fs,t),a(Fs,eo),n(e,sn,t),d(Ve,e,t),n(e,tn,t),n(e,Os,t),a(Os,so),n(e,an,t),d(We,e,t),n(e,nn,t),n(e,Hs,t),a(Hs,to),n(e,ln,t),d(Ge,e,t),n(e,rn,t),n(e,Be,t),a(Be,Ls),n(e,on,t),n(e,Us,t),a(Us,ao),n(e,pn,t),n(e,Vs,t),a(Vs,no),n(e,hn,t),d(Me,e,t),n(e,cn,t),n(e,Ws,t),a(Ws,lo),n(e,mn,t),d(Re,e,t),n(e,un,t),n(e,Gs,t),a(Gs,ro),n(e,fn,t),d(Ye,e,t),n(e,dn,t),n(e,U,t),a(U,ne),a(ne,Ht),d(Xe,Ht,null),a(U,oo),a(U,Lt),a(Lt,po),n(e,gn,t),n(e,le,t),a(le,io),a(le,Ut),a(Ut,ho),a(le,co),n(e,_n,t),d(Je,e,t),n(e,bn,t),n(e,Bs,t),a(Bs,mo),n(e,kn,t),d(Ke,e,t),n(e,vn,t),n(e,V,t),a(V,re),a(re,Vt),d(Qe,Vt,null),a(V,uo),a(V,Wt),a(Wt,fo),n(e,jn,t),n(e,Ms,t),a(Ms,go),n(e,$n,t),d(Ze,e,t),n(e,wn,t),n(e,oe,t),a(oe,_o),a(oe,Gt),a(Gt,bo),a(oe,ko),n(e,yn,t),d(es,e,t),n(e,xn,t),n(e,Rs,t),a(Rs,vo),n(e,qn,t),d(ss,e,t),n(e,Tn,t),n(e,pe,t),a(pe,jo),a(pe,Bt),a(Bt,$o),a(pe,wo),n(e,En,t),d(ts,e,t),n(e,Sn,t),n(e,D,t),a(D,yo),a(D,Mt),a(Mt,xo),a(D,qo),a(D,Rt),a(Rt,To),a(D,Eo),n(e,Pn,t),d(as,e,t),n(e,zn,t),n(e,Ys,t),a(Ys,So),n(e,Dn,t),d(ns,e,t),n(e,An,t),n(e,W,t),a(W,ie),a(ie,Yt),d(ls,Yt,null),a(W,Po),a(W,Xt),a(Xt,zo),n(e,In,t),n(e,Xs,t),a(Xs,Do),n(e,Cn,t),d(rs,e,t),n(e,Nn,t),n(e,Js,t),a(Js,Ao),n(e,Fn,t),d(os,e,t),n(e,On,t),n(e,Ks,t),a(Ks,Io),n(e,Hn,t),d(ps,e,t),n(e,Ln,t),n(e,Qs,t),a(Qs,Co),n(e,Un,t),d(is,e,t),n(e,Vn,t),n(e,Zs,t),a(Zs,No),n(e,Wn,t),d(hs,e,t),n(e,Gn,t),n(e,et,t),a(et,Fo),n(e,Bn,t),d(cs,e,t),n(e,Mn,t),n(e,ms,t),a(ms,st),n(e,Rn,t),n(e,tt,t),a(tt,Oo),n(e,Yn,t),d(us,e,t),n(e,Xn,t),n(e,at,t),a(at,Ho),n(e,Jn,t),n(e,he,t),a(he,Lo),a(he,Jt),a(Jt,Uo),a(he,Vo),n(e,Kn,t),n(e,nt,t),a(nt,Wo),Qn=!0},p(e,[t]){const fs={};t&2&&(fs.$$scope={dirty:t,ctx:e}),R.$set(fs)},i(e){Qn||(g(v.$$.fragment,e),g(ue.$$.fragment,e),g(de.$$.fragment,e),g(ge.$$.fragment,e),g(R.$$.fragment,e),g(_e.$$.fragment,e),g(be.$$.fragment,e),g(je.$$.fragment,e),g($e.$$.fragment,e),g(we.$$.fragment,e),g(ye.$$.fragment,e),g(xe.$$.fragment,e),g(qe.$$.fragment,e),g(Te.$$.fragment,e),g(Ee.$$.fragment,e),g(Se.$$.fragment,e),g(Pe.$$.fragment,e),g(ze.$$.fragment,e),g(De.$$.fragment,e),g(Ie.$$.fragment,e),g(Ce.$$.fragment,e),g(Ne.$$.fragment,e),g(Fe.$$.fragment,e),g(He.$$.fragment,e),g(Le.$$.fragment,e),g(Ue.$$.fragment,e),g(Ve.$$.fragment,e),g(We.$$.fragment,e),g(Ge.$$.fragment,e),g(Me.$$.fragment,e),g(Re.$$.fragment,e),g(Ye.$$.fragment,e),g(Xe.$$.fragment,e),g(Je.$$.fragment,e),g(Ke.$$.fragment,e),g(Qe.$$.fragment,e),g(Ze.$$.fragment,e),g(es.$$.fragment,e),g(ss.$$.fragment,e),g(ts.$$.fragment,e),g(as.$$.fragment,e),g(ns.$$.fragment,e),g(ls.$$.fragment,e),g(rs.$$.fragment,e),g(os.$$.fragment,e),g(ps.$$.fragment,e),g(is.$$.fragment,e),g(hs.$$.fragment,e),g(cs.$$.fragment,e),g(us.$$.fragment,e),Qn=!0)},o(e){_(v.$$.fragment,e),_(ue.$$.fragment,e),_(de.$$.fragment,e),_(ge.$$.fragment,e),_(R.$$.fragment,e),_(_e.$$.fragment,e),_(be.$$.fragment,e),_(je.$$.fragment,e),_($e.$$.fragment,e),_(we.$$.fragment,e),_(ye.$$.fragment,e),_(xe.$$.fragment,e),_(qe.$$.fragment,e),_(Te.$$.fragment,e),_(Ee.$$.fragment,e),_(Se.$$.fragment,e),_(Pe.$$.fragment,e),_(ze.$$.fragment,e),_(De.$$.fragment,e),_(Ie.$$.fragment,e),_(Ce.$$.fragment,e),_(Ne.$$.fragment,e),_(Fe.$$.fragment,e),_(He.$$.fragment,e),_(Le.$$.fragment,e),_(Ue.$$.fragment,e),_(Ve.$$.fragment,e),_(We.$$.fragment,e),_(Ge.$$.fragment,e),_(Me.$$.fragment,e),_(Re.$$.fragment,e),_(Ye.$$.fragment,e),_(Xe.$$.fragment,e),_(Je.$$.fragment,e),_(Ke.$$.fragment,e),_(Qe.$$.fragment,e),_(Ze.$$.fragment,e),_(es.$$.fragment,e),_(ss.$$.fragment,e),_(ts.$$.fragment,e),_(as.$$.fragment,e),_(ns.$$.fragment,e),_(ls.$$.fragment,e),_(rs.$$.fragment,e),_(os.$$.fragment,e),_(ps.$$.fragment,e),_(is.$$.fragment,e),_(hs.$$.fragment,e),_(cs.$$.fragment,e),_(us.$$.fragment,e),Qn=!1},d(e){s(j),e&&s(G),e&&s(y),b(v),e&&s(Qt),b(ue,e),e&&s(Zt),e&&s(B),e&&s(ea),e&&s(gs),e&&s(sa),e&&s(M),e&&s(ta),e&&s(bs),e&&s(aa),b(de,e),e&&s(na),e&&s(ks),e&&s(la),b(ge,e),e&&s(ra),b(R,e),e&&s(oa),e&&s(vs),e&&s(pa),b(_e,e),e&&s(ia),e&&s(C),b(be),e&&s(ha),e&&s(ke),e&&s(ca),e&&s(js),e&&s(ma),e&&s($s),e&&s(ua),b(je,e),e&&s(fa),e&&s(ws),e&&s(da),b($e,e),e&&s(ga),e&&s(N),b(we),e&&s(_a),e&&s(ys),e&&s(ba),b(ye,e),e&&s(ka),e&&s(F),b(xe),e&&s(va),e&&s(xs),e&&s(ja),b(qe,e),e&&s($a),e&&s(x),e&&s(wa),e&&s(q),e&&s(ya),e&&s(w),e&&s(xa),b(Te,e),e&&s(qa),e&&s(qs),e&&s(Ta),b(Ee,e),e&&s(Ea),e&&s(K),e&&s(Sa),b(Se,e),e&&s(Pa),e&&s(Ts),e&&s(za),e&&s(O),b(Pe),e&&s(Da),e&&s(Es),e&&s(Aa),b(ze,e),e&&s(Ia),e&&s(Ss),e&&s(Ca),b(De,e),e&&s(Na),e&&s(Ae),e&&s(Fa),e&&s(zs),e&&s(Oa),b(Ie,e),e&&s(Ha),e&&s(Ds),e&&s(La),b(Ce,e),e&&s(Ua),e&&s(As),e&&s(Va),b(Ne,e),e&&s(Wa),e&&s(Is),e&&s(Ga),e&&s(Cs),e&&s(Ba),e&&s(H),b(Fe),e&&s(Ma),e&&s(ee),e&&s(Ra),e&&s(se),e&&s(Ya),b(He,e),e&&s(Xa),e&&s(te),e&&s(Ja),e&&s(Ns),e&&s(Ka),e&&s(L),b(Le),e&&s(Qa),e&&s(z),e&&s(Za),b(Ue,e),e&&s(en),e&&s(Fs),e&&s(sn),b(Ve,e),e&&s(tn),e&&s(Os),e&&s(an),b(We,e),e&&s(nn),e&&s(Hs),e&&s(ln),b(Ge,e),e&&s(rn),e&&s(Be),e&&s(on),e&&s(Us),e&&s(pn),e&&s(Vs),e&&s(hn),b(Me,e),e&&s(cn),e&&s(Ws),e&&s(mn),b(Re,e),e&&s(un),e&&s(Gs),e&&s(fn),b(Ye,e),e&&s(dn),e&&s(U),b(Xe),e&&s(gn),e&&s(le),e&&s(_n),b(Je,e),e&&s(bn),e&&s(Bs),e&&s(kn),b(Ke,e),e&&s(vn),e&&s(V),b(Qe),e&&s(jn),e&&s(Ms),e&&s($n),b(Ze,e),e&&s(wn),e&&s(oe),e&&s(yn),b(es,e),e&&s(xn),e&&s(Rs),e&&s(qn),b(ss,e),e&&s(Tn),e&&s(pe),e&&s(En),b(ts,e),e&&s(Sn),e&&s(D),e&&s(Pn),b(as,e),e&&s(zn),e&&s(Ys),e&&s(Dn),b(ns,e),e&&s(An),e&&s(W),b(ls),e&&s(In),e&&s(Xs),e&&s(Cn),b(rs,e),e&&s(Nn),e&&s(Js),e&&s(Fn),b(os,e),e&&s(On),e&&s(Ks),e&&s(Hn),b(ps,e),e&&s(Ln),e&&s(Qs),e&&s(Un),b(is,e),e&&s(Vn),e&&s(Zs),e&&s(Wn),b(hs,e),e&&s(Gn),e&&s(et),e&&s(Bn),b(cs,e),e&&s(Mn),e&&s(ms),e&&s(Rn),e&&s(tt),e&&s(Yn),b(us,e),e&&s(Xn),e&&s(at),e&&s(Jn),e&&s(he),e&&s(Kn),e&&s(nt)}}}const Zi={local:"text-to-speech",sections:[{local:"load-the-dataset",title:"Load the dataset"},{local:"preprocess-the-data",sections:[{local:"text-cleanup-for-speecht5-tokenization",title:"Text cleanup for SpeechT5 tokenization "},{local:"speakers",title:"Speakers"},{local:"speaker-embeddings",title:"Speaker embeddings"},{local:"processing-the-dataset",title:"Processing the dataset"},{local:"data-collator",title:"Data collator"}],title:"Preprocess the data"},{local:"train-the-model",title:"Train the model"},{local:"inference",title:"Inference"}],title:"Text to speech"};function eh(Kt){return Ri(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rh extends Wi{constructor(j){super();Gi(this,j,eh,Qi,Bi,{})}}export{rh as default,Zi as metadata};
