features_server.html 159 KB
Newer Older
Anthony Larcher's avatar
Anthony Larcher committed
1
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Anthony Larcher's avatar
Anthony Larcher committed
3
4


Anthony Larcher's avatar
Anthony Larcher committed
5
6
7
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Anthony Larcher's avatar
Anthony Larcher committed
8
    
Anthony Larcher's avatar
Anthony Larcher committed
9
    <title>features_server &mdash; SIDEKIT 1.0.0 documentation</title>
Anthony Larcher's avatar
Anthony Larcher committed
10
    
Anthony Larcher's avatar
Anthony Larcher committed
11
    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
Anthony Larcher's avatar
Anthony Larcher committed
12
13
14
15
16
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
Anthony Larcher's avatar
Anthony Larcher committed
17
        VERSION:     '1.0.0',
Anthony Larcher's avatar
Anthony Larcher committed
18
19
20
21
22
23
24
25
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
Anthony Larcher's avatar
Anthony Larcher committed
26
    <link rel="top" title="SIDEKIT 1.0.0 documentation" href="../index.html" />
Anthony Larcher's avatar
Anthony Larcher committed
27
28
29
30
31
32
33
34
35
36
37
38
    <link rel="up" title="Module code" href="index.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
Anthony Larcher's avatar
Anthony Larcher committed
39
        <li class="nav-item nav-item-0"><a href="../index.html">SIDEKIT 1.0.0 documentation</a> &raquo;</li>
Anthony Larcher's avatar
Anthony Larcher committed
40
41
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
Anthony Larcher's avatar
Anthony Larcher committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
Anthony Larcher's avatar
Anthony Larcher committed
60
61
62
63
64

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
Anthony Larcher's avatar
Anthony Larcher committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
            
  <h1>Source code for features_server</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="c">#</span>
<span class="c"># This file is part of SIDEKIT.</span>
<span class="c">#</span>
<span class="c"># SIDEKIT is a python package for speaker verification.</span>
<span class="c"># Home page: http://www-lium.univ-lemans.fr/sidekit/</span>
<span class="c">#</span>
<span class="c"># SIDEKIT is a python package for speaker verification.</span>
<span class="c"># Home page: http://www-lium.univ-lemans.fr/sidekit/</span>
<span class="c">#    </span>
<span class="c"># SIDEKIT is free software: you can redistribute it and/or modify</span>
<span class="c"># it under the terms of the GNU LLesser General Public License as </span>
<span class="c"># published by the Free Software Foundation, either version 3 of the License, </span>
<span class="c"># or (at your option) any later version.</span>
<span class="c">#</span>
<span class="c"># SIDEKIT is distributed in the hope that it will be useful,</span>
<span class="c"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="c"># GNU Lesser General Public License for more details.</span>
<span class="c">#</span>
<span class="c"># You should have received a copy of the GNU Lesser General Public License</span>
<span class="c"># along with SIDEKIT.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Copyright 2014-2015 Sylvain Meignier and Anthony Larcher</span>

<span class="sd">    :mod:`features_server` provides methods to manage features</span>

<span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
96
97
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">multiprocessing</span>
Anthony Larcher's avatar
Anthony Larcher committed
98
<span class="kn">import</span> <span class="nn">logging</span>
Anthony Larcher's avatar
Anthony Larcher committed
99
<span class="kn">from</span> <span class="nn">sidekit</span> <span class="kn">import</span> <span class="n">PARALLEL_MODULE</span>
Anthony Larcher's avatar
Anthony Larcher committed
100
101
102
103
<span class="kn">from</span> <span class="nn">sidekit.frontend.features</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">sidekit.frontend.vad</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">sidekit.frontend.io</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">sidekit.frontend.normfeat</span> <span class="kn">import</span> <span class="o">*</span>
Anthony Larcher's avatar
Anthony Larcher committed
104
105
<span class="kn">from</span> <span class="nn">sidekit.sidekit_wrappers</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">import</span> <span class="nn">sys</span>
Anthony Larcher's avatar
Anthony Larcher committed
106
107
<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">ctypes</span>
Anthony Larcher's avatar
Anthony Larcher committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

<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">==</span> <span class="mi">3</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">queue</span> <span class="kn">as</span> <span class="nn">Queue</span>
<span class="k">else</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">Queue</span>
<span class="c"># import memory_profiler</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>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">&quot;Copyright 2014-2016 Anthony Larcher&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s">&quot;Anthony Larcher&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s">&quot;anthony.larcher@univ-lemans.fr&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s">&quot;Production&quot;</span>
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s">&#39;reStructuredText&#39;</span>
Anthony Larcher's avatar
Anthony Larcher committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174


<div class="viewcode-block" id="FeaturesServer"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer">[docs]</a><span class="k">class</span> <span class="nc">FeaturesServer</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A class for acoustic feature management.</span>
<span class="sd">    FeaturesServer should be used to extract acoustic features (MFCC or LFCC)</span>
<span class="sd">    from audio files in SPHERE, WAV or RAW PCM format.</span>
<span class="sd">    It can also be used to read and write acoustic features from and to disk</span>
<span class="sd">    in SPRO4 or HTK format.</span>

<span class="sd">    :attr input_dir: directory where to load audio or feature files</span>
<span class="sd">    :attr input_file_extension: extension of the incoming files</span>
<span class="sd">    :attrlabel_dir: directory where to read and write label files</span>
<span class="sd">    :attr label_files_extension: extension of label files to read and write</span>
<span class="sd">    :attr from_file: format of the input files to read, can be `audio`, `spro4`</span>
<span class="sd">        or `htk`, for audio files, format is given by the extension</span>
<span class="sd">    :attr config: pre-defined configuration for speaker diarization or recognition</span>
<span class="sd">        in 8 or 16kHz. Default is speaker recognition 8kHz</span>
<span class="sd">    :attr single_channel_extension: list with a single extension to add to </span>
<span class="sd">        the audio filename when processing a single channel file. </span>
<span class="sd">        Default is empty, means the feature file has the same name as </span>
<span class="sd">        the audio file</span>
<span class="sd">    :attr double_channel_extension: list of two channel extension to add </span>
<span class="sd">        to the audio filename when processing two channel files. </span>
<span class="sd">        Default is [&#39;_a&#39;, &#39;_b&#39;]</span>
<span class="sd">    :attr sampling_frequency: sample frequency in Hz, default is None, </span>
<span class="sd">        determine when reading the audio file</span>
<span class="sd">    :attr lower_frequency: lower frequency limit of the filter bank</span>
<span class="sd">    :attr higher_frequency: higher frequency limit of the filter bank</span>
<span class="sd">    :attr linear_filters: number of linear filters to use for LFCC extraction</span>
<span class="sd">    :attr log_filters: number of linear filters to use for MFCC extraction</span>
<span class="sd">    :attr window_size: size of the sliding window in seconds</span>
<span class="sd">    :attr shift: time shift between two feature vectors</span>
<span class="sd">    :attr ceps_number: number of cepstral coefficients to extract</span>
<span class="sd">    :attr snr: snr level to consider for SNR-based voice activity detection</span>
<span class="sd">    :attr vad: type of voice activity detection to use, can be &#39;snr&#39;, &#39;energy&#39; </span>
<span class="sd">        (using a three Gaussian detector) or &#39;label&#39; when reading the info from </span>
<span class="sd">        pre-computed label files</span>
<span class="sd">    :attr feat_norm: normalization of the acoustic features, can be </span>
<span class="sd">        &#39;cms&#39; for cepstral mean subtraction, &#39;mvn&#39; for mean variance </span>
<span class="sd">        normalization or &#39;stg&#39; for short term Gaussianization</span>
<span class="sd">    :attr log_e: boolean, keep log energy</span>
<span class="sd">    :attr delta: boolean, add the first derivative of the cepstral coefficients</span>
<span class="sd">    :attr double_delta: boolean, add the second derivative of the cepstral </span>
<span class="sd">        coefficients</span>
<span class="sd">    :attr rasta: boolean, perform RASTA filtering</span>
<span class="sd">    :attr keep_all_features: boolean, if False, only features labeled as </span>
<span class="sd">        &quot;speech&quot; by the vad are saved if True, all features are saved and </span>
<span class="sd">        a label file is produced</span>

<span class="sd">    &quot;&quot;&quot;</span>

Anthony Larcher's avatar
Anthony Larcher committed
175
176
177
178
179
180
181
182
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">input_dir</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">input_file_extension</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">label_dir</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">label_file_extension</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">from_file</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">config</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">single_channel_extension</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">),</span>
                 <span class="n">double_channel_extension</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;_a&#39;</span><span class="p">,</span> <span class="s">&#39;_b&#39;</span><span class="p">),</span>
Anthony Larcher's avatar
Anthony Larcher committed
183
184
185
186
187
188
189
190
191
192
193
194
                 <span class="n">sampling_frequency</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">lower_frequency</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">higher_frequency</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">linear_filters</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">log_filters</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">window_size</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">shift</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">ceps_number</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">snr</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">vad</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">feat_norm</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">log_e</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
195
196
197
198
                 <span class="n">dct_pca</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                 <span class="n">dct_pca_config</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">sdc</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                 <span class="n">sdc_config</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
199
200
                 <span class="n">delta</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">double_delta</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
201
                 <span class="n">delta_filter</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
202
203
204
205
                 <span class="n">rasta</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">keep_all_features</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                 <span class="n">spec</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
                 <span class="n">mspec</span><span class="o">=</span><span class="bp">False</span>
Anthony Larcher's avatar
Anthony Larcher committed
206
                 <span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
        <span class="sd">&quot;&quot;&quot; Process of extracting the feature frames (LFCC or MFCC) from an audio signal.</span>
<span class="sd">        Speech Activity Detection, MFCC (or LFCC) extraction and normalization.</span>
<span class="sd">        Can include RASTA filtering, Short Term Gaussianization, MVN and delta</span>
<span class="sd">        computation.</span>

<span class="sd">        :param input_dir: directory where to find the audio files.</span>
<span class="sd">                Default is ./</span>
<span class="sd">        :param input_file_extension: extension of the audio files to read.</span>
<span class="sd">                Default is &#39;sph&#39;.</span>
<span class="sd">        :param label_dir: directory where to store label files is required.</span>
<span class="sd">                Default is ./</span>
<span class="sd">        :param label_file_extension: extension of the label files to create.</span>
<span class="sd">                Default is &#39;.lbl&#39;.</span>
<span class="sd">        :param configuration file : &#39;diar_16k&#39;, &#39;sid_16k&#39;, &#39;diar_8k&#39; or &#39;sid_8k&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>

