nkululeko 0.81.4__py3-none-any.whl → 0.81.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,30 @@
1
1
  # estimate.snr
2
- import numpy as np
2
+ """
3
+ Module for estimating SNR (signal to noise ratio) from an audio signal.
4
+
5
+ This module provides a class `SNREstimator` which calculates the SNR based on
6
+ the log energy and energy thresholds of the audio signal.
7
+
8
+ """
9
+
10
+ import argparse
11
+
3
12
  import audiofile
4
13
  import matplotlib.pyplot as plt
14
+ import numpy as np
5
15
  from scipy.signal.windows import hamming
6
- import argparse
7
16
 
8
17
 
9
18
  class SNREstimator:
10
- """Estimate SNR from audio signal using log energy and energy thresholds
19
+ """Estimate SNR from audio signal using log energy and energy thresholds.
20
+
11
21
  Args:
12
22
  input_data (ndarray): Input audio signal
13
23
  sample_rate (int): Sampling rate of input audio signal
14
24
  window_size (int): Window size in samples
15
25
  hop_size (int): Hop size in samples
16
26
 
17
- Returns:
27
+ Returns:
18
28
  object: SNREstimator object
19
29
  estimated_snr (float): Estimated SNR in dB, extracted from SNREstimator.estimate_snr()
20
30
 
@@ -34,7 +44,7 @@ class SNREstimator:
34
44
  num_frames = 1 + (len(signal) - self.frame_length) // self.hop_length
35
45
  frames = [
36
46
  signal[
37
- i * self.hop_length : (i * self.hop_length) + self.frame_length
47
+ i * self.hop_length: (i * self.hop_length) + self.frame_length
38
48
  ]
39
49
  for i in range(num_frames)
40
50
  ]
@@ -54,7 +64,8 @@ class SNREstimator:
54
64
  for frame in frames
55
65
  ]
56
66
 
57
- energy_threshold_low = np.percentile(log_energies, 25) # First quartile
67
+ energy_threshold_low = np.percentile(
68
+ log_energies, 25) # First quartile
58
69
  energy_threshold_high = np.percentile(
59
70
  log_energies, 75
60
71
  ) # Third quartile
nkululeko/constants.py CHANGED
@@ -1,2 +1,2 @@
1
- VERSION="0.81.4"
1
+ VERSION="0.81.6"
2
2
  SAMPLING_RATE = 16000
nkululeko/data/dataset.py CHANGED
@@ -76,6 +76,7 @@ class Dataset:
76
76
  if rename_cols:
77
77
  col_dict = ast.literal_eval(rename_cols)
78
78
  df = df.rename(columns=col_dict)
79
+ self.util.debug(f"renamed data columns: {col_dict}")
79
80
  return df
80
81
 
81
82
  def _report_load(self):
@@ -281,13 +282,19 @@ class Dataset:
281
282
  # try to get the age values
282
283
  df_local["age"] = source_df["age"].astype(int)
283
284
  got_age = True
284
- except (KeyError, ValueError, audformat.errors.BadKeyError) as e:
285
+ except (KeyError, ValueError, audformat.errors.BadKeyError):
285
286
  pass
286
287
  try:
287
288
  # also it might be possible that the sex is part of the speaker description
288
289
  df_local["gender"] = db[table]["speaker"].get(map="gender")
289
290
  got_gender = True
290
- except (ValueError, audformat.errors.BadKeyError) as e:
291
+ except (ValueError, audformat.errors.BadKeyError):
292
+ pass
293
+ try:
294
+ # also it might be possible that the sex is part of the speaker description
295
+ df_local["gender"] = db[table]["speaker"].get(map="sex")
296
+ got_gender = True
297
+ except (ValueError, audformat.errors.BadKeyError):
291
298
  pass
292
299
  try:
293
300
  # also it might be possible that the age is part of the speaker description
nkululeko/demo.py CHANGED
@@ -2,20 +2,35 @@
2
2
  # Demonstration code to use the ML-experiment framework
3
3
  # Test the loading of a previously trained model and demo mode
