features_server.html 145 KB
Newer Older
Anthony Larcher's avatar
Anthony Larcher committed
1
2


Anthony Larcher's avatar
warning    
Anthony Larcher committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>features_server &mdash; SIDEKIT 0.1.16 documentation</title>
  

  
  

  

  
  
Anthony Larcher's avatar
Anthony Larcher committed
21
    
Anthony Larcher's avatar
warning    
Anthony Larcher committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="SIDEKIT 0.1.16 documentation" href="../index.html"/>
        <link rel="up" title="Module code" href="index.html"/> 

  
  <script src="_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

Anthony Larcher's avatar
Anthony Larcher committed
45
    
Anthony Larcher's avatar
warning    
Anthony Larcher committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        

        
          <a href="../index.html" class="icon icon-home"> SIDEKIT
        

        
        </a>

        
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

        
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
          
          
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../aboutSIDEKIT.html">About SIDEKIT</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../contact.html">Contact</a></li>
<li class="toctree-l2"><a class="reference internal" href="../license.html">License</a></li>
<li class="toctree-l2"><a class="reference internal" href="../compatibilities.html">Compatibilities</a><ul class="simple">
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../howto.html">How to</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../install.html">Quick installation</a><ul class="simple">
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/shorttuto.html">Enter the SIDEKIT</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/featureExtraction.html">Extract acoustic features</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/ubmTraining.html">Train a Universal Background Model</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/factoranalysis.html">The unified Factor Analyser training</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html">Start with a tutorial</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/RSR2015.html">RSR2015</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../tutorial/rsr2015_init.html">Prepare to run experiments on RSR2015</a></li>
<li class="toctree-l4"><a class="reference internal" href="../tutorial/rsr2015_gmm_ubm.html">Run a GMM-UBM system</a></li>
<li class="toctree-l4"><a class="reference internal" href="../tutorial/rsr2015_svm_gmm.html">Run a SVM-GMM system</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/SRE10.html">NIST-SRE 2010</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../tutorial/sre10_init.html">Prepare to run experiments on NIST-SRE 2010</a></li>
<li class="toctree-l4"><a class="reference internal" href="../tutorial/sre10_iv.html">Run an <cite>i</cite>-vector system</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../sidekit.html">SIDEKIT</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../sidekit_classes.html">Main Classes</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../featuresserver.html">FeaturesServer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mixture.html">Mixture</a></li>
<li class="toctree-l3"><a class="reference internal" href="../statserver.html">StatServer</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../sidekit_modules.html">Additional modules</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../sidekit_io.html">sidekit_io</a></li>
<li class="toctree-l3"><a class="reference internal" href="../iv_scoring.html">iv_scoring</a></li>
<li class="toctree-l3"><a class="reference internal" href="../gmm_scoring.html">gmm_scoring</a></li>
<li class="toctree-l3"><a class="reference internal" href="../sv_utils.html">sv_utils</a></li>
<li class="toctree-l3"><a class="reference internal" href="../svm_training.html">svm_training</a></li>
<li class="toctree-l3"><a class="reference internal" href="../svm_scoring.html">svm_scoring</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../bosaris.html">The <strong>bosaris</strong> package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/license.html">BOSARIS License</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/detplot.html">DetPlot</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/idmap.html">IdMap</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/key.html">Key</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/ndx.html">Ndx</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/plotwindow.html">PlotWindow</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bosaris/scores.html">Scores</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../frontend.html">The <strong>frontend</strong> package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../frontend/features.html">Features</a></li>
<li class="toctree-l3"><a class="reference internal" href="../frontend/io.html">io</a></li>
<li class="toctree-l3"><a class="reference internal" href="../frontend/normfeat.html">Normfeat</a></li>
<li class="toctree-l3"><a class="reference internal" href="../frontend/vad.html">vad</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../libsvm.html">The <strong>libsvm</strong> package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../libsvm/libsvm_core.html">LIBSVM Core library</a><ul class="simple">
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Links.html">External links</a></li>
<li class="toctree-l1"><a class="reference internal" href="../references.html">References</a></li>
<li class="toctree-l1"><a class="reference internal" href="../known_errors.html">Known errors and warnings</a></li>
</ul>

          
        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">SIDEKIT</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
          <li><a href="index.html">Module code</a> &raquo;</li>
      
    <li>features_server</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document">
Anthony Larcher's avatar
Anthony Larcher committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
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
793
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
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
            
  <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>

<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-2015 Anthony Larcher&quot;</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s">&quot;LGPL&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>


<span class="kn">import</span> <span class="nn">logging</span>
<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>
<span class="kn">from</span> <span class="nn">sidekit.sidekit_io</span> <span class="kn">import</span> <span class="n">read_pickle</span><span class="p">,</span> <span class="n">write_pickle</span>
<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>
<span class="kn">import</span> <span class="nn">multiprocessing</span>