Anthony Larcher's avatar
Anthony Larcher committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
        <span class="bp">self</span><span class="o">.</span><span class="n">input_dir</span> <span class="o">=</span> <span class="s">&#39;./&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span> <span class="o">=</span> <span class="s">&#39;wav&#39;</span>        
        <span class="bp">self</span><span class="o">.</span><span class="n">label_dir</span> <span class="o">=</span> <span class="s">&#39;./&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">label_file_extension</span> <span class="o">=</span> <span class="s">&#39;.lbl&#39;</span>        
        <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span> <span class="o">=</span> <span class="s">&#39;audio&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">single_channel_extension</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;&#39;</span><span class="p">],</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;_a&#39;</span><span class="p">,</span> <span class="s">&#39;_b&#39;</span><span class="p">],</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">8000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">/</span> <span class="mf">2.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">24</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
        <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>
Anthony Larcher's avatar
Anthony Larcher committed
239
240
        <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="bp">None</span>
Anthony Larcher's avatar
Anthony Larcher committed
241
242
243
244
245
246
247
248
249
250
251
252
        <span class="bp">self</span><span class="o">.</span><span class="n">log_e</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span> <span class="o">=</span> <span class="bp">False</span>        
        <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span> <span class="o">=</span> <span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filter</span> <span class="o">=</span> <span class="bp">None</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">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spec</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mspec</span> <span class="o">=</span> <span class="bp">False</span>
Anthony Larcher's avatar
Anthony Larcher committed
253

Anthony Larcher's avatar
Anthony Larcher committed
254
        <span class="c"># If a predefined config is chosen, apply it</span>
Anthony Larcher's avatar
Anthony Larcher committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
        <span class="k">if</span> <span class="n">config</span> <span class="o">==</span> <span class="s">&#39;diar_16k&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_config_diar_16k</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">config</span> <span class="o">==</span> <span class="s">&#39;diar_8k&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_config_diar_8k</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">config</span> <span class="o">==</span> <span class="s">&#39;sid_8k&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_config_sid_8k</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">config</span> <span class="o">==</span> <span class="s">&#39;sid_16k&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_config_sid_16k</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">config</span> <span class="o">==</span> <span class="s">&#39;fb_8k&#39;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_config_fb_8k</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">config</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;unknown configuration value&#39;</span><span class="p">)</span>

Anthony Larcher's avatar
Anthony Larcher committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
        <span class="c"># Manually entered parameters are applied</span>
        <span class="k">if</span> <span class="n">input_dir</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">input_dir</span> <span class="o">=</span> <span class="n">input_dir</span>
        <span class="k">if</span> <span class="n">input_file_extension</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span> <span class="o">=</span> <span class="n">input_file_extension</span>
        <span class="k">if</span> <span class="n">label_dir</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label_dir</span> <span class="o">=</span> <span class="n">label_dir</span>
        <span class="k">if</span> <span class="n">label_file_extension</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label_file_extension</span> <span class="o">=</span> <span class="n">label_file_extension</span>
        <span class="k">if</span> <span class="n">from_file</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span> <span class="o">=</span> <span class="n">from_file</span>
        <span class="k">if</span> <span class="n">single_channel_extension</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">single_channel_extension</span> <span class="o">=</span> <span class="n">single_channel_extension</span>
        <span class="k">if</span> <span class="n">double_channel_extension</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span> <span class="o">=</span> <span class="n">double_channel_extension</span>
Anthony Larcher's avatar
Anthony Larcher committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
        <span class="k">if</span> <span class="n">sampling_frequency</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="n">sampling_frequency</span>
        <span class="k">if</span> <span class="n">lower_frequency</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="n">lower_frequency</span>
        <span class="k">if</span> <span class="n">higher_frequency</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="n">higher_frequency</span>
        <span class="k">if</span> <span class="n">linear_filters</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="n">linear_filters</span>
        <span class="k">if</span> <span class="n">log_filters</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="n">log_filters</span>
        <span class="k">if</span> <span class="n">window_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</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="n">window_size</span>
        <span class="k">if</span> <span class="n">shift</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">shift</span> <span class="o">=</span> <span class="n">shift</span>
        <span class="k">if</span> <span class="n">ceps_number</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ceps_number</span> <span class="o">=</span> <span class="n">ceps_number</span>
        <span class="k">if</span> <span class="n">snr</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">snr</span> <span class="o">=</span> <span class="n">snr</span>
        <span class="k">if</span> <span class="n">vad</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">vad</span> <span class="o">=</span> <span class="n">vad</span>
        <span class="k">if</span> <span class="n">feat_norm</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">=</span> <span class="n">feat_norm</span>
        <span class="k">if</span> <span class="n">log_e</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">log_e</span> <span class="o">=</span> <span class="n">log_e</span>
Anthony Larcher's avatar
Anthony Larcher committed
309
310
311
312
313
314
315
316
        <span class="k">if</span> <span class="n">dct_pca</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span> <span class="o">=</span> <span class="n">dct_pca</span>
        <span class="k">if</span> <span class="n">dct_pca_config</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span> <span class="o">=</span> <span class="n">dct_pca_config</span>
        <span class="k">if</span> <span class="n">sdc</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span> <span class="o">=</span> <span class="n">sdc</span>
        <span class="k">if</span> <span class="n">sdc_config</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span> <span class="o">=</span> <span class="n">sdc_config</span>
Anthony Larcher's avatar
Anthony Larcher committed
317
318
319
320
        <span class="k">if</span> <span class="n">delta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="n">delta</span>
        <span class="k">if</span> <span class="n">double_delta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="n">double_delta</span>
Anthony Larcher's avatar
Anthony Larcher committed
321
322
        <span class="k">if</span> <span class="n">delta_filter</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">filter</span> <span class="o">=</span> <span class="n">delta_filter</span>
Anthony Larcher's avatar
Anthony Larcher committed
323
324
325
326
327
328
329
330
331
332
333
334
        <span class="k">if</span> <span class="n">rasta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span> <span class="o">=</span> <span class="n">rasta</span>
        <span class="k">if</span> <span class="n">keep_all_features</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span> <span class="o">=</span> <span class="n">keep_all_features</span>
        <span class="k">if</span> <span class="n">spec</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spec</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">if</span> <span class="n">mspec</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mspec</span> <span class="o">=</span> <span class="bp">True</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">cep</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show</span> <span class="o">=</span> <span class="s">&#39;empty&#39;</span>
Anthony Larcher's avatar
Anthony Larcher committed
335
        <span class="bp">self</span><span class="o">.</span><span class="n">audio_filename</span> <span class="o">=</span> <span class="s">&#39;empty&#39;</span>
Anthony Larcher's avatar
Anthony Larcher committed
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">ch</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> show: {} keep_all_features: {} from_file: {}</span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">show</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> inputDir: {} inputFileExtension: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">input_dir</span><span class="p">,</span>
                                                                 <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> labelDir: {}  labelFileExtension: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</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="bp">self</span><span class="o">.</span><span class="n">label_file_extension</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> lower_frequency: {}  higher_frequency: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> sampling_frequency: {} &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> linear_filters: {}  or log_filters: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> ceps_number: {}  window_size: {} shift: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ceps_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">shift</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> vad: {}  snr: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vad</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">snr</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> feat_norm: {} rasta: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s"> log_e: {} delta: {} double_delta: {} </span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">log_e</span><span class="p">,</span>
                                                                  <span class="bp">self</span><span class="o">.</span><span class="n">delta</span><span class="p">,</span>
                                                                  <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
356
        <span class="k">return</span> <span class="n">ch</span>
Anthony Larcher's avatar
Anthony Larcher committed
357
358
359
360
361
362
363
364
365
366

    <span class="k">def</span> <span class="nf">_config_diar_16k</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        12 MFCC + E, no norm</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">16000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="mf">133.3333</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="mf">6855.4976</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">40</span>
Anthony Larcher's avatar
Anthony Larcher committed
367
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
Anthony Larcher's avatar
Anthony Larcher committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
        <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">12</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="bp">None</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">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="bp">False</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="k">def</span> <span class="nf">_config_diar_8k</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        12 MFCC + E, no norm</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">8000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">24</span>
Anthony Larcher's avatar
Anthony Larcher committed
388
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
Anthony Larcher's avatar
Anthony Larcher committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
        <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">12</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="bp">None</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">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="bp">False</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="k">def</span> <span class="nf">_config_sid_16k</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        19 MFCC + E + D + DD, norm cmvn</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">16000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="mf">133.3333</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="mf">6855.4976</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">40</span>
Anthony Larcher's avatar
Anthony Larcher committed
409
410
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;_a&#39;</span><span class="p">,</span> <span class="s">&#39;_b&#39;</span><span class="p">],</span>
Anthony Larcher's avatar
Anthony Larcher committed
411
412
413
        <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>
Anthony Larcher's avatar
Anthony Larcher committed
414
415
        <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>
Anthony Larcher's avatar
Anthony Larcher committed
416
417
418
        <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>
Anthony Larcher's avatar
Anthony Larcher committed
419
420
        <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>
Anthony Larcher's avatar
Anthony Larcher committed
421
422
423
424
425
426
427
428
429
430

    <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>
<span class="sd">        19 MFCC + E + D + DD, norm cmvn</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">8000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="mi">300</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="mi">3400</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">24</span>
Anthony Larcher's avatar
Anthony Larcher committed
431
432
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;_a&#39;</span><span class="p">,</span> <span class="s">&#39;_b&#39;</span><span class="p">],</span>
Anthony Larcher's avatar
Anthony Larcher committed
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
        <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="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">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_fb_8k</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        19 MFCC + E + D + DD, norm cmvn</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">8000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="mi">300</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="mi">3400</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">40</span>
Anthony Larcher's avatar
Anthony Larcher committed
453
454
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;_a&#39;</span><span class="p">,</span> <span class="s">&#39;_b&#39;</span><span class="p">],</span>
Anthony Larcher's avatar
Anthony Larcher committed
455
456
457
458
459
460
461
462
463
464
465
        <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">0</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="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_e</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="bp">False</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">mspec</span> <span class="o">=</span> <span class="bp">True</span>