4
4
  # needs the project config file to run before
5
+ """
6
+ This script is used to test the loading of a previously trained model and run it in demo mode.
7
+ It requires the project config file to be run before.
5
8
 
6
- import os
9
+ Usage:
10
+ python -m nkululeko.demo [--config CONFIG] [--file FILE] [--list LIST] [--folder FOLDER] [--outfile OUTFILE]
11
+
12
+ Options: \n
13
+ --config CONFIG The base configuration file (default: exp.ini) \n
14
+ --file FILE A file that should be processed (16kHz mono wav) \n
15
+ --list LIST A file with a list of files, one per line, that should be processed (16kHz mono wav) \n
16
+ --folder FOLDER A name of a folder where the files within the list are in (default: ./) \n
17
+ --outfile OUTFILE A filename to store the results in CSV (default: None)
18
+ """
7
19
  import argparse
8
20
  import configparser
21
+ import os
9
22
 
23
+ import nkululeko.glob_conf as glob_conf
24
+ from nkululeko.constants import VERSION
10
25
  from nkululeko.experiment import Experiment
11
26
  from nkululeko.utils.util import Util
12
- from nkululeko.constants import VERSION
13
- import nkululeko.glob_conf as glob_conf
14
27
 
15
28
 
16
29
  def main(src_dir):
17
- parser = argparse.ArgumentParser(description="Call the nkululeko framework.")
18
- parser.add_argument("--config", default="exp.ini", help="The base configuration")
30
+ parser = argparse.ArgumentParser(
31
+ description="Call the nkululeko DEMO framework.")
32
+ parser.add_argument("--config", default="exp.ini",
33
+ help="The base configuration")
19
34
  parser.add_argument(
20
35
  "--file", help="A file that should be processed (16kHz mono wav)"
21
36
  )
@@ -1,8 +1,11 @@
1
+ # demo_predictor.py
1
2
  import os
2
- import pandas as pd
3
- import numpy as np
4
- import audiofile
3
+
5
4
  import audformat
5
+ import audiofile
6
+ import numpy as np
7
+ import pandas as pd
8
+
6
9
  import nkululeko.glob_conf as glob_conf
7
10
  from nkululeko.utils.util import Util
8
11
 
nkululeko/experiment.py CHANGED
@@ -695,7 +695,7 @@ class Experiment:
695
695
  pickle.dump(self.__dict__, f)
696
696
  f.close()
697
697
  except TypeError:
698
- self.feature_extractor.featExtractor.model = None
698
+ self.feature_extractor.feat_extractor.model = None
699
699
  f = open(filename, "wb")
700
700
  pickle.dump(self.__dict__, f)
701
701
  f.close()
nkululeko/explore.py CHANGED
@@ -1,17 +1,20 @@
1
1
  # explore.py
2
2
  # explore the feature sets
3
3
 
4
- from nkululeko.experiment import Experiment
5
- import configparser
6
- from nkululeko.utils.util import Util
7
- from nkululeko.constants import VERSION
8
4
  import argparse
5
+ import configparser
9
6
  import os
10
7
 
8
+ from nkululeko.constants import VERSION
9
+ from nkululeko.experiment import Experiment
10
+ from nkululeko.utils.util import Util
11
+
11
12
 
12
13
  def main(src_dir):
13
- parser = argparse.ArgumentParser(description="Call the nkululeko framework.")
14
- parser.add_argument("--config", default="exp.ini", help="The base configuration")
14
+ parser = argparse.ArgumentParser(
15
+ description="Call the nkululeko EXPLORE framework.")
16
+ parser.add_argument("--config", default="exp.ini",
17
+ help="The base configuration")
15
18
  args = parser.parse_args()
16
19
  if args.config is not None:
17
20
  config_file = args.config
@@ -46,9 +49,11 @@ def main(src_dir):
46
49
 
47
50
  # split into train and test
48
51
  expr.fill_train_and_tests()
49
- util.debug(f"train shape : {expr.df_train.shape}, test shape:{expr.df_test.shape}")
52
+ util.debug(
53
+ f"train shape : {expr.df_train.shape}, test shape:{expr.df_test.shape}")
50
54
 