<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>

    <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="s">&#39;./&#39;</span><span class="p">,</span>
                 <span class="n">input_file_extension</span><span class="o">=</span><span class="s">&#39;.sph&#39;</span><span class="p">,</span>
                 <span class="n">label_dir</span><span class="o">=</span><span class="s">&#39;./&#39;</span><span class="p">,</span>
                 <span class="n">label_file_extension</span><span class="o">=</span><span class="s">&#39;.lbl&#39;</span><span class="p">,</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">config</span><span class="o">=</span><span class="s">&#39;sid_8k&#39;</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>
                 <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>
                 <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>
                 <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>
    <span class="p">):</span>
        <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>

        <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>
        <span class="bp">self</span><span class="o">.</span><span class="n">snr</span> <span class="o">=</span> <span class="bp">None</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="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="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="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="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="bp">self</span><span class="o">.</span><span class="n">audio_filename</span> <span class="o">=</span> <span class="s">&#39;empty&#39;</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">spec</span> <span class="o">=</span> <span class="bp">False</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="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>

        <span class="c">#self.input_dir = input_dir</span>
        <span class="c">#self.label_dir = label_dir</span>
        <span class="c">#self.label_file_extension = label_file_extension</span>
        <span class="c">#self.input_file_extension = input_file_extension</span>
        <span class="c">#self.from_file = from_file</span>
        <span class="c">#self.audio_filename = &#39;empty&#39;</span>
        <span class="c">#self.filter = None</span>
        <span class="c">#self.spec = False</span>
        <span class="c">#self.vad = None</span>
        <span class="c">#self.feat_norm = None</span>

        <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>
        <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>
        <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">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>
        <span class="k">if</span> <span class="ow">not</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">lower_frequency</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">higher_frequency</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="bp">self</span><span class="o">.</span><span class="n">sampling_frequency</span> <span class="o">/</span> <span class="mf">2.</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>

    <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>
        <span class="k">return</span> <span class="n">ch</span><span class="p">;</span>

    <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>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.0256</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">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>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.0256</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">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>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.0256</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>
        <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_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>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.0256</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>
        <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>
        <span class="bp">self</span><span class="o">.</span><span class="n">window_size</span> <span class="o">=</span> <span class="mf">0.0250</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">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>
        

    <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>
            <span class="k">raise</span> <span class="p">(</span>
            <span class="s">&quot;file rate don&#39;t match the rate of the feature server configuration&quot;</span><span class="p">)</span>
        <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>
        <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>

        <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>
            <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>

        <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>
            <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>
                <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>
                <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>
        <span class="k">del</span> <span class="n">x</span>
       <span class="c"># Smooth the labels and fuse the channels if more than one.</span>
        <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>
        <span class="n">cep</span> <span class="o">=</span> <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>

        <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">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">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>
                 <span class="n">nwin</span><span class="o">=</span><span class="n">window_sample</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>
                 <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>
            <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="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="n">cep</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>
            
        <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>
            <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">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>

    <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>
        <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>
                               <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="mi">2</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;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>
                <span class="n">label_filename</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">label_dir</span><span class="p">,</span> <span class="n">show</span> <span class="o">+</span> <span class="n">ext</span>
                                              <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_file_extension</span><span class="p">)</span>
                <span class="n">label</span> <span class="o">=</span> <span class="n">read_label</span><span class="p">(</span><span class="n">label_filename</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">warrning</span><span class="p">(</span><span class="s">&#39;Wrong VAD type&#39;</span><span class="p">)</span>
        <span class="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>
<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">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>
        <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>
        <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>

<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>
        <span class="k">if</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>
            <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>
                <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">cms</span><span class="p">(</span><span class="n">c</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">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>
                <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">cmvn</span><span class="p">(</span><span class="n">c</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">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>
                <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">stg</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">[</span><span class="n">chan</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">logging</span><span class="o">.</span><span class="n">warrning</span><span class="p">(</span><span class="s">&#39;Wrong feature normalisation type&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">cep</span>

<div class="viewcode-block" id="FeaturesServer.load"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.load">[docs]</a>    <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<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="c"># logging.debug(&#39;get precomputed mfcc: &#39; + show)</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>

            <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>
            <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>
                <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">!=</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="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>
                    <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>
            <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="o">==</span> <span class="mi">2</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="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>
            <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&#39;!!! no keep all feature !!!&#39;</span><span class="p">)</span>
            <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>
<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>
        <span class="k">if</span> <span class="n">and_label</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="p">:</span>
                <span class="n">output_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">splitext</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="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">label_file_extension</span>
                <span class="n">save_label</span><span class="p">(</span><span class="n">output_filename</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="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">output_filename</span> <span class="o">=</span> <span class="p">[</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="mi">0</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_file_extension</span><span class="p">,</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="mi">1</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_file_extension</span><span class="p">]</span>
                <span class="n">save_label</span><span class="p">(</span><span class="n">output_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">label</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">save_label</span><span class="p">(</span><span class="n">output_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">label</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="FeaturesServer.save_list"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.save_list">[docs]</a>    <span class="k">def</span> <span class="nf">save_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">audio_file_list</span><span class="p">,</span> <span class="n">feature_file_list</span><span class="p">,</span> <span class="n">mfcc_format</span><span class="p">,</span> <span class="n">feature_dir</span><span class="p">,</span> 
                  <span class="n">feature_file_extension</span><span class="p">,</span> <span class="n">and_label</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Function that takes a list of audio files and extract features</span>
<span class="sd">        </span>
<span class="sd">        :param audio_file_list: an array of string containing the name of the feature </span>
<span class="sd">            files to load</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">size</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">audio_file</span><span class="p">,</span> <span class="n">feature_file</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">audio_file_list</span><span class="p">,</span> <span class="n">feature_file_list</span><span class="p">):</span>
            <span class="n">cep_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">feature_dir</span><span class="p">,</span> <span class="n">feature_file</span> <span class="o">+</span> 
                <span class="n">feature_file_extension</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;process </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">cep_filename</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">audio_file</span><span class="p">,</span> <span class="n">cep_filename</span><span class="p">,</span> <span class="n">mfcc_format</span><span class="p">,</span> <span class="n">and_label</span><span class="p">)</span>
</div>
    <span class="k">def</span> <span class="nf">dim</span><span class="p">(</span><span class="bp">self</span><span class="p">):</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="s">&#39;empty&#39;</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="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">dim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ceps_number</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">dim</span> <span class="o">+=</span> <span class="mi">1</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">dim</span> <span class="o">*=</span> <span class="mi">2</span>
        <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">dim</span> <span class="o">*=</span> <span class="mi">2</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">&#39;cep dim computed using featureServer parameters&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">dim</span>

<div class="viewcode-block" id="FeaturesServer.save_parallel"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.save_parallel">[docs]</a>    <span class="k">def</span> <span class="nf">save_parallel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">input_audio_list</span><span class="p">,</span> <span class="n">output_feature_list</span><span class="p">,</span> <span class="n">mfcc_format</span><span class="p">,</span> <span class="n">feature_dir</span><span class="p">,</span> 
                         <span class="n">feature_file_extension</span><span class="p">,</span> <span class="n">and_label</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">numThread</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Extract features from audio file using parallel computation</span>
<span class="sd">        </span>
<span class="sd">        :param input_audio_list: an array of string containing the name </span>
<span class="sd">            of the audio files to process</span>
<span class="sd">        :param output_feature_list: an array of string containing the </span>
<span class="sd">            name of the features files to save</span>
<span class="sd">        :param numThread: number of parallel process to run</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># Split the features to process for multi-threading</span>
        <span class="n">loa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array_split</span><span class="p">(</span><span class="n">input_audio_list</span><span class="p">,</span> <span class="n">numThread</span><span class="p">)</span>
        <span class="n">lof</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array_split</span><span class="p">(</span><span class="n">output_feature_list</span><span class="p">,</span> <span class="n">numThread</span><span class="p">)</span>
    
        <span class="n">jobs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">multiprocessing</span><span class="o">.</span><span class="n">freeze_support</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">feat</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">loa</span><span class="p">):</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">Process</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">save_list</span><span class="p">,</span>
                    <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">loa</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> <span class="n">lof</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> <span class="n">mfcc_format</span><span class="p">,</span> <span class="n">feature_dir</span><span class="p">,</span> 
                          <span class="n">feature_file_extension</span><span class="p">,</span> <span class="n">and_label</span><span class="p">))</span>                                       
            <span class="n">jobs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">p</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">jobs</span><span class="p">:</span>
            <span class="n">p</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
</div>
    <span class="k">def</span> <span class="nf">_load_and_stack_worker</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">input</span><span class="p">,</span> <span class="n">output</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Load a list of feature files into a multiprocessing.Queue object</span>
<span class="sd">        </span>
<span class="sd">        :param input: a multiprocessing.JoinableQueue object</span>
<span class="sd">        :param output: a list of multiprocessing.Queue objects to fill</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
            <span class="n">next_task</span> <span class="o">=</span> <span class="nb">input</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
            
            <span class="k">if</span> <span class="n">next_task</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># Poison pill means shutdown</span>
                <span class="n">output</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>
                <span class="nb">input</span><span class="o">.</span><span class="n">task_done</span><span class="p">()</span>
                <span class="k">break</span>
            
            <span class="c">#check which channel to keep from the file</span>
            <span class="k">if</span> <span class="n">next_task</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</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="ow">and</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="s">&#39;audio&#39;</span><span class="p">):</span>
                <span class="n">next_task</span> <span class="o">=</span> <span class="n">next_task</span><span class="p">[:</span><span class="o">-</span><span class="nb">len</span><span class="p">(</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="n">output</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">next_task</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">next_task</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</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="ow">and</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">next_task</span> <span class="o">=</span> <span class="n">next_task</span><span class="p">[:</span><span class="o">-</span><span class="nb">len</span><span class="p">(</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="n">output</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">next_task</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>