Anthony Larcher's avatar
Anthony Larcher committed
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
 
    <span class="k">def</span> <span class="nf">_config_lid_8k_sdc</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        7 MFCC + 1 - 3 - 7 SDC</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">=</span> <span class="mi">8000</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span> <span class="o">=</span> <span class="mi">300</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span> <span class="o">=</span> <span class="mi">3400</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span> <span class="o">=</span> <span class="mi">24</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.025</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;_a&#39;</span><span class="p">,</span> <span class="s">&#39;_b&#39;</span><span class="p">],</span>
        <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">7</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="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="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">log_e</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</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">False</span>
Anthony Larcher's avatar
Anthony Larcher committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

    <span class="k">def</span> <span class="nf">_features</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="n">cep</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">label</span> <span class="o">=</span> <span class="bp">None</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>
        <span class="n">shift_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">shift</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">)</span>

        <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_dir</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">=</span><span class="n">show</span><span class="p">)</span>
        <span class="n">audio_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="n">d</span><span class="p">,</span> <span class="n">show</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">audio_filename</span><span class="p">):</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_dir</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span>
                          <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span><span class="p">)</span>
            <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s">&#39;File &#39;</span> <span class="o">+</span> <span class="n">audio_filename</span> <span class="o">+</span> <span class="s">&#39; not found&#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;read audio&#39;</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="n">audio_filename</span><span class="p">)</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">rate</span> <span class="o">=</span> <span class="n">read_audio</span><span class="p">(</span><span class="n">audio_filename</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rate</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
507
            <span class="k">raise</span> <span class="s">&quot;file rate don&#39;t match the rate of the feature server configuration&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
508
509
510
511
512
513
514
515
516
        <span class="bp">self</span><span class="o">.</span><span class="n">audio_filename</span> <span class="o">=</span> <span class="n">audio_filename</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39; size of signal: </span><span class="si">%f</span><span class="s"> len </span><span class="si">%d</span><span class="s"> type size </span><span class="si">%d</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">x</span><span class="o">.</span><span class="n">nbytes</span><span class="o">/</span><span class="mi">1024</span><span class="o">/</span><span class="mi">1024</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="o">.</span><span class="n">nbytes</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">ndim</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">[:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span>

        <span class="n">channel_ext</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">channel_nb</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="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
517
        <span class="n">x</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">0.0001</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</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>
Anthony Larcher's avatar
Anthony Larcher committed
518
519
520
521
522
523
524

        <span class="k">if</span> <span class="n">channel_nb</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">channel_ext</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span>
            <span class="c"># Random noise is added to the input signal to avoid zero frames.</span>
        <span class="k">elif</span> <span class="n">channel_nb</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">channel_ext</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;_a&#39;</span><span class="p">)</span>
            <span class="n">channel_ext</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;_b&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
525
            <span class="n">x</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="mf">0.0001</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</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>
Anthony Larcher's avatar
Anthony Larcher committed
526
527
528
529
530
531
532
533

        <span class="c"># Process channels one by one</span>
        <span class="k">for</span> <span class="n">chan</span><span class="p">,</span> <span class="n">chan_ext</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">channel_ext</span><span class="p">):</span>
            <span class="n">l</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">dec</span> <span class="o">=</span> <span class="n">shift_sample</span> <span class="o">*</span> <span class="mi">250</span> <span class="o">*</span> <span class="mi">25000</span> <span class="o">+</span> <span class="n">window_sample</span>
            <span class="n">dec2</span> <span class="o">=</span> <span class="n">window_sample</span> <span class="o">-</span> <span class="n">shift_sample</span>
            <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">end</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>
Anthony Larcher's avatar
Anthony Larcher committed
534
            <span class="k">while</span> <span class="n">start</span> <span class="o">&lt;</span> <span class="n">l</span> <span class="o">-</span> <span class="n">dec2</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
                <span class="c"># if end &lt; l:</span>
                <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;process part : </span><span class="si">%f</span><span class="s"> </span><span class="si">%f</span><span class="s"> </span><span class="si">%f</span><span class="s">&#39;</span><span class="p">,</span>
                             <span class="n">start</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">,</span>
                             <span class="n">end</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">,</span>
                             <span class="n">l</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">)</span>
                <span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_features_chan</span><span class="p">(</span><span class="n">show</span><span class="p">,</span> <span class="n">channel_ext</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">end</span><span class="p">,</span> <span class="n">chan</span><span class="p">])</span>

                <span class="k">if</span> <span class="n">cep</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">cep</span> <span class="o">=</span> <span class="p">[]</span>
                    <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>
                <span class="n">start</span> <span class="o">=</span> <span class="n">end</span> <span class="o">-</span> <span class="n">dec2</span>
                <span class="n">end</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">end</span> <span class="o">+</span> <span class="n">dec</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
553
554
                <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;!! size of signal cep: </span><span class="si">%f</span><span class="s"> len </span><span class="si">%d</span><span class="s"> type size </span><span class="si">%d</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">cep</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">nbytes</span><span class="o">/</span><span class="mi">1024</span><span class="o">/</span><span class="mi">1024</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cep</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span>
                             <span class="n">cep</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">nbytes</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">cep</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
Anthony Larcher's avatar
Anthony Larcher committed
555
        <span class="k">del</span> <span class="n">x</span>
Anthony Larcher's avatar
Anthony Larcher committed
556
        <span class="c"># Smooth the labels and fuse the channels if more than one.</span>
Anthony Larcher's avatar
Anthony Larcher committed
557
558
        <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;Smooth the labels and fuse the channels if more than one&#39;</span><span class="p">)</span>
        <span class="n">label</span> <span class="o">=</span> <span class="n">label_fusion</span><span class="p">(</span><span class="n">label</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
559
        <span class="bp">self</span><span class="o">.</span><span class="n">_normalize</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">cep</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

        <span class="c"># Keep only the required features and save the appropriate files</span>
        <span class="c"># which are either feature files alone or feature and label files</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</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;no keep all&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">chan</span><span class="p">,</span> <span class="n">chan_ext</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">channel_ext</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="o">=</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="p">[</span><span class="n">chan</span><span class="p">]]</span>
                <span class="n">label</span><span class="p">[</span><span class="n">chan</span><span class="p">]</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="n">label</span><span class="p">[</span><span class="n">chan</span><span class="p">]]</span>

        <span class="k">return</span> <span class="n">cep</span><span class="p">,</span> <span class="n">label</span>

    <span class="k">def</span> <span class="nf">_features_chan</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="n">channel_ext</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;Compelete the overwhole process of extracting the feature frames</span>
<span class="sd">        (LFCC or MFCC) from an audio signal.</span>
<span class="sd">        Speech Activity Detection, MFCC (or LFCC) extraction and normalization.</span>
<span class="sd">        Can include RASTA filtering, Short Term Gaussianization, MVN and delta</span>
<span class="sd">        computation.</span>

<span class="sd">        :param show: name of the file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># Extract cepstral coefficients</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">mfcc</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">fs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">,</span>
                 <span class="n">lowfreq</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">lower_frequency</span><span class="p">,</span>
                 <span class="n">maxfreq</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</span><span class="p">,</span>
                 <span class="n">nlinfilt</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">linear_filters</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
586
                 <span class="n">nwin</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">window_size</span><span class="p">,</span> <span class="n">nlogfilt</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">log_filters</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
587
588
589
590
                 <span class="n">nceps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ceps_number</span><span class="p">,</span> <span class="n">get_spec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">spec</span><span class="p">,</span> 
                 <span class="n">get_mspec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">mspec</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceps_number</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">mspec</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
591
592
            <span class="n">cep</span> <span class="o">=</span> <span class="n">c</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
            <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_vad</span><span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">x</span><span class="p">,</span> <span class="n">channel_ext</span><span class="p">,</span> <span class="n">show</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
593
594
595
596
597
598
            
        <span class="k">else</span><span class="p">:</span>
            <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_vad</span><span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">x</span><span class="p">,</span> <span class="n">channel_ext</span><span class="p">,</span> <span class="n">show</span><span class="p">)</span>
    
            <span class="n">cep</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_log_e</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
            <span class="n">cep</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_rasta</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
599
600
601
602
603
604
605
606
607
608
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span><span class="p">:</span>
                <span class="n">cep</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_delta_and_2delta</span><span class="p">(</span><span class="n">cep</span><span class="p">)</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span><span class="p">:</span>
                <span class="n">cep</span> <span class="o">=</span> <span class="n">pca_dct</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> 
                              <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> 
                              <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span><span class="p">:</span>
                <span class="n">cep</span> <span class="o">=</span> <span class="n">shifted_delta_cepstral</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> 
                                             <span class="n">P</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> 
                                             <span class="n">k</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
Anthony Larcher's avatar
Anthony Larcher committed
609
610
611
612
613
614
615
616
617
618
619
        <span class="k">return</span> <span class="n">cep</span><span class="p">,</span> <span class="n">label</span>

    <span class="k">def</span> <span class="nf">_log_e</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;If required, add the log energy as last coefficient&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_e</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;keep log_e&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">][:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">],</span> <span class="n">c</span><span class="p">[</span><span class="mi">0</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">info</span><span class="p">(</span><span class="s">&#39;don</span><span class="se">\&#39;</span><span class="s">t keep c0&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

Anthony Larcher's avatar
Anthony Larcher committed
620
    <span class="k">def</span> <span class="nf">_vad</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">logEnergy</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">channel_ext</span><span class="p">,</span> <span class="n">show</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Apply Voice Activity Detection.</span>
<span class="sd">        :param x:</span>
<span class="sd">        :param channel:</span>
<span class="sd">        :param window_sample:</span>
<span class="sd">        :param channel_ext:</span>
<span class="sd">        :param show:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <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="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>
            <span class="n">label</span> <span class="o">=</span> <span class="n">vad_snr</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">snr</span><span class="p">,</span> <span class="n">fs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span><span class="p">,</span>
                            <span class="n">shift</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">shift</span><span class="p">,</span> <span class="n">nwin</span><span class="o">=</span><span class="n">window_sample</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;energy&#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 : energy&#39;</span><span class="p">)</span>
            <span class="n">label</span> <span class="o">=</span> <span class="n">vad_energy</span><span class="p">(</span><span class="n">logEnergy</span><span class="p">,</span> <span class="n">distribNb</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                               <span class="n">nbTrainIt</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">flooring</span><span class="o">=</span><span class="mf">0.0001</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
643
                               <span class="n">ceiling</span><span class="o">=</span><span class="mf">1.5</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
644
645
646
        <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;lbl&#39;</span><span class="p">:</span>  <span class="c"># load existing labels as reference</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;vad : lbl&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">ext</span> <span class="ow">in</span> <span class="n">channel_ext</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
647
                <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>
Anthony Larcher's avatar
Anthony Larcher committed
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
                <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="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>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Performs RASTA filtering if required.</span>
<span class="sd">        The two first frames are copied from the third to keep</span>
<span class="sd">        the length consistent</span>
<span class="sd">        !!! if vad is None: label[] is empty</span>

<span class="sd">        :param channel: name of the channel</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">rasta</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;perform RASTA </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span><span class="p">)</span>
            <span class="n">cep</span> <span class="o">=</span> <span class="n">rasta_filt</span><span class="p">(</span><span class="n">cep</span><span class="p">)</span>
            <span class="n">cep</span><span class="p">[:</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">cep</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]</span>
            <span class="n">label</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">label</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
            
        <span class="k">return</span> <span class="n">cep</span><span class="p">,</span> <span class="n">label</span>

    <span class="k">def</span> <span class="nf">_delta_and_2delta</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="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add deltas and double deltas.</span>
Anthony Larcher's avatar
Anthony Larcher committed
674
675
676
<span class="sd">        :param cep: a matrix of cepstral cefficients</span>
<span class="sd">        </span>
<span class="sd">        :return: the cepstral coefficient stacked with deltas and double deltas</span>
Anthony Larcher's avatar
Anthony Larcher committed
677
678
679
680
681
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta</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;add delta&#39;</span><span class="p">)</span>
            <span class="n">delta</span> <span class="o">=</span> <span class="n">compute_delta</span><span class="p">(</span><span class="n">cep</span><span class="p">)</span>
            <span class="n">cep</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">column_stack</span><span class="p">((</span><span class="n">cep</span><span class="p">,</span> <span class="n">delta</span><span class="p">))</span>
Anthony Larcher's avatar
Anthony Larcher committed
682
683
684
685
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</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;add delta delta&#39;</span><span class="p">)</span>
                <span class="n">double_delta</span> <span class="o">=</span> <span class="n">compute_delta</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span>
                <span class="n">cep</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">column_stack</span><span class="p">((</span><span class="n">cep</span><span class="p">,</span> <span class="n">double_delta</span><span class="p">))</span>
Anthony Larcher's avatar
Anthony Larcher committed
686
687
688
689
        <span class="k">return</span> <span class="n">cep</span>

    <span class="k">def</span> <span class="nf">_normalize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">cep</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
690
<span class="sd">        Normalize features in place</span>
Anthony Larcher's avatar
Anthony Larcher committed
691
692
693
694
695
696
697
698

<span class="sd">        :param label:</span>
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># Perform feature normalization on the entire session.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</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 norm&#39;</span><span class="p">)</span>
            <span class="k">pass</span>
Anthony Larcher's avatar
Anthony Larcher committed
699
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s">&#39;cms&#39;</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
700
701
            <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;cms norm&#39;</span><span class="p">)</span>
            <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>
Anthony Larcher's avatar
Anthony Larcher committed
702
                <span class="n">cms</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="p">[</span><span class="n">chan</span><span class="p">])</span>
Anthony Larcher's avatar
Anthony Larcher committed
703
704
705
        <span class="k">elif</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="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;cmvn norm&#39;</span><span class="p">)</span>
            <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>
Anthony Larcher's avatar
Anthony Larcher committed
706
                <span class="n">cmvn</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="p">[</span><span class="n">chan</span><span class="p">])</span>
Anthony Larcher's avatar
Anthony Larcher committed
707
708
709
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s">&#39;stg&#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;stg norm&#39;</span><span class="p">)</span>
            <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>
Anthony Larcher's avatar
Anthony Larcher committed
710
711
712
                <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>
Anthony Larcher's avatar
Anthony Larcher committed
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749

<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>
<span class="sd">        Load a cep from audio or mfcc file. This method loads all channels</span>
<span class="sd">        available in the file.</span>
<span class="sd">        </span>
<span class="sd">        :param show: the name of the show to load</span>
<span class="sd">        </span>
<span class="sd">        :return: the cep array and the label array</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># test if features is already computed</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show</span> <span class="o">==</span> <span class="n">show</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show</span> <span class="o">=</span> <span class="n">show</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span> <span class="o">==</span> <span class="s">&#39;audio&#39;</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;compute MFCC: &#39;</span> <span class="o">+</span> <span class="n">show</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="bp">self</span><span class="o">.</span><span class="n">__repr__</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_features</span><span class="p">(</span><span class="n">show</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span> <span class="o">==</span> <span class="s">&#39;pickle&#39;</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;load pickle: &#39;</span> <span class="o">+</span> <span class="n">show</span><span class="p">)</span>
                <span class="n">input_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">input_dir</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">=</span><span class="n">show</span><span class="p">),</span>
                                              <span class="n">show</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">cep</span> <span class="o">=</span> <span class="p">[</span><span class="n">read_pickle</span><span class="p">(</span><span class="n">input_filename</span><span class="p">)]</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span> <span class="o">==</span> <span class="s">&#39;spro4&#39;</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;load spro4: &#39;</span> <span class="o">+</span> <span class="n">show</span><span class="p">)</span>
                <span class="n">input_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">input_dir</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">=</span><span class="n">show</span><span class="p">),</span>
                                              <span class="n">show</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">cep</span> <span class="o">=</span> <span class="p">[</span><span class="n">read_spro4</span><span class="p">(</span><span class="n">input_filename</span><span class="p">)]</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_file</span> <span class="o">==</span> <span class="s">&#39;htk&#39;</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;load htk: &#39;</span> <span class="o">+</span> <span class="n">show</span><span class="p">)</span>
                <span class="n">input_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">input_dir</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">=</span><span class="n">show</span><span class="p">),</span>
                                              <span class="n">show</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_file_extension</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">cep</span> <span class="o">=</span> <span class="p">[</span><span class="n">read_htk</span><span class="p">(</span><span class="n">input_filename</span><span class="p">)[</span><span class="mi">0</span><span class="p">]]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;unknown from_file value&#39;</span><span class="p">)</span>