51
- plot_feats = eval(util.config_val("EXPL", "feature_distributions", "False"))
55
+ plot_feats = eval(util.config_val(
56
+ "EXPL", "feature_distributions", "False"))
52
57
  tsne = eval(util.config_val("EXPL", "tsne", "False"))
53
58
  scatter = eval(util.config_val("EXPL", "scatter", "False"))
54
59
  spotlight = eval(util.config_val("EXPL", "spotlight", "False"))
@@ -32,10 +32,7 @@ class AudModelAgenderSet(Featureset):
32
32
  audeer.extract_archive(archive_path, model_root)
33
33
  device = self.util.config_val("MODEL", "device", "cpu")
34
34
  self.model = audonnx.load(model_root, device=device)
35
- pytorch_total_params = sum(p.numel() for p in self.model.parameters())
36
- self.util.debug(
37
- f"initialized agender model with {pytorch_total_params} parameters in total"
38
- )
35
+ self.util.debug(f"initialized agender model")
39
36
  self.model_loaded = True
40
37
 
41
38
  def extract(self):
@@ -13,11 +13,12 @@ from nkululeko.feat_extract.featureset import Featureset
13
13
  import nkululeko.glob_conf as glob_conf
14
14
 
15
15
 
16
- class AudModelDimSet(Featureset):
17
- """
18
- Emotional dimensions from the wav2vec2. based model finetuned on MSPPodcast emotions, described in the paper
16
+ class AuddimSet(Featureset):
17
+ """Emotional dimensions from the wav2vec2 model finetuned on MSPPodcast emotions.
18
+
19
+ Described in the paper
19
20
  "Dawn of the transformer era in speech emotion recognition: closing the valence gap"
20
- https://arxiv.org/abs/2203.07378
21
+ https://arxiv.org/abs/2203.07378.
21
22
  """
22
23
 
23
24
  def __init__(self, name, data_df):
@@ -11,11 +11,12 @@ import torch
11
11
  from nkululeko.feat_extract.featureset import Featureset
12
12
 
13
13
 
14
- class AudModelSet(Featureset):
15
- """
16
- Embeddings from the wav2vec2. based model finetuned on MSPPodcast emotions, described in the paper
14
+ class AudmodelSet(Featureset):
15
+ """Embeddings from the wav2vec2 based model finetuned on MSPPodcast emotions.
16
+
17
+ Described in the paper:
17
18
  "Dawn of the transformer era in speech emotion recognition: closing the valence gap"
18
- https://arxiv.org/abs/2203.07378
19
+ https://arxiv.org/abs/2203.07378.
19
20
  """
20
21
 
21
22
  def __init__(self, name, data_df):
@@ -8,7 +8,7 @@ from nkululeko.utils.util import Util
8
8
  from nkululeko.feat_extract.featureset import Featureset
9
9
 
10
10
 
11
- class Importset(Featureset):
11
+ class ImportSet(Featureset):
12
12
  """Class to import features that have been compiled elsewhere"""
13
13
 
14
14
  def __init__(self, name, data_df):
@@ -10,6 +10,7 @@ pip uninstall -y torch torchvision torchaudio
10
10
  pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
11
11
 
12
12
  """
13
+
13
14
  import os
14
15
  import pandas as pd
15
16
  from tqdm import tqdm
@@ -23,7 +24,7 @@ from nkululeko.utils.util import Util
23
24
  from nkululeko.feat_extract.featureset import Featureset
24
25
 
25
26
 
26
- class MOSSet(Featureset):
27
+ class MosSet(Featureset):
27
28
  """Class to predict MOS (mean opinion score)"""
28
29
 
29
30
  def __init__(self, name, data_df):
@@ -1,17 +1,19 @@
1
1
  # feats_praat.py
2
- from nkululeko.feat_extract.featureset import Featureset
2
+ import ast
3
3
  import os
4
- import pandas as pd
4
+
5
5
  import numpy as np
6
- import nkululeko.glob_conf as glob_conf
6
+ import pandas as pd
7
+
7
8
  from nkululeko.feat_extract import feinberg_praat
8
- import ast
9
+ from nkululeko.feat_extract.featureset import Featureset
10
+ import nkululeko.glob_conf as glob_conf
9
11
 
10
12
 
11
- class Praatset(Featureset):
12
- """
13
- a feature extractor for the Praat software, based on
14
- David R. Feinberg's Praat scripts for the parselmouth python interface.
13
+ class PraatSet(Featureset):
14
+ """A feature extractor for the Praat software.
15
+
16
+ Based on David R. Feinberg's Praat scripts for the parselmouth python interface.
15
17
  https://osf.io/6dwr3/
16
18
 
17
19
  """
