Commit b5e32295 authored by Anthony Larcher's avatar Anthony Larcher
Browse files

Copyright modification

parent ad91c87c
# -*- coding: utf-8 -*-
"""
Copyright 2014-2015 Anthony Larcher
Copyright 2014-2016 Anthony Larcher
.. topic::sidekit
......
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 18 19:30:05 2014
@author: antho
# This package is a translation of a part of the BOSARIS toolkit.
# The authors thank Niko Brummer and Agnitio for allowing them to
# translate this code and provide the community with efficient structures
# and tools.
#
# The BOSARIS Toolkit is a collection of functions and classes in Matlab
# that can be used to calibrate, fuse and plot scores from speaker recognition
# (or other fields in which scores are used to test the hypothesis that two
# samples are from the same source) trials involving a model and a test segment.
# The toolkit was written at the BOSARIS2010 workshop which took place at the
# University of Technology in Brno, Czech Republic from 5 July to 6 August 2010.
# See the User Guide (available on the toolkit website)1 for a discussion of the
# theory behind the toolkit and descriptions of some of the algorithms used.
#
# The BOSARIS toolkit in MATLAB can be downloaded from `the website
# <https://sites.google.com/site/bosaristoolkit/>`_.
"""
This is the 'ndx' module
"""
import numpy as np
import os
......
......@@ -411,13 +411,13 @@
<span class="bp">self</span><span class="o">.</span><span class="n">shift</span> <span class="o">=</span> <span class="mf">0.01</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ceps_number</span> <span class="o">=</span> <span class="mi">13</span>
<span class="bp">self</span><span class="o">.</span><span class="n">snr</span> <span class="o">=</span> <span class="mi">40</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vad</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">=</span> <span class="s">&#39;cmvn_win&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vad</span> <span class="o">=</span> <span class="s">&#39;snr&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">=</span> <span class="s">&#39;cmvn&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">log_e</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rasta</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rasta</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">def</span> <span class="nf">_config_sid_8k</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
......@@ -547,7 +547,6 @@
<span class="n">label</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">cep</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">label</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">cep</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">label</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
......@@ -642,7 +641,7 @@
<span class="n">label</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vad</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;no vad&#39;</span><span class="p">)</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">True</span><span class="p">]</span> <span class="o">*</span> <span class="n">x</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">True</span><span class="p">]</span> <span class="o">*</span> <span class="n">logEnergy</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">vad</span> <span class="o">==</span> <span class="s">&#39;snr&#39;</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;vad : snr&#39;</span><span class="p">)</span>
<span class="n">window_sample</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">)</span>
......@@ -659,7 +658,7 @@
<span class="n">label_filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">label_dir</span><span class="p">,</span> <span class="n">show</span> <span class="o">+</span> <span class="n">ext</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_file_extension</span><span class="p">)</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">read_label</span><span class="p">(</span><span class="n">label_filename</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">warrning</span><span class="p">(</span><span class="s">&#39;Wrong VAD type&#39;</span><span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&#39;Wrong VAD type&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">label</span>
<span class="k">def</span> <span class="nf">_rasta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="p">):</span>
......@@ -721,7 +720,7 @@
<span class="k">for</span> <span class="n">chan</span><span class="p">,</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">cep</span><span class="p">):</span>
<span class="n">stg</span><span class="p">(</span><span class="n">cep</span><span class="p">[</span><span class="n">chan</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">[</span><span class="n">chan</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">warrning</span><span class="p">(</span><span class="s">&#39;Wrong feature normalisation type&#39;</span><span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&#39;Wrong feature normalisation type&#39;</span><span class="p">)</span>
<div class="viewcode-block" id="FeaturesServer.load"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.load">[docs]</a> <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
......
......@@ -273,7 +273,6 @@
<span class="c"># Verify that mel2hz(melsc)&gt;linsc</span>
<span class="k">while</span> <span class="n">mel2hz</span><span class="p">(</span><span class="n">melsc</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">linsc</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;nlinfilt = &#39;</span><span class="p">,</span> <span class="n">nlinfilt</span><span class="p">,</span> <span class="s">&#39; nlogfilt = &#39;</span><span class="p">,</span> <span class="n">nlogfilt</span><span class="p">,</span> <span class="s">&#39; ne fonctionne pas&#39;</span><span class="p">)</span>
<span class="c"># in this case, we add a linear filter</span>
<span class="n">nlinfilt</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">nlogfilt</span> <span class="o">-=</span> <span class="mi">1</span>
......@@ -367,18 +366,9 @@
<span class="k">return</span> <span class="n">fbank</span><span class="p">,</span> <span class="n">sub_band_freqs</span>
</div>
<div class="viewcode-block" id="mfcc"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.mfcc">[docs]</a><span class="k">def</span> <span class="nf">mfcc</span><span class="p">(</span><span class="n">input_sig</span><span class="p">,</span> <span class="n">lowfreq</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">maxfreq</span><span class="o">=</span><span class="mi">8000</span><span class="p">,</span> <span class="n">nlinfilt</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">nlogfilt</span><span class="o">=</span><span class="mi">24</span><span class="p">,</span>
<span class="n">nwin</span><span class="o">=</span><span class="mf">0.025</span><span class="p">,</span> <span class="n">fs</span><span class="o">=</span><span class="mi">16000</span><span class="p">,</span> <span class="n">nceps</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="n">midfreq</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">shift</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span>
<span class="n">nwin</span><span class="o">=</span><span class="mf">0.025</span><span class="p">,</span> <span class="n">fs</span><span class="o">=</span><span class="mi">16000</span><span class="p">,</span> <span class="n">nceps</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="n">shift</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span>
<span class="n">get_spec</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">get_mspec</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Compute Mel Frequency Cepstral Coefficients.</span>
......@@ -420,13 +410,12 @@
<span class="c"># Pre-emphasis factor (to take into account the -6dB/octave rolloff of the</span>
<span class="c"># radiation at the lips level</span>
<span class="n">prefac</span> <span class="o">=</span> <span class="mf">0.97</span>
<span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;pre emphasis&#39;</span><span class="p">)</span>
<span class="n">extract</span> <span class="o">=</span> <span class="n">pre_emphasis</span><span class="p">(</span><span class="n">input_sig</span><span class="p">,</span> <span class="n">prefac</span><span class="p">)</span>
<span class="c"># Compute the overlap of frames and cut the signal in frames of length nwin</span>
<span class="c"># overlaping by &quot;overlap&quot; samples</span>
<span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;axis&#39;</span><span class="p">)</span>
<span class="n">window_length</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">nwin</span> <span class="o">*</span> <span class="n">fs</span><span class="p">))</span>
<span class="c">#window_length = int((nwin * fs))</span>
<span class="n">w</span> <span class="o">=</span> <span class="n">hamming</span><span class="p">(</span><span class="n">window_length</span><span class="p">,</span> <span class="n">sym</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">overlap</span> <span class="o">=</span> <span class="n">window_length</span> <span class="o">-</span> <span class="nb">int</span><span class="p">(</span><span class="n">shift</span> <span class="o">*</span> <span class="n">fs</span><span class="p">)</span>
<span class="n">framed</span> <span class="o">=</span> <span class="n">segment_axis</span><span class="p">(</span><span class="n">extract</span><span class="p">,</span> <span class="n">window_length</span><span class="p">,</span> <span class="n">overlap</span><span class="p">)</span>
......@@ -441,7 +430,6 @@
<span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">stop</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">dec</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
<span class="k">while</span> <span class="n">start</span> <span class="o">&lt;</span> <span class="n">l</span><span class="p">:</span>
<span class="c"># logging.debug(&#39;fft start: %d stop: %d&#39;, start, stop)</span>
<span class="c"># Compute the spectrum magnitude</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">framed</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">,</span> <span class="p">:]</span> <span class="o">*</span> <span class="n">w</span>
<span class="n">spec</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">rfft</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">nfft</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">))</span>
......@@ -456,14 +444,11 @@
<span class="c"># Filter the spectrum through the triangle filterbank</span>
<span class="c"># Prepare the hamming window and the filter bank</span>
<span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;trf bank&#39;</span><span class="p">)</span>
<span class="n">fbank</span> <span class="o">=</span> <span class="n">trfbank</span><span class="p">(</span><span class="n">fs</span><span class="p">,</span> <span class="n">nfft</span><span class="p">,</span> <span class="n">lowfreq</span><span class="p">,</span> <span class="n">maxfreq</span><span class="p">,</span> <span class="n">nlinfilt</span><span class="p">,</span> <span class="n">nlogfilt</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="c"># mspec = np.log(np.maximum(1.0, np.dot(spec, fbank.T)))</span>
<span class="n">mspec</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="n">fbank</span><span class="o">.</span><span class="n">T</span><span class="p">))</span>
<span class="n">mspec</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">spec</span><span class="p">,</span> <span class="n">fbank</span><span class="o">.</span><span class="n">T</span><span class="p">))</span>
<span class="k">del</span> <span class="n">fbank</span>
<span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;dct&#39;</span><span class="p">)</span>
<span class="c"># Use the DCT to &#39;compress&#39; the coefficients (spectrum -&gt; cepstrum domain)</span>
<span class="c"># The C0 term is removed as it is the constant term</span>
<span class="n">ceps</span> <span class="o">=</span> <span class="n">dct</span><span class="p">(</span><span class="n">mspec</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">norm</span><span class="o">=</span><span class="s">&#39;ortho&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)[:,</span> <span class="mi">1</span><span class="p">:</span><span class="n">nceps</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
......@@ -502,35 +487,42 @@
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">stride_tricks</span><span class="o">.</span><span class="n">as_strided</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">sig</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="s">&#39;constant&#39;</span><span class="p">,</span> <span class="n">constant_values</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,)),</span>
<span class="n">shape</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span>
<span class="n">strides</span><span class="o">=</span><span class="n">strides</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span>
<span class="c">############</span>
<span class="c"># Ask permission to LUKAS (replace with my own function including padding...)</span>
<span class="c"># def framing(a, window, shift=1):</span>
<span class="c"># &quot;&quot;&quot;</span>
<span class="c"># a is a matrix of features, one feature per line</span>
<span class="c"># window is the size of the sliding window (in number of features)$</span>
<span class="c">#</span>
<span class="c"># assume that left and right context have been added to the sequence of features</span>
<span class="c"># &quot;&quot;&quot;</span>
<span class="c"># shape = ((a.shape[0] - window) / shift + 1, window) + a.shape[1:]</span>
<span class="c"># strides = (a.strides[0] * shift, a.strides[0]) + a.strides[1:]</span>
<span class="c"># return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)</span>
</div>
<span class="k">def</span> <span class="nf">dct_basis</span><span class="p">(</span><span class="n">nbasis</span><span class="p">,</span> <span class="n">length</span><span class="p">):</span>
<div class="viewcode-block" id="dct_basis"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.dct_basis">[docs]</a><span class="k">def</span> <span class="nf">dct_basis</span><span class="p">(</span><span class="n">nbasis</span><span class="p">,</span> <span class="n">length</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> :param nbasis: number of CT coefficients to keep</span>
<span class="sd"> :param length: length of the matrix to process</span>
<span class="sd"> :return: a basis of DCT coefficients</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">scipy</span><span class="o">.</span><span class="n">fftpack</span><span class="o">.</span><span class="n">idct</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="n">nbasis</span><span class="p">,</span> <span class="n">length</span><span class="p">),</span> <span class="n">norm</span><span class="o">=</span><span class="s">&#39;ortho&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="get_trap"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.get_trap">[docs]</a><span class="k">def</span> <span class="nf">get_trap</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">left_ctx</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">right_ctx</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">dct_nb</span><span class="o">=</span><span class="mi">16</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">get_trap</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">left_ctx</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">right_ctx</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">dct_nb</span><span class="o">=</span><span class="mi">16</span><span class="p">):</span>
<span class="sd"> :param X: matrix of acoustic frames</span>
<span class="sd"> :param left_ctx: left context of the frame to consider (given in number of frames)</span>
<span class="sd"> :param right_ctx: right context of the frame to consider (given in number of frames)</span>
<span class="sd"> :param dct_nb: number of DCT coefficient to keep for dimensionality reduction</span>
<span class="sd"> :return: matrix of traps features (in rows)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">X</span> <span class="o">=</span> <span class="n">framing</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">win_size</span><span class="o">=</span><span class="n">left_ctx</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">right_ctx</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">hamming_dct</span> <span class="o">=</span> <span class="p">(</span><span class="n">dct_basis</span><span class="p">(</span><span class="n">dct_nb</span><span class="p">,</span> <span class="n">left_ctx</span> <span class="o">+</span> <span class="n">right_ctx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">hamming</span><span class="p">(</span><span class="n">left_ctx</span> <span class="o">+</span> <span class="n">right_ctx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">T</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span>
<span class="s">&quot;float32&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">X</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">hamming_dct</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">hamming_dct</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">X</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="get_context"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.get_context">[docs]</a><span class="k">def</span> <span class="nf">get_context</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">left_ctx</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">right_ctx</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">apply_hamming</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">get_context</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">left_ctx</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">right_ctx</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">apply_hamming</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd"> :param X: matrix of acoustic frames</span>
<span class="sd"> :param left_ctx: left context of the frame to consider (given in number of frames)</span>
<span class="sd"> :param right_ctx: right context of the frame to consider (given in number of frames)</span>
<span class="sd"> :param apply_hamming: boolean, if True, multiply by a temporal hamming window</span>
<span class="sd"> :return: a matrix of frames concatenated with their left and right context</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">X</span> <span class="o">=</span> <span class="n">framing</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">win_size</span><span class="o">=</span><span class="n">left_ctx</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">right_ctx</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="n">left_ctx</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">right_ctx</span><span class="p">)</span> <span class="o">*</span> <span class="n">X</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="n">X</span>
<span class="k">return</span> <span class="n">X</span></div>
</pre></div>
</div>
......
......@@ -117,7 +117,7 @@
<span class="sd"> :param input_sig: the input vector of signal to pre emphasize</span>
<span class="sd"> :param pre: value that defines the pre-emphasis filter. </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">lfilter</span><span class="p">([</span><span class="mf">1.0</span><span class="p">,</span> <span class="o">-</span><span class="n">pre</span><span class="p">],</span> <span class="mi">1</span><span class="p">,</span> <span class="n">input_sig</span><span class="p">)</span>
<span class="k">return</span> <span class="n">lfilter</span><span class="p">([</span><span class="mf">1.0</span><span class="p">,</span> <span class="o">-</span><span class="n">pre</span><span class="p">],</span> <span class="mi">1</span><span class="p">,</span> <span class="n">input_sig</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>
</div>
<div class="viewcode-block" id="segment_axis"><a class="viewcode-back" href="../../frontend/vad.html#frontend.vad.segment_axis">[docs]</a><span class="k">def</span> <span class="nf">segment_axis</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">length</span><span class="p">,</span> <span class="n">overlap</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s">&#39;cut&#39;</span><span class="p">,</span> <span class="n">endvalue</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
......
......@@ -95,6 +95,10 @@
<span class="kn">from</span> <span class="nn">sidekit.statserver</span> <span class="kn">import</span> <span class="n">StatServer</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="o">.</span><span class="n">major</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="p">:</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="nb">reduce</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s">&quot;LGPL&quot;</span>
<span class="n">__author__</span> <span class="o">=</span> <span class="s">&quot;Anthony Larcher&quot;</span>
......
......@@ -98,6 +98,9 @@
<span class="kn">import</span> <span class="nn">gzip</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="o">.</span><span class="n">major</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="p">:</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="nb">reduce</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s">&quot;LGPL&quot;</span>
<span class="n">__author__</span> <span class="o">=</span> <span class="s">&quot;Anthony Larcher&quot;</span>
......
......@@ -131,7 +131,7 @@
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">test_sv</span><span class="p">,</span> <span class="n">StatServer</span><span class="p">),</span> <span class="s">&#39;Second parameter should be a StatServer&#39;</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ndx</span><span class="p">,</span> <span class="n">Ndx</span><span class="p">),</span> <span class="s">&#39;Third parameter should be an Ndx&#39;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">segIdx</span><span class="p">:</span>
<span class="k">if</span> <span class="n">segIdx</span> <span class="o">==</span> <span class="p">[]:</span>
<span class="n">segIdx</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">ndx</span><span class="o">.</span><span class="n">segset</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="c"># Load SVM models</span>
......
......@@ -116,6 +116,26 @@ is similar to SPRO4: filt=np.array([.2, .1, 0, -.1, -.2])</li>
</table>
</dd></dl>
<dl class="function">
<dt id="frontend.features.dct_basis">
<code class="descclassname">frontend.features.</code><code class="descname">dct_basis</code><span class="sig-paren">(</span><em>nbasis</em>, <em>length</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#dct_basis"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.dct_basis" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>nbasis</strong> &#8211; number of CT coefficients to keep</li>
<li><strong>length</strong> &#8211; length of the matrix to process</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a basis of DCT coefficients</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="frontend.features.framing">
<code class="descclassname">frontend.features.</code><code class="descname">framing</code><span class="sig-paren">(</span><em>sig</em>, <em>win_size</em>, <em>win_shift=1</em>, <em>context=(0</em>, <em>0)</em>, <em>pad='zeros'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#framing"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.framing" title="Permalink to this definition"></a></dt>
......@@ -135,6 +155,50 @@ is similar to SPRO4: filt=np.array([.2, .1, 0, -.1, -.2])</li>
</table>
</dd></dl>
<dl class="function">
<dt id="frontend.features.get_context">
<code class="descclassname">frontend.features.</code><code class="descname">get_context</code><span class="sig-paren">(</span><em>X</em>, <em>left_ctx=7</em>, <em>right_ctx=7</em>, <em>apply_hamming=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#get_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.get_context" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>X</strong> &#8211; matrix of acoustic frames</li>
<li><strong>left_ctx</strong> &#8211; left context of the frame to consider (given in number of frames)</li>
<li><strong>right_ctx</strong> &#8211; right context of the frame to consider (given in number of frames)</li>
<li><strong>apply_hamming</strong> &#8211; boolean, if True, multiply by a temporal hamming window</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a matrix of frames concatenated with their left and right context</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="frontend.features.get_trap">
<code class="descclassname">frontend.features.</code><code class="descname">get_trap</code><span class="sig-paren">(</span><em>X</em>, <em>left_ctx=15</em>, <em>right_ctx=15</em>, <em>dct_nb=16</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#get_trap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.get_trap" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>X</strong> &#8211; matrix of acoustic frames</li>
<li><strong>left_ctx</strong> &#8211; left context of the frame to consider (given in number of frames)</li>
<li><strong>right_ctx</strong> &#8211; right context of the frame to consider (given in number of frames)</li>
<li><strong>dct_nb</strong> &#8211; number of DCT coefficient to keep for dimensionality reduction</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">matrix of traps features (in rows)</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="frontend.features.hz2mel">
<code class="descclassname">frontend.features.</code><code class="descname">hz2mel</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#hz2mel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.hz2mel" title="Permalink to this definition"></a></dt>
......@@ -194,7 +258,7 @@ is similar to SPRO4: filt=np.array([.2, .1, 0, -.1, -.2])</li>
<dl class="function">
<dt id="frontend.features.mfcc">
<code class="descclassname">frontend.features.</code><code class="descname">mfcc</code><span class="sig-paren">(</span><em>input_sig</em>, <em>lowfreq=100</em>, <em>maxfreq=8000</em>, <em>nlinfilt=0</em>, <em>nlogfilt=24</em>, <em>nwin=0.025</em>, <em>fs=16000</em>, <em>nceps=13</em>, <em>midfreq=1000</em>, <em>shift=0.01</em>, <em>get_spec=False</em>, <em>get_mspec=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#mfcc"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.mfcc" title="Permalink to this definition"></a></dt>
<code class="descclassname">frontend.features.</code><code class="descname">mfcc</code><span class="sig-paren">(</span><em>input_sig</em>, <em>lowfreq=100</em>, <em>maxfreq=8000</em>, <em>nlinfilt=0</em>, <em>nlogfilt=24</em>, <em>nwin=0.025</em>, <em>fs=16000</em>, <em>nceps=13</em>, <em>shift=0.01</em>, <em>get_spec=False</em>, <em>get_mspec=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/frontend/features.html#mfcc"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#frontend.features.mfcc" title="Permalink to this definition"></a></dt>
<dd><p>Compute Mel Frequency Cepstral Coefficients.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
......
......@@ -196,6 +196,10 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="frontend/features.html#frontend.features.dct_basis">dct_basis() (in module frontend.features)</a>
</dt>
<dt><a href="bosaris/detplot.html#bosaris.DetPlot">DetPlot (class in bosaris)</a>
</dt>
......@@ -338,6 +342,10 @@
</dt>
<dt><a href="frontend/features.html#frontend.features.get_context">get_context() (in module frontend.features)</a>
</dt>
<dt><a href="mixture.html#mixture.Mixture.get_invcov_super_vector">get_invcov_super_vector() (mixture.Mixture method)</a>
</dt>
......@@ -420,6 +428,10 @@
</dt>
<dt><a href="frontend/features.html#frontend.features.get_trap">get_trap() (in module frontend.features)</a>
</dt>
<dt><a href="statserver.html#statserver.StatServer.get_wccn_choleski_stat1">get_wccn_choleski_stat1() (statserver.StatServer method)</a>
</dt>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment