import{S as ro,i as oo,s as ao,e as o,k as l,w as q,t as n,M as no,c as a,d as r,m,a as s,x as C,h as i,b as h,G as e,g as c,y as M,q as F,o as D,B as H,v as so,L as io}from"../../chunks/vendor-hf-doc-builder.js";import{D as ce}from"../../chunks/Docstring-hf-doc-builder.js";import{C as lo}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as to}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as mo}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function fo(je){let u,L,_,p,T;return p=new lo({props:{code:`from transformers.audio_utils import stft, fram_wave
import numpy as np

audio = np.random.rand(50)
fft_window_size = 10
hop_length = 2
framed_audio = fram_wave(audio, hop_length, fft_window_size)
spectrogram = stft(framed_audio, np.hanning(fft_window_size + 1))`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.audio_utils <span class="hljs-keyword">import</span> stft, fram_wave
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-meta">&gt;&gt;&gt; </span>audio = np.random.rand(<span class="hljs-number">50</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>fft_window_size = <span class="hljs-number">10</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>hop_length = <span class="hljs-number">2</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>framed_audio = fram_wave(audio, hop_length, fft_window_size)
<span class="hljs-meta">&gt;&gt;&gt; </span>spectrogram = stft(framed_audio, np.hanning(fft_window_size + <span class="hljs-number">1</span>))`}}),{c(){u=o("p"),L=n("Example:"),_=l(),q(p.$$.fragment)},l(f){u=a(f,"P",{});var k=s(u);L=i(k,"Example:"),k.forEach(r),_=m(f),C(p.$$.fragment,f)},m(f,k){c(f,u,k),e(u,L),c(f,_,k),M(p,f,k),T=!0},p:io,i(f){T||(F(p.$$.fragment,f),T=!0)},o(f){D(p.$$.fragment,f),T=!1},d(f){f&&r(u),f&&r(_),H(p,f)}}}function co(je){let u,L,_,p,T,f,k,ie,st,he,it,Be,b,lt,ue,mt,dt,pe,ft,ct,_e,ht,ut,Oe,le,pt,Ne,S,P,ge,K,_t,we,gt,Ue,A,G,wt,ve,vt,Ve,I,W,bt,be,yt,Ke,g,J,$t,y,Et,ye,xt,Tt,$e,kt,zt,R,qt,Ct,Mt,Ee,Ft,Dt,Q,me,Ht,$,X,St,xe,At,It,Lt,Y,Pt,Te,jt,Bt,Ot,ke,Nt,Ut,ze,Vt,Kt,w,Gt,qe,Wt,Jt,Ce,Rt,Qt,Me,Xt,Yt,Fe,Zt,er,Ge,E,Z,tr,ee,rr,De,or,ar,nr,j,We,v,te,sr,re,ir,He,lr,mr,dr,Se,fr,cr,oe,Ae,hr,ur,Ie,pr,Je,x,ae,_r,ne,gr,Le,wr,vr,br,Pe,yr,Re;return f=new to({}),K=new to({}),G=new ce({props:{name:"transformers.audio_utils.hertz_to_mel",anchor:"transformers.audio_utils.hertz_to_mel",parameters:[{name:"freq",val:": float"},{name:"mel_scale",val:": str = 'htk'"}],parametersDescription:[{anchor:"transformers.audio_utils.hertz_to_mel.freqs",description:`<strong>freqs</strong> (<code>float</code>) &#x2014;
Frequencies in Hertz`,name:"freqs"},{anchor:"transformers.audio_utils.hertz_to_mel.mel_scale",description:`<strong>mel_scale</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;htk&quot;</code>) &#x2014;
Scale to use, <code>htk</code> or <code>slaney</code>.`,name:"mel_scale"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/audio_utils.py#L27",returnDescription:`
<p>Frequency in Mels</p>
`,returnType:`
<p>mels (<code>float</code>)</p>
`}}),W=new ce({props:{name:"transformers.audio_utils.mel_to_hertz",anchor:"transformers.audio_utils.mel_to_hertz",parameters:[{name:"mels",val:": array"},{name:"mel_scale",val:": str = 'htk'"}],parametersDescription:[{anchor:"transformers.audio_utils.mel_to_hertz.mels",description:`<strong>mels</strong> (<code>np.array</code>) &#x2014;
Mel frequencies`,name:"mels"},{anchor:"transformers.audio_utils.mel_to_hertz.mel_scale",description:`<strong>mel_scale</strong> (<code>str</code>, <em>optional</em>, <code>&quot;htk&quot;</code>) &#x2014;
Scale to use: <code>htk</code> or <code>slaney</code>.`,name:"mel_scale"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/audio_utils.py#L64",returnDescription:`
<p>Mels converted to Hertz</p>
`,returnType:`
<p>freqs (<code>np.array</code>)</p>
`}}),J=new ce({props:{name:"transformers.audio_utils.get_mel_filter_banks",anchor:"transformers.audio_utils.get_mel_filter_banks",parameters:[{name:"nb_frequency_bins",val:": int"},{name:"nb_mel_filters",val:": int"},{name:"frequency_min",val:": float"},{name:"frequency_max",val:": float"},{name:"sample_rate",val:": int"},{name:"norm",val:": typing.Optional[str] = None"},{name:"mel_scale",val:": str = 'htk'"}],parametersDescription:[{anchor:"transformers.audio_utils.get_mel_filter_banks.nb_frequency_bins",description:`<strong>nb_frequency_bins</strong> (<code>int</code>) &#x2014;
Number of frequencies used to compute the spectrogram (should be the same as in <code>stft</code>).`,name:"nb_frequency_bins"},{anchor:"transformers.audio_utils.get_mel_filter_banks.nb_mel_filters",description:`<strong>nb_mel_filters</strong> (<code>int</code>) &#x2014;
Number of Mel filers to generate.`,name:"nb_mel_filters"},{anchor:"transformers.audio_utils.get_mel_filter_banks.frequency_min",description:`<strong>frequency_min</strong> (<code>float</code>) &#x2014;
Minimum frequency of interest(Hertz).`,name:"frequency_min"},{anchor:"transformers.audio_utils.get_mel_filter_banks.frequency_max",description:`<strong>frequency_max</strong> (<code>float</code>) &#x2014;
Maximum frequency of interest(Hertz).`,name:"frequency_max"},{anchor:"transformers.audio_utils.get_mel_filter_banks.sample_rate",description:`<strong>sample_rate</strong> (<code>int</code>) &#x2014;
Sample rate of the audio waveform.`,name:"sample_rate"},{anchor:"transformers.audio_utils.get_mel_filter_banks.norm",description:`<strong>norm</strong> (<code>str</code>, <em>optional</em>) &#x2014;
If &#x201C;slaney&#x201D;, divide the triangular Mel weights by the width of the mel band (area normalization).`,name:"norm"},{anchor:"transformers.audio_utils.get_mel_filter_banks.mel_scale",description:`<strong>mel_scale</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;htk&quot;</code>) &#x2014;
Scale to use: <code>&quot;htk&quot;</code> or <code>&quot;slaney&quot;</code>.`,name:"mel_scale"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/audio_utils.py#L130",returnDescription:`
<p>Triangular filter banks (fb matrix) of shape (<code>nb_frequency_bins</code>, <code>nb_mel_filters</code>). This matrix
is a projection matrix to go from a spectrogram to a Mel Spectrogram.</p>
`,returnType:`
<p><code>np.ndarray</code></p>
`}}),Z=new ce({props:{name:"transformers.audio_utils.stft",anchor:"transformers.audio_utils.stft",parameters:[{name:"frames",val:": array"},{name:"windowing_function",val:": array"},{name:"fft_window_size",val:": int = None"}],parametersDescription:[{anchor:"transformers.audio_utils.stft.frames",description:`<strong>frames</strong> (<code>np.array</code> of dimension <code>(num_frames, fft_window_size)</code>) &#x2014;
A framed audio signal obtained using <code>audio_utils.fram_wav</code>.`,name:"frames"},{anchor:"transformers.audio_utils.stft.windowing_function",description:`<strong>windowing_function</strong> (<code>np.array</code> of dimension <code>(nb_frequency_bins, nb_mel_filters)</code> &#x2014;
A array reprensenting the function that will be used to reduces the amplitude of the discontinuities at the
boundaries of each frame when computing the STFT. Each frame will be multiplied by the windowing_function.
For more information on the discontinuities, called <em>Spectral leakage</em>, refer to [this
tutorial]<a href="https://download.ni.com/evaluation/pxi/Understanding%20FFTs%20and%20Windowing.pdf" rel="nofollow">https://download.ni.com/evaluation/pxi/Understanding%20FFTs%20and%20Windowing.pdf</a>`,name:"windowing_function"},{anchor:"transformers.audio_utils.stft.fft_window_size",description:`<strong>fft_window_size</strong> (<code>int</code>, <em>optional</em>) &#x2014;
Size of the window om which the Fourier transform is applied. This controls the frequency resolution of the
spectrogram. 400 means that the fourrier transform is computed on windows of 400 samples. The number of
frequency bins (<code>nb_frequency_bins</code>) used to divide the window into equal strips is equal to
<code>(1+fft_window_size)//2</code>. An increase of the fft_window_size slows the calculus time proportionnally.`,name:"fft_window_size"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/audio_utils.py#L304",returnDescription:`
<p>A spectrogram of shape <code>(num_frames, nb_frequency_bins)</code> obtained using the STFT algorithm</p>
`,returnType:`
<p>spectrogram (<code>np.ndarray</code>)</p>
`}}),j=new mo({props:{anchor:"transformers.audio_utils.stft.example",$$slots:{default:[fo]},$$scope:{ctx:je}}}),te=new ce({props:{name:"transformers.audio_utils.power_to_db",anchor:"transformers.audio_utils.power_to_db",parameters:[{name:"mel_spectrogram",val:""},{name:"top_db",val:" = None"},{name:"a_min",val:" = 1e-10"},{name:"ref",val:" = 1.0"}],parametersDescription:[{anchor:"transformers.audio_utils.power_to_db.mel_spectrogram",description:`<strong>mel_spectrogram</strong> (<code>np.array</code>) &#x2014;
Input mel spectrogram.`,name:"mel_spectrogram"},{anchor:"transformers.audio_utils.power_to_db.top_db",description:`<strong>top_db</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The maximum decibel value.`,name:"top_db"},{anchor:"transformers.audio_utils.power_to_db.a_min",description:`<strong>a_min</strong> (<code>int</code>, <em>optional</em>, default to 1e-10) &#x2014;
Minimum value to use when cliping the mel spectrogram.`,name:"a_min"},{anchor:"transformers.audio_utils.power_to_db.ref",description:`<strong>ref</strong> (<code>float</code>, <em>optional</em>, default to 1.0) &#x2014;
Maximum reference value used to scale the mel_spectrogram.`,name:"ref"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/audio_utils.py#L215"}}),ae=new ce({props:{name:"transformers.audio_utils.fram_wave",anchor:"transformers.audio_utils.fram_wave",parameters:[{name:"waveform",val:": array"},{name:"hop_length",val:": int = 160"},{name:"fft_window_size",val:": int = 400"},{name:"center",val:": bool = True"}],parametersDescription:[{anchor:"transformers.audio_utils.fram_wave.waveform",description:`<strong>waveform</strong> (<code>np.array</code> of shape <code>(sample_length,)</code>) &#x2014;
The raw waveform which will be split into smaller chunks.`,name:"waveform"},{anchor:"transformers.audio_utils.fram_wave.hop_length",description:`<strong>hop_length</strong> (<code>int</code>, <em>optional</em>, defaults to 160) &#x2014;
Step between each window of the waveform.`,name:"hop_length"},{anchor:"transformers.audio_utils.fram_wave.fft_window_size",description:`<strong>fft_window_size</strong> (<code>int</code>, <em>optional</em>, defaults to 400) &#x2014;
Defines the size of the window.`,name:"fft_window_size"},{anchor:"transformers.audio_utils.fram_wave.center",description:`<strong>center</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether or not to center each frame around the middle of the frame. Centering is done by reflecting the
waveform on the left and on the right.`,name:"center"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/audio_utils.py#L249",returnDescription:`
<p>The framed waveforms that can be fed to <code>np.fft</code>.</p>
`,returnType:`
<p>framed_waveform (<code>np.array</code> of shape <code>(waveform.shape // hop_length , fft_window_size)</code>)</p>
`}}),{c(){u=o("meta"),L=l(),_=o("h1"),p=o("a"),T=o("span"),q(f.$$.fragment),k=l(),ie=o("span"),st=n("Utilities for "),he=o("code"),it=n("FeatureExtractors"),Be=l(),b=o("p"),lt=n("This page lists all the utility functions that can be used by the audio "),ue=o("code"),mt=n("FeatureExtractor"),dt=n(" in order to compute special features from a raw audio using common algorithms such as "),pe=o("em"),ft=n("Short Time Fourier Transform"),ct=n(" or "),_e=o("em"),ht=n("Mel log spectrogram"),ut=n("."),Oe=l(),le=o("p"),pt=n("Most of those are only useful if you are studying the code of the image processors in the library."),Ne=l(),S=o("h2"),P=o("a"),ge=o("span"),q(K.$$.fragment),_t=l(),we=o("span"),gt=n("Audio Transformations"),Ue=l(),A=o("div"),q(G.$$.fragment),wt=l(),ve=o("p"),vt=n("Convert Hertz to Mels."),Ve=l(),I=o("div"),q(W.$$.fragment),bt=l(),be=o("p"),yt=n("Convert mel bin numbers to frequencies."),Ke=l(),g=o("div"),q(J.$$.fragment),$t=l(),y=o("p"),Et=n("Create a frequency bin conversion matrix used to obtain the Mel Spectrogram. This is called a "),ye=o("em"),xt=n("mel filter bank"),Tt=n(`,
and various implementation exist, which differ in the number of filters, the shape of the filters, the way the
filters are spaced, the bandwidth of the filters, and the manner in which the spectrum is warped. The goal of these
features is to approximate the non-linear human perception of the variation in pitch with respect to the frequency.
This code is heavily inspired from the `),$e=o("em"),kt=n("torchaudio"),zt=n(` implementation, see
`),R=o("a"),qt=n("here"),Ct=n(" for more details."),Mt=l(),Ee=o("p"),Ft=n("Tips:"),Dt=l(),Q=o("ul"),me=o("li"),Ht=n("Different banks of Mel filters were introduced in the litterature. The following variation are supported:"),$=o("ul"),X=o("li"),St=n(`MFCC FB-20: introduced in 1980 by Davis and Mermelstein, it assumes a sampling frequency of 10 kHertz
and a speech bandwidth of `),xe=o("code"),At=n("[0, 4600]"),It=n(" Hertz"),Lt=l(),Y=o("li"),Pt=n(`MFCC FB-24 HTK: from the Cambridge HMM Toolkit (HTK) (1995) uses a filter bank of 24 filters for a
speech bandwidth `),Te=o("code"),jt=n("[0, 8000]"),Bt=n(" Hertz (sampling rate \u2265 16 kHertz)."),Ot=l(),ke=o("li"),Nt=n(`MFCC FB-40: from the Auditory Toolbox for MATLAB written by Slaney in 1998, assumes a sampling rate
of 16 kHertz, and speech bandwidth [133, 6854] Hertz. This version also includes an area normalization.`),Ut=l(),ze=o("li"),Vt=n(`HFCC-E FB-29 (Human Factor Cepstral Coefficients) of Skowronski and Harris (2004), assumes sampling
rate of 12.5 kHertz and speech bandwidth [0, 6250] Hertz`),Kt=l(),w=o("li"),Gt=n("The default parameters of "),qe=o("code"),Wt=n("torchaudio"),Jt=n("\u2019s mel filterbanks implement the "),Ce=o("code"),Rt=n('"htk"'),Qt=n(" filers while "),Me=o("code"),Xt=n("torchlibrosa"),Yt=n(`
uses the `),Fe=o("code"),Zt=n('"slaney"'),er=n(" implementation."),Ge=l(),E=o("div"),q(Z.$$.fragment),tr=l(),ee=o("p"),rr=n(`Calculates the complex Short-Time Fourier Transform (STFT) of the given framed signal. Should give the same results
as `),De=o("code"),or=n("torch.stft"),ar=n("."),nr=l(),q(j.$$.fragment),We=l(),v=o("div"),q(te.$$.fragment),sr=l(),re=o("p"),ir=n(`Convert a mel spectrogram from power to db scale, this function is the numpy implementation of librosa.power_to_lb.
It computes `),He=o("code"),lr=n("10 * log10(mel_spectrogram / ref)"),mr=n(", using basic log properties for stability."),dr=l(),Se=o("p"),fr=n("Tips:"),cr=l(),oe=o("ul"),Ae=o("li"),hr=n(`The motivation behind applying the log function on the mel spectrogram is that humans do not hear loudness on
a
linear scale. Generally to double the percieved volume of a sound we need to put 8 times as much energy into
it.`),ur=l(),Ie=o("li"),pr=n(`This means that large variations in energy may not sound all that different if the sound is loud to begin
with. This compression operation makes the mel features match more closely what humans actually hear.`),Je=l(),x=o("div"),q(ae.$$.fragment),_r=l(),ne=o("p"),gr=n(`In order to compute the short time fourier transform, the waveform needs to be split in overlapping windowed
segments called `),Le=o("code"),wr=n("frames"),vr=n("."),br=l(),Pe=o("p"),yr=n(`The window length (window_length) defines how much of the signal is contained in each frame, while the hop length
defines the step between the beginning of each new frame.`),this.h()},l(t){const d=no('[data-svelte="svelte-1phssyn"]',document.head);u=a(d,"META",{name:!0,content:!0}),d.forEach(r),L=m(t),_=a(t,"H1",{class:!0});var se=s(_);p=a(se,"A",{id:!0,class:!0,href:!0});var xr=s(p);T=a(xr,"SPAN",{});var Tr=s(T);C(f.$$.fragment,Tr),Tr.forEach(r),xr.forEach(r),k=m(se),ie=a(se,"SPAN",{});var $r=s(ie);st=i($r,"Utilities for "),he=a($r,"CODE",{});var kr=s(he);it=i(kr,"FeatureExtractors"),kr.forEach(r),$r.forEach(r),se.forEach(r),Be=m(t),b=a(t,"P",{});var B=s(b);lt=i(B,"This page lists all the utility functions that can be used by the audio "),ue=a(B,"CODE",{});var zr=s(ue);mt=i(zr,"FeatureExtractor"),zr.forEach(r),dt=i(B," in order to compute special features from a raw audio using common algorithms such as "),pe=a(B,"EM",{});var qr=s(pe);ft=i(qr,"Short Time Fourier Transform"),qr.forEach(r),ct=i(B," or "),_e=a(B,"EM",{});var Cr=s(_e);ht=i(Cr,"Mel log spectrogram"),Cr.forEach(r),ut=i(B,"."),B.forEach(r),Oe=m(t),le=a(t,"P",{});var Mr=s(le);pt=i(Mr,"Most of those are only useful if you are studying the code of the image processors in the library."),Mr.forEach(r),Ne=m(t),S=a(t,"H2",{class:!0});var Qe=s(S);P=a(Qe,"A",{id:!0,class:!0,href:!0});var Fr=s(P);ge=a(Fr,"SPAN",{});var Dr=s(ge);C(K.$$.fragment,Dr),Dr.forEach(r),Fr.forEach(r),_t=m(Qe),we=a(Qe,"SPAN",{});var Hr=s(we);gt=i(Hr,"Audio Transformations"),Hr.forEach(r),Qe.forEach(r),Ue=m(t),A=a(t,"DIV",{class:!0});var Xe=s(A);C(G.$$.fragment,Xe),wt=m(Xe),ve=a(Xe,"P",{});var Sr=s(ve);vt=i(Sr,"Convert Hertz to Mels."),Sr.forEach(r),Xe.forEach(r),Ve=m(t),I=a(t,"DIV",{class:!0});var Ye=s(I);C(W.$$.fragment,Ye),bt=m(Ye),be=a(Ye,"P",{});var Ar=s(be);yt=i(Ar,"Convert mel bin numbers to frequencies."),Ar.forEach(r),Ye.forEach(r),Ke=m(t),g=a(t,"DIV",{class:!0});var O=s(g);C(J.$$.fragment,O),$t=m(O),y=a(O,"P",{});var N=s(y);Et=i(N,"Create a frequency bin conversion matrix used to obtain the Mel Spectrogram. This is called a "),ye=a(N,"EM",{});var Ir=s(ye);xt=i(Ir,"mel filter bank"),Ir.forEach(r),Tt=i(N,`,
and various implementation exist, which differ in the number of filters, the shape of the filters, the way the
filters are spaced, the bandwidth of the filters, and the manner in which the spectrum is warped. The goal of these
features is to approximate the non-linear human perception of the variation in pitch with respect to the frequency.
This code is heavily inspired from the `),$e=a(N,"EM",{});var Lr=s($e);kt=i(Lr,"torchaudio"),Lr.forEach(r),zt=i(N,` implementation, see
`),R=a(N,"A",{href:!0,rel:!0});var Pr=s(R);qt=i(Pr,"here"),Pr.forEach(r),Ct=i(N," for more details."),N.forEach(r),Mt=m(O),Ee=a(O,"P",{});var jr=s(Ee);Ft=i(jr,"Tips:"),jr.forEach(r),Dt=m(O),Q=a(O,"UL",{});var Ze=s(Q);me=a(Ze,"LI",{});var Er=s(me);Ht=i(Er,"Different banks of Mel filters were introduced in the litterature. The following variation are supported:"),$=a(Er,"UL",{});var U=s($);X=a(U,"LI",{});var et=s(X);St=i(et,`MFCC FB-20: introduced in 1980 by Davis and Mermelstein, it assumes a sampling frequency of 10 kHertz
and a speech bandwidth of `),xe=a(et,"CODE",{});var Br=s(xe);At=i(Br,"[0, 4600]"),Br.forEach(r),It=i(et," Hertz"),et.forEach(r),Lt=m(U),Y=a(U,"LI",{});var tt=s(Y);Pt=i(tt,`MFCC FB-24 HTK: from the Cambridge HMM Toolkit (HTK) (1995) uses a filter bank of 24 filters for a
speech bandwidth `),Te=a(tt,"CODE",{});var Or=s(Te);jt=i(Or,"[0, 8000]"),Or.forEach(r),Bt=i(tt," Hertz (sampling rate \u2265 16 kHertz)."),tt.forEach(r),Ot=m(U),ke=a(U,"LI",{});var Nr=s(ke);Nt=i(Nr,`MFCC FB-40: from the Auditory Toolbox for MATLAB written by Slaney in 1998, assumes a sampling rate
of 16 kHertz, and speech bandwidth [133, 6854] Hertz. This version also includes an area normalization.`),Nr.forEach(r),Ut=m(U),ze=a(U,"LI",{});var Ur=s(ze);Vt=i(Ur,`HFCC-E FB-29 (Human Factor Cepstral Coefficients) of Skowronski and Harris (2004), assumes sampling
rate of 12.5 kHertz and speech bandwidth [0, 6250] Hertz`),Ur.forEach(r),U.forEach(r),Er.forEach(r),Kt=m(Ze),w=a(Ze,"LI",{});var z=s(w);Gt=i(z,"The default parameters of "),qe=a(z,"CODE",{});var Vr=s(qe);Wt=i(Vr,"torchaudio"),Vr.forEach(r),Jt=i(z,"\u2019s mel filterbanks implement the "),Ce=a(z,"CODE",{});var Kr=s(Ce);Rt=i(Kr,'"htk"'),Kr.forEach(r),Qt=i(z," filers while "),Me=a(z,"CODE",{});var Gr=s(Me);Xt=i(Gr,"torchlibrosa"),Gr.forEach(r),Yt=i(z,`
uses the `),Fe=a(z,"CODE",{});var Wr=s(Fe);Zt=i(Wr,'"slaney"'),Wr.forEach(r),er=i(z," implementation."),z.forEach(r),Ze.forEach(r),O.forEach(r),Ge=m(t),E=a(t,"DIV",{class:!0});var de=s(E);C(Z.$$.fragment,de),tr=m(de),ee=a(de,"P",{});var rt=s(ee);rr=i(rt,`Calculates the complex Short-Time Fourier Transform (STFT) of the given framed signal. Should give the same results
as `),De=a(rt,"CODE",{});var Jr=s(De);or=i(Jr,"torch.stft"),Jr.forEach(r),ar=i(rt,"."),rt.forEach(r),nr=m(de),C(j.$$.fragment,de),de.forEach(r),We=m(t),v=a(t,"DIV",{class:!0});var V=s(v);C(te.$$.fragment,V),sr=m(V),re=a(V,"P",{});var ot=s(re);ir=i(ot,`Convert a mel spectrogram from power to db scale, this function is the numpy implementation of librosa.power_to_lb.
It computes `),He=a(ot,"CODE",{});var Rr=s(He);lr=i(Rr,"10 * log10(mel_spectrogram / ref)"),Rr.forEach(r),mr=i(ot,", using basic log properties for stability."),ot.forEach(r),dr=m(V),Se=a(V,"P",{});var Qr=s(Se);fr=i(Qr,"Tips:"),Qr.forEach(r),cr=m(V),oe=a(V,"UL",{});var at=s(oe);Ae=a(at,"LI",{});var Xr=s(Ae);hr=i(Xr,`The motivation behind applying the log function on the mel spectrogram is that humans do not hear loudness on
a
linear scale. Generally to double the percieved volume of a sound we need to put 8 times as much energy into
it.`),Xr.forEach(r),ur=m(at),Ie=a(at,"LI",{});var Yr=s(Ie);pr=i(Yr,`This means that large variations in energy may not sound all that different if the sound is loud to begin
with. This compression operation makes the mel features match more closely what humans actually hear.`),Yr.forEach(r),at.forEach(r),V.forEach(r),Je=m(t),x=a(t,"DIV",{class:!0});var fe=s(x);C(ae.$$.fragment,fe),_r=m(fe),ne=a(fe,"P",{});var nt=s(ne);gr=i(nt,`In order to compute the short time fourier transform, the waveform needs to be split in overlapping windowed
segments called `),Le=a(nt,"CODE",{});var Zr=s(Le);wr=i(Zr,"frames"),Zr.forEach(r),vr=i(nt,"."),nt.forEach(r),br=m(fe),Pe=a(fe,"P",{});var eo=s(Pe);yr=i(eo,`The window length (window_length) defines how much of the signal is contained in each frame, while the hop length
defines the step between the beginning of each new frame.`),eo.forEach(r),fe.forEach(r),this.h()},h(){h(u,"name","hf:doc:metadata"),h(u,"content",JSON.stringify(ho)),h(p,"id","utilities-for-featureextractors"),h(p,"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"),h(p,"href","#utilities-for-featureextractors"),h(_,"class","relative group"),h(P,"id","transformers.audio_utils.hertz_to_mel"),h(P,"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"),h(P,"href","#transformers.audio_utils.hertz_to_mel"),h(S,"class","relative group"),h(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),h(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),h(R,"href","https://pytorch.org/audio/stable/transforms.html"),h(R,"rel","nofollow"),h(g,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),h(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),h(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),h(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,d){e(document.head,u),c(t,L,d),c(t,_,d),e(_,p),e(p,T),M(f,T,null),e(_,k),e(_,ie),e(ie,st),e(ie,he),e(he,it),c(t,Be,d),c(t,b,d),e(b,lt),e(b,ue),e(ue,mt),e(b,dt),e(b,pe),e(pe,ft),e(b,ct),e(b,_e),e(_e,ht),e(b,ut),c(t,Oe,d),c(t,le,d),e(le,pt),c(t,Ne,d),c(t,S,d),e(S,P),e(P,ge),M(K,ge,null),e(S,_t),e(S,we),e(we,gt),c(t,Ue,d),c(t,A,d),M(G,A,null),e(A,wt),e(A,ve),e(ve,vt),c(t,Ve,d),c(t,I,d),M(W,I,null),e(I,bt),e(I,be),e(be,yt),c(t,Ke,d),c(t,g,d),M(J,g,null),e(g,$t),e(g,y),e(y,Et),e(y,ye),e(ye,xt),e(y,Tt),e(y,$e),e($e,kt),e(y,zt),e(y,R),e(R,qt),e(y,Ct),e(g,Mt),e(g,Ee),e(Ee,Ft),e(g,Dt),e(g,Q),e(Q,me),e(me,Ht),e(me,$),e($,X),e(X,St),e(X,xe),e(xe,At),e(X,It),e($,Lt),e($,Y),e(Y,Pt),e(Y,Te),e(Te,jt),e(Y,Bt),e($,Ot),e($,ke),e(ke,Nt),e($,Ut),e($,ze),e(ze,Vt),e(Q,Kt),e(Q,w),e(w,Gt),e(w,qe),e(qe,Wt),e(w,Jt),e(w,Ce),e(Ce,Rt),e(w,Qt),e(w,Me),e(Me,Xt),e(w,Yt),e(w,Fe),e(Fe,Zt),e(w,er),c(t,Ge,d),c(t,E,d),M(Z,E,null),e(E,tr),e(E,ee),e(ee,rr),e(ee,De),e(De,or),e(ee,ar),e(E,nr),M(j,E,null),c(t,We,d),c(t,v,d),M(te,v,null),e(v,sr),e(v,re),e(re,ir),e(re,He),e(He,lr),e(re,mr),e(v,dr),e(v,Se),e(Se,fr),e(v,cr),e(v,oe),e(oe,Ae),e(Ae,hr),e(oe,ur),e(oe,Ie),e(Ie,pr),c(t,Je,d),c(t,x,d),M(ae,x,null),e(x,_r),e(x,ne),e(ne,gr),e(ne,Le),e(Le,wr),e(ne,vr),e(x,br),e(x,Pe),e(Pe,yr),Re=!0},p(t,[d]){const se={};d&2&&(se.$$scope={dirty:d,ctx:t}),j.$set(se)},i(t){Re||(F(f.$$.fragment,t),F(K.$$.fragment,t),F(G.$$.fragment,t),F(W.$$.fragment,t),F(J.$$.fragment,t),F(Z.$$.fragment,t),F(j.$$.fragment,t),F(te.$$.fragment,t),F(ae.$$.fragment,t),Re=!0)},o(t){D(f.$$.fragment,t),D(K.$$.fragment,t),D(G.$$.fragment,t),D(W.$$.fragment,t),D(J.$$.fragment,t),D(Z.$$.fragment,t),D(j.$$.fragment,t),D(te.$$.fragment,t),D(ae.$$.fragment,t),Re=!1},d(t){r(u),t&&r(L),t&&r(_),H(f),t&&r(Be),t&&r(b),t&&r(Oe),t&&r(le),t&&r(Ne),t&&r(S),H(K),t&&r(Ue),t&&r(A),H(G),t&&r(Ve),t&&r(I),H(W),t&&r(Ke),t&&r(g),H(J),t&&r(Ge),t&&r(E),H(Z),H(j),t&&r(We),t&&r(v),H(te),t&&r(Je),t&&r(x),H(ae)}}}const ho={local:"utilities-for-featureextractors",sections:[{local:"transformers.audio_utils.hertz_to_mel",title:"Audio Transformations"}],title:"Utilities for `FeatureExtractors`"};function uo(je){return so(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class bo extends ro{constructor(u){super();oo(this,u,uo,co,ao,{})}}export{bo as default,ho as metadata};