@@ -1,14 +1,17 @@
1
- """ feats_snr.py
2
- Estimate snr (signal to noise ratio as acoustic features)
1
+ """ feats_snr.py is to estimate snr.
2
+
3
+ SNR (signal to noise ratio) is extracted as acoustic features.
3
4
  """
4
5
  import os
5
- from tqdm import tqdm
6
- import pandas as pd
6
+
7
7
  import audiofile
8
+ import pandas as pd
9
+ from tqdm import tqdm
10
+
8
11
  import nkululeko.glob_conf as glob_conf
9
- from nkululeko.utils.util import Util
10
- from nkululeko.feat_extract.featureset import Featureset
11
12
  from nkululeko.autopredict.estimate_snr import SNREstimator
13
+ from nkululeko.feat_extract.featureset import Featureset
14
+ from nkululeko.utils.util import Util
12
15
 
13
16
 
14
17
  class SNRSet(Featureset):
@@ -16,14 +19,17 @@ class SNRSet(Featureset):
16
19
 
17
20
  def __init__(self, name, data_df):
18
21
  """Constructor."""
22
+
19
23
  super().__init__(name, data_df)
20
24
 
21
25
  def extract(self):
22
26
  """Estimate the features or load them from disk if present."""
27
+
23
28
  store = self.util.get_path("store")
24
29
  store_format = self.util.config_val("FEATS", "store_format", "pkl")
25
30
  storage = f"{store}{self.name}.{store_format}"
26
- extract = self.util.config_val("FEATS", "needs_feature_extraction", False)
31
+ extract = self.util.config_val(
32
+ "FEATS", "needs_feature_extraction", False)
27
33
  no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
28
34
  if extract or no_reuse or not os.path.isfile(storage):
29
35
  self.util.debug("estimating SNR, this might take a while...")
@@ -40,7 +46,8 @@ class SNRSet(Featureset):
40
46
  snr = self.get_snr(signal[0], sampling_rate)
41
47
  snr_series[idx] = snr
42
48
  print("")
43
- self.df = pd.DataFrame(snr_series.values.tolist(), index=self.data_df.index)
49
+ self.df = pd.DataFrame(
50
+ snr_series.values.tolist(), index=self.data_df.index)
44
51
  self.df.columns = ["snr"]
45
52
  self.util.write_store(self.df, storage, store_format)
46
53
  try:
@@ -53,10 +60,11 @@ class SNRSet(Featureset):
53
60
 
54
61
  def get_snr(self, signal, sampling_rate):
55
62
  r"""Estimate SNR from raw audio signal.
63
+
56
64
  Args:
57
65
  signal: audio signal
58
66
  sampling_rate: sample rate
59
- Returns
67
+ Returns:
60
68
  snr: estimated signal to noise ratio