Anthony Larcher's avatar
Anthony Larcher committed
750
751
            <span class="c"># Load labels if needed</span>
            <span class="n">input_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="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">=</span><span class="n">show</span><span class="p">),</span> <span class="n">show</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>
Anthony Larcher's avatar
Anthony Larcher committed
752
753
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">input_filename</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="p">[</span><span class="n">read_label</span><span class="p">(</span><span class="n">input_filename</span><span class="p">)]</span>
Anthony Larcher's avatar
Anthony Larcher committed
754
755
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">missing</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">dtype</span><span class="o">=</span><span class="s">&#39;bool&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
756
757
758
759
760
761
                    <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">missing</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="p">[</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="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">filter</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_filter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
Anthony Larcher's avatar
Anthony Larcher committed
762
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
763
764
765
                <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_filter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
766
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;!!! no keep all feature !!!&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
            <span class="k">for</span> <span class="n">chan</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="n">chan</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="n">chan</span><span class="p">][</span><span class="bp">self</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="bp">self</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="o">=</span> <span class="bp">self</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="bp">self</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">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span>
</div>
    <span class="k">def</span> <span class="nf">_filter</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="sd">&quot;&quot;&quot;</span>
<span class="sd">        keep only the MFCC index present in the filter list</span>
<span class="sd">        :param cep:</span>
<span class="sd">        :return: return the list of MFCC given by filter list</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filter</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;filter list is empty&#39;</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;applied filter&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">cep</span><span class="p">[:,</span> <span class="bp">self</span><span class="o">.</span><span class="n">filter</span><span class="p">]</span>

<div class="viewcode-block" id="FeaturesServer.save"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.save">[docs]</a>    <span class="k">def</span> <span class="nf">save</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="n">filename</span><span class="p">,</span> <span class="n">mfcc_format</span><span class="p">,</span> <span class="n">and_label</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Save the cep array in file</span>
<span class="sd">        </span>
<span class="sd">        :param show: the name of the show to save (loaded if need)</span>
<span class="sd">        :param filename: the file name of the mffc file or a list of 2 filenames</span>
<span class="sd">            for the case of double channel files</span>
<span class="sd">        :param mfcc_format: format of the mfcc file taken in values</span>
<span class="sd">            [&#39;pickle&#39;, &#39;spro4&#39;, &#39;htk&#39;]</span>
Anthony Larcher's avatar
Anthony Larcher committed
793
<span class="sd">        :param and_label: boolean, if True save label files</span>
Anthony Larcher's avatar
Anthony Larcher committed
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
<span class="sd">        </span>
<span class="sd">        :raise: Exception if feature format is unknown</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">show</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">root</span><span class="p">,</span> <span class="n">ext</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">splitext</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
            <span class="n">filename</span> <span class="o">=</span> <span class="p">[</span><span class="n">root</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">ext</span><span class="p">,</span> 
                        <span class="n">root</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">double_channel_extension</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">ext</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">mfcc_format</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;pickle&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</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;save pickle format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
                <span class="n">write_pickle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">),</span> <span class="n">filename</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</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;save pickle format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</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;save pickle format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">write_pickle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">),</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>    
                    <span class="n">write_pickle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">),</span> <span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">mfcc_format</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;text&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</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;save text format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
                <span class="n">np</span><span class="o">.</span><span class="n">savetxt</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</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;save text format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</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;save text format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">np</span><span class="o">.</span><span class="n">savetxt</span><span class="p">(</span><span class="n">filename</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>    
                    <span class="n">np</span><span class="o">.</span><span class="n">savetxt</span><span class="p">(</span><span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">mfcc_format</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;spro4&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</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;save spro4 format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
                <span class="n">write_spro4</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">filename</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</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;save spro4 format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</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;save spro4 format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">write_spro4</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">write_spro4</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">mfcc_format</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;htk&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</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;save htk format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
                <span class="n">write_spro4</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</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;save htk format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</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;save htk format: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">write_htk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">filename</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">write_htk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cep</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">filename</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="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;unknown feature format&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
850

Anthony Larcher's avatar
Anthony Larcher committed
851