61
69
  """
62
70
  snr_estimator = SNREstimator(signal, sampling_rate)
@@ -1,36 +1,33 @@
1
- """ feats_squim.py
2
- predict SQUIM ( SPEECH QUALITY AND INTELLIGIBILITY
3
- MEASURES) features
1
+ """Predict SQUIM ( SPEECH QUALITY AND INTELLIGIBILITY MEASURES) features.
4
2
 
5
-
6
- Wideband Perceptual Estimation of Speech Quality (PESQ) [2]
7
- Short-Time Objective Intelligibility (STOI) [3]
8
- Scale-Invariant Signal-to-Distortion Ratio (SI-SDR) [4]
9
-
10
-
11
- adapted from
3
+ Wideband Perceptual Estimation of Speech Quality (PESQ) [2].
4
+ Short-Time Objective Intelligibility (STOI) [3].
5
+ Scale-Invariant Signal-to-Distortion Ratio (SI-SDR) [4].
6
+ Adapted from
12
7
  from https://pytorch.org/audio/main/tutorials/squim_tutorial.html#sphx-glr-tutorials-squim-tutorial-py
13
- paper: https://arxiv.org/pdf/2304.01448.pdf
14
-
15
- needs
8
+ paper: https://arxiv.org/pdf/2304.01448.pdf.
9
+ Needs
16
10
  pip uninstall -y torch torchvision torchaudio
17
11
  pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
18
12
 
19
13
  """
20
14
 
21
15
  import os
22
- from tqdm import tqdm
16
+
23
17
  import pandas as pd
24
18
  import torch
25
19
  import torchaudio
26
20
  from torchaudio.pipelines import SQUIM_OBJECTIVE
21
+ from tqdm import tqdm
22
+
27
23
  import audiofile
24
+
25
+ from nkululeko.feat_extract.featureset import Featureset
28
26
  import nkululeko.glob_conf as glob_conf
29
27
  from nkululeko.utils.util import Util
30
- from nkululeko.feat_extract.featureset import Featureset
31
28
 
32
29
 
33
- class SQUIMSet(Featureset):
30
+ class SquimSet(Featureset):
34
31
  """Class to predict SQUIM features"""
35
32
 
36
33
  def __init__(self, name, data_df):
@@ -1,22 +1,25 @@
1
- """
2
- feature_extractor.py
3
-
4
- Helper class to encapsulate feature extraction methods
1
+ """Extract acoustic features from audio samples.
5
2
 
3
+ Extract acoustic features using several feature extractors
4
+ (appends the features column-wise)
6
5
  """
6
+
7
7
  import pandas as pd
8
8
 
9
9
  from nkululeko.utils.util import Util
10
10
 
11
11
 
12
12
  class FeatureExtractor:
13
- """
14
- Extract acoustic features from audio samples, using several feature extractors (appends the features column-wise)
13
+ """Extract acoustic features from audio samples.
14
+
15
+ Extract acoustic features using several feature extractors (appends the features column-wise).
16
+
15
17
  Args:
16
18
  data_df (pandas.DataFrame): dataframe with audiofile paths as index
17
- feats_types (array of strings): designations of acoustic feature extractors to be used
18
- data_name (string): names of databases that are extracted (for the caching)
19
- feats_designation (string): the type of split (train/test), also is used for the cache name.
19
+ feats_types (List[str]): designations of acoustic feature extractors to be used
20
+ data_name (str): name of databases that are extracted (for caching)
21
+ feats_designation (str): the type of split (train/test), also is used for the cache name.
22
+
20
23
  Returns:
21
24
  df (pandas.DataFrame): dataframe with same index as data_df and acoustic features in columns
22
25
  """
@@ -25,7 +28,6 @@ class FeatureExtractor:
25
28
  df = None
26
29
  data_df = None # dataframe to get audio paths
27
30
 
28
- # def __init__
29
31
  def __init__(self, data_df, feats_types, data_name, feats_designation):
30
32
  self.data_df = data_df
31
33
  self.data_name = data_name
@@ -34,147 +36,69 @@ class FeatureExtractor:
34
36
  self.feats_designation = feats_designation
35
37
 
36
38
  def extract(self):
37
- # feats_types = self.util.config_val_list('FEATS', 'type', ['os'])
38
- self.featExtractor = None
39
39
  self.feats = pd.DataFrame()
40
- _scale = True
41
40
  for feats_type in self.feats_types:
42
41
  store_name = f"{self.data_name}_{feats_type}"
43
- if feats_type == "os":
44
- from nkululeko.feat_extract.feats_opensmile import Opensmileset
45
-
46
- self.featExtractor = Opensmileset(
47
- f"{store_name}_{self.feats_designation}", self.data_df
48
- )
49
- elif feats_type == "spectra":
50
- from nkululeko.feat_extract.feats_spectra import Spectraloader
51
-
52
- self.featExtractor = Spectraloader(
53
- f"{store_name}_{self.feats_designation}", self.data_df
54
- )
55
- elif feats_type == "trill":
56
- from nkululeko.feat_extract.feats_trill import TRILLset
57
-
58
- self.featExtractor = TRILLset(
59
- f"{store_name}_{self.feats_designation}", self.data_df
60
- )
61
- elif feats_type.startswith("wav2vec"):
62
- from nkululeko.feat_extract.feats_wav2vec2 import Wav2vec2
63
-
64
- self.featExtractor = Wav2vec2(
65
- f"{store_name}_{self.feats_designation}",
66
- self.data_df,
67
- feats_type,
68
- )
69
- elif feats_type.startswith("hubert"):
70
- from nkululeko.feat_extract.feats_hubert import Hubert
71
-
72
- self.featExtractor = Hubert(
73
- f"{store_name}_{self.feats_designation}",
74
- self.data_df,
75
- feats_type,
76
- )
77
-
78
- elif feats_type.startswith("wavlm"):
79
- from nkululeko.feat_extract.feats_wavlm import Wavlm
80
-
81
- self.featExtractor = Wavlm(
82
- f"{store_name}_{self.feats_designation}",
83
- self.data_df,
84
- feats_type,
85
- )
86
-
87
- elif feats_type.startswith("spkrec"):
88
- from nkululeko.feat_extract.feats_spkrec import Spkrec
89
-
90
- self.featExtractor = Spkrec(
91
- f"{store_name}_{self.feats_designation}",
92
- self.data_df,
93
- feats_type,
94
- )
95
- elif feats_type == "audmodel":
96
- from nkululeko.feat_extract.feats_audmodel import AudModelSet
97
-
98
- self.featExtractor = AudModelSet(
99
- f"{store_name}_{self.feats_designation}", self.data_df
100
- )
101
- elif feats_type == "auddim":
102
- from nkululeko.feat_extract.feats_audmodel_dim import (
103
- AudModelDimSet,
104
- )
105
-
106
- self.featExtractor = AudModelDimSet(
107
- f"{store_name}_{self.feats_designation}", self.data_df
108
- )
109
- elif feats_type == "agender":
110
- from nkululeko.feat_extract.feats_agender import (
111
- AudModelAgenderSet,
112
- )
113
-
114
- self.featExtractor = AudModelAgenderSet(
115
- f"{store_name}_{self.feats_designation}", self.data_df
116
- )
117
- elif feats_type == "agender_agender":
118
- from nkululeko.feat_extract.feats_agender_agender import (
119
- AgenderAgenderSet,
120
- )
121
-
122
- self.featExtractor = AgenderAgenderSet(
123
- f"{store_name}_{self.feats_designation}", self.data_df
124
- )
125
- elif feats_type == "snr":
126
- from nkululeko.feat_extract.feats_snr import SNRSet
127
-
128
- self.featExtractor = SNRSet(
129
- f"{store_name}_{self.feats_designation}", self.data_df
130
- )
131
- elif feats_type == "mos":
132
- from nkululeko.feat_extract.feats_mos import MOSSet
133
-
134
- self.featExtractor = MOSSet(
135
- f"{store_name}_{self.feats_designation}", self.data_df
136
- )
137
- elif feats_type == "squim":
138
- from nkululeko.feat_extract.feats_squim import SQUIMSet
139
-
140
- self.featExtractor = SQUIMSet(
141
- f"{store_name}_{self.feats_designation}", self.data_df
142
- )
143
- elif feats_type == "clap":
144
- from nkululeko.feat_extract.feats_clap import Clap
145
-
146
- self.featExtractor = Clap(
147
- f"{store_name}_{self.feats_designation}", self.data_df
148
- )
149
- elif feats_type == "praat":
150
- from nkululeko.feat_extract.feats_praat import Praatset
151
-
152
- self.featExtractor = Praatset(
153
- f"{store_name}_{self.feats_designation}", self.data_df
154
- )
155
- elif feats_type == "mld":
156
- from nkululeko.feat_extract.feats_mld import MLD_set
157
-
158
- self.featExtractor = MLD_set(
159
- f"{store_name}_{self.feats_designation}", self.data_df
160
- )
161
- elif feats_type == "import":
162
- from nkululeko.feat_extract.feats_import import Importset
163
-
164
- self.featExtractor = Importset(
165
- f"{store_name}_{self.feats_designation}", self.data_df
166
- )
167
- else:
168
- self.util.error(f"unknown feats_type: {feats_type}")
169
-
170
- self.featExtractor.extract()
171
- self.featExtractor.filter()
172
- # remove samples that were not extracted by MLD
173
- # self.df_test = self.df_test.loc[self.df_test.index.intersection(featExtractor_test.df.index)]
174
- # self.df_train = self.df_train.loc[self.df_train.index.intersection(featExtractor_train.df.index)]
175
- self.util.debug(f"{feats_type}: shape : {self.featExtractor.df.shape}")
176
- self.feats = pd.concat([self.feats, self.featExtractor.df], axis=1)
42
+ self.feat_extractor = self._get_feat_extractor(store_name, feats_type)
43
+ self.feat_extractor.extract()
44
+ self.feat_extractor.filter()
45
+ self.feats = pd.concat([self.feats, self.feat_extractor.df], axis=1)
177
46
  return self.feats
178
47
 
179
48
  def extract_sample(self, signal, sr):
180
- return self.featExtractor.extract_sample(signal, sr)
49
+ return self.feat_extractor.extract_sample(signal, sr)
50
+
51
+ def _get_feat_extractor(self, store_name, feats_type):
52
+ feat_extractor_class = self._get_feat_extractor_class(feats_type)
53
+ if feat_extractor_class is None:
54
+ self.util.error(f"unknown feats_type: {feats_type}")
55
+ return feat_extractor_class(
56
+ f"{store_name}_{self.feats_designation}", self.data_df
57
+ )
58
+
59
+ def _get_feat_extractor_class(self, feats_type):
60
+ if feats_type == "os":
61
+ from nkululeko.feat_extract.feats_opensmile import Opensmileset
62
+
63
+ return Opensmileset
64
+ elif feats_type == "spectra":
65
+ from nkululeko.feat_extract.feats_spectra import Spectraloader
66
+
67
+ return Spectraloader
68
+ elif feats_type == "trill":
69
+ from nkululeko.feat_extract.feats_trill import TRILLset
70
+
71
+ return TRILLset
72
+ elif feats_type.startswith(("wav2vec", "hubert", "wavlm", "spkrec")):
73
+ return self._get_feat_extractor_by_prefix(feats_type)
74
+ elif feats_type in (
75
+ "audmodel",
76
+ "auddim",
77
+ "agender",
78
+ "agender_agender",
79
+ "snr",
80
+ "mos",
81
+ "squim",
82
+ "clap",
83
+ "praat",
84
+ "mld",
85
+ "import",
86
+ ):
87
+ return self._get_feat_extractor_by_name(feats_type)
88
+ else:
89
+ return None
90
+
91
+ def _get_feat_extractor_by_prefix(self, feats_type):
92
+ prefix, _, ext = feats_type.partition("_")
93
+ from importlib import import_module
94
+
95
+ module = import_module(f"nkululeko.feat_extract.feats_{prefix.lower()}")
96
+ class_name = f"{prefix.capitalize()}{ext.capitalize()}set"
97
+ return getattr(module, class_name)
98
+
99
+ def _get_feat_extractor_by_name(self, feats_type):
100
+ from importlib import import_module
101
+
102
+ module = import_module(f"nkululeko.feat_extract.feats_{feats_type.lower()}")
103
+ class_name = f"{feats_type.capitalize()}Set"
104
+ return getattr(module, class_name)