nkululeko 0.81.4__py3-none-any.whl → 0.81.7__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.
- nkululeko/autopredict/estimate_snr.py +17 -6
- nkululeko/constants.py +1 -1
- nkululeko/data/dataset.py +9 -2
- nkululeko/demo.py +20 -5
- nkululeko/demo_predictor.py +6 -3
- nkululeko/experiment.py +1 -1
- nkululeko/explore.py +13 -8
- nkululeko/feat_extract/feats_agender.py +7 -8
- nkululeko/feat_extract/{feats_audmodel_dim.py → feats_auddim.py} +10 -7
- nkululeko/feat_extract/feats_audmodel.py +10 -7
- nkululeko/feat_extract/feats_clap.py +10 -6
- nkululeko/feat_extract/feats_hubert.py +3 -2
- nkululeko/feat_extract/feats_import.py +3 -3
- nkululeko/feat_extract/feats_mos.py +4 -3
- nkululeko/feat_extract/feats_opensmile.py +10 -24
- nkululeko/feat_extract/feats_oxbow.py +16 -11
- nkululeko/feat_extract/feats_praat.py +18 -13
- nkululeko/feat_extract/feats_snr.py +17 -9
- nkululeko/feat_extract/feats_spectra.py +3 -2
- nkululeko/feat_extract/feats_squim.py +15 -18
- nkululeko/feat_extract/feats_trill.py +10 -6
- nkululeko/feat_extract/feats_wav2vec2.py +16 -7
- nkululeko/feat_extract/feats_wavlm.py +1 -4
- nkululeko/feat_extract/feats_whisper.py +110 -0
- nkululeko/feat_extract/featureset.py +6 -3
- nkululeko/feature_extractor.py +83 -148
- nkululeko/multidb.py +18 -12
- nkululeko/predict.py +26 -8
- nkululeko/reporter.py +332 -0
- nkululeko/resample.py +12 -7
- nkululeko/runmanager.py +17 -8
- nkululeko/test.py +9 -6
- nkululeko/test_predictor.py +1 -0
- nkululeko/utils/stats.py +12 -5
- {nkululeko-0.81.4.dist-info → nkululeko-0.81.7.dist-info}/METADATA +16 -1
- {nkululeko-0.81.4.dist-info → nkululeko-0.81.7.dist-info}/RECORD +39 -37
- {nkululeko-0.81.4.dist-info → nkululeko-0.81.7.dist-info}/LICENSE +0 -0
- {nkululeko-0.81.4.dist-info → nkululeko-0.81.7.dist-info}/WHEEL +0 -0
- {nkululeko-0.81.4.dist-info → nkululeko-0.81.7.dist-info}/top_level.txt +0 -0
@@ -1,20 +1,30 @@
|
|
1
1
|
# estimate.snr
|
2
|
-
|
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
|
-
|
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
|
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(
|
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.
|
1
|
+
VERSION="0.81.7"
|
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)
|
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)
|
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
|
-
|
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(
|
18
|
-
|
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
|
)
|
nkululeko/demo_predictor.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# demo_predictor.py
|
1
2
|
import os
|
2
|
-
|
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.
|
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(
|
14
|
-
|
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(
|
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(
|
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"))
|
@@ -9,16 +9,17 @@ import numpy as np
|
|
9
9
|
import audinterface
|
10
10
|
|
11
11
|
|
12
|
-
class
|
12
|
+
class AgenderSet(Featureset):
|
13
13
|
"""
|
14
14
|
Embeddings from the wav2vec2. based model finetuned on agender data, described in the paper
|
15
15
|
"Speech-based Age and Gender Prediction with Transformers"
|
16
16
|
https://arxiv.org/abs/2306.16962
|
17
17
|
"""
|
18
18
|
|
19
|
-
def __init__(self, name, data_df):
|
20
|
-
super().__init__(name, data_df)
|
19
|
+
def __init__(self, name, data_df, feats_type):
|
20
|
+
super().__init__(name, data_df, feats_type)
|
21
21
|
self.model_loaded = False
|
22
|
+
self.feats_type = feats_type
|
22
23
|
|
23
24
|
def _load_model(self):
|
24
25
|
model_url = "https://zenodo.org/record/7761387/files/w2v2-L-robust-6-age-gender.25c844af-1.1.1.zip"
|
@@ -28,14 +29,12 @@ class AudModelAgenderSet(Featureset):
|
|
28
29
|
if not os.path.isdir(model_root):
|
29
30
|
cache_root = audeer.mkdir("cache")
|
30
31
|
model_root = audeer.mkdir(model_root)
|
31
|
-
archive_path = audeer.download_url(
|
32
|
+
archive_path = audeer.download_url(
|
33
|
+
model_url, cache_root, verbose=True)
|
32
34
|
audeer.extract_archive(archive_path, model_root)
|
33
35
|
device = self.util.config_val("MODEL", "device", "cpu")
|
34
36
|
self.model = audonnx.load(model_root, device=device)
|
35
|
-
|
36
|
-
self.util.debug(
|
37
|
-
f"initialized agender model with {pytorch_total_params} parameters in total"
|
38
|
-
)
|
37
|
+
self.util.debug(f"initialized agender model")
|
39
38
|
self.model_loaded = True
|
40
39
|
|
41
40
|
def extract(self):
|
@@ -13,16 +13,18 @@ from nkululeko.feat_extract.featureset import Featureset
|
|
13
13
|
import nkululeko.glob_conf as glob_conf
|
14
14
|
|
15
15
|
|
16
|
-
class
|
17
|
-
"""
|
18
|
-
|
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
|
-
def __init__(self, name, data_df):
|
24
|
-
super().__init__(name, data_df)
|
24
|
+
def __init__(self, name, data_df, feats_type):
|
25
|
+
super().__init__(name, data_df, feats_type)
|
25
26
|
self.model_loaded = False
|
27
|
+
self.feats_types = feats_type
|
26
28
|
|
27
29
|
def _load_model(self):
|
28
30
|
model_url = "https://zenodo.org/record/6221127/files/w2v2-L-robust-12.6bc4a7fd-1.1.0.zip"
|
@@ -30,7 +32,8 @@ class AudModelDimSet(Featureset):
|
|
30
32
|
if not os.path.isdir(model_root):
|
31
33
|
cache_root = audeer.mkdir("cache")
|
32
34
|
model_root = audeer.mkdir(model_root)
|
33
|
-
archive_path = audeer.download_url(
|
35
|
+
archive_path = audeer.download_url(
|
36
|
+
model_url, cache_root, verbose=True)
|
34
37
|
audeer.extract_archive(archive_path, model_root)
|
35
38
|
cuda = "cuda" if torch.cuda.is_available() else "cpu"
|
36
39
|
device = self.util.config_val("MODEL", "device", cuda)
|
@@ -11,16 +11,18 @@ import torch
|
|
11
11
|
from nkululeko.feat_extract.featureset import Featureset
|
12
12
|
|
13
13
|
|
14
|
-
class
|
15
|
-
"""
|
16
|
-
|
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
|
-
def __init__(self, name, data_df):
|
22
|
-
super().__init__(name, data_df)
|
22
|
+
def __init__(self, name, data_df, feats_type):
|
23
|
+
super().__init__(name, data_df, feats_type)
|
23
24
|
self.model_loaded = False
|
25
|
+
self.feats_type = feats_type
|
24
26
|
|
25
27
|
def _load_model(self):
|
26
28
|
model_url = "https://zenodo.org/record/6221127/files/w2v2-L-robust-12.6bc4a7fd-1.1.0.zip"
|
@@ -28,7 +30,8 @@ class AudModelSet(Featureset):
|
|
28
30
|
if not os.path.isdir(model_root):
|
29
31
|
cache_root = audeer.mkdir("cache")
|
30
32
|
model_root = audeer.mkdir(model_root)
|
31
|
-
archive_path = audeer.download_url(
|
33
|
+
archive_path = audeer.download_url(
|
34
|
+
model_url, cache_root, verbose=True)
|
32
35
|
audeer.extract_archive(archive_path, model_root)
|
33
36
|
cuda = "cuda" if torch.cuda.is_available() else "cpu"
|
34
37
|
device = self.util.config_val("MODEL", "device", cuda)
|
@@ -11,14 +11,15 @@ import laion_clap
|
|
11
11
|
import audiofile
|
12
12
|
|
13
13
|
|
14
|
-
class
|
14
|
+
class ClapSet(Featureset):
|
15
15
|
"""Class to extract laion's clap embeddings (https://github.com/LAION-AI/CLAP)"""
|
16
16
|
|
17
|
-
def __init__(self, name, data_df):
|
17
|
+
def __init__(self, name, data_df, feats_type):
|
18
18
|
"""Constructor. is_train is needed to distinguish from test/dev sets, because they use the codebook from the training"""
|
19
|
-
super().__init__(name, data_df)
|
19
|
+
super().__init__(name, data_df, feats_type)
|
20
20
|
self.device = self.util.config_val("MODEL", "device", "cpu")
|
21
21
|
self.model_initialized = False
|
22
|
+
self.feat_type = feats_type
|
22
23
|
|
23
24
|
def init_model(self):
|
24
25
|
# load model
|
@@ -32,12 +33,14 @@ class Clap(Featureset):
|
|
32
33
|
store = self.util.get_path("store")
|
33
34
|
store_format = self.util.config_val("FEATS", "store_format", "pkl")
|
34
35
|
storage = f"{store}{self.name}.{store_format}"
|
35
|
-
extract = self.util.config_val(
|
36
|
+
extract = self.util.config_val(
|
37
|
+
"FEATS", "needs_feature_extraction", False)
|
36
38
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
37
39
|
if extract or no_reuse or not os.path.isfile(storage):
|
38
40
|
if not self.model_initialized:
|
39
41
|
self.init_model()
|
40
|
-
self.util.debug(
|
42
|
+
self.util.debug(
|
43
|
+
"extracting clap embeddings, this might take a while...")
|
41
44
|
emb_series = pd.Series(index=self.data_df.index, dtype=object)
|
42
45
|
length = len(self.data_df.index)
|
43
46
|
for idx, (file, start, end) in enumerate(
|
@@ -51,7 +54,8 @@ class Clap(Featureset):
|
|
51
54
|
)
|
52
55
|
emb = self.get_embeddings(signal, sampling_rate)
|
53
56
|
emb_series[idx] = emb
|
54
|
-
self.df = pd.DataFrame(
|
57
|
+
self.df = pd.DataFrame(
|
58
|
+
emb_series.values.tolist(), index=self.data_df.index)
|
55
59
|
self.util.write_store(self.df, storage, store_format)
|
56
60
|
try:
|
57
61
|
glob_conf.config["DATA"]["needs_feature_extraction"] = "false"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# feats_hubert.py
|
2
2
|
# HuBERT feature extractor for Nkululeko
|
3
|
-
# example feat_type = "hubert-large-ll60k", "hubert-xlarge-ll60k"
|
3
|
+
# example feat_type = "hubert-large-ll60k", "hubert-xlarge-ll60k",
|
4
|
+
# "hubert-base-ls960", hubert-large-ls960-ft", "hubert-xlarge-ls960-ft"
|
4
5
|
|
5
6
|
|
6
7
|
import os
|
@@ -22,7 +23,7 @@ class Hubert(Featureset):
|
|
22
23
|
def __init__(self, name, data_df, feat_type):
|
23
24
|
"""Constructor. is_train is needed to distinguish from test/dev sets,
|
24
25
|
because they use the codebook from the training"""
|
25
|
-
super().__init__(name, data_df)
|
26
|
+
super().__init__(name, data_df, feat_type)
|
26
27
|
# check if device is not set, use cuda if available
|
27
28
|
cuda = "cuda" if torch.cuda.is_available() else "cpu"
|
28
29
|
self.device = self.util.config_val("MODEL", "device", cuda)
|
@@ -8,11 +8,11 @@ from nkululeko.utils.util import Util
|
|
8
8
|
from nkululeko.feat_extract.featureset import Featureset
|
9
9
|
|
10
10
|
|
11
|
-
class
|
11
|
+
class ImportSet(Featureset):
|
12
12
|
"""Class to import features that have been compiled elsewhere"""
|
13
13
|
|
14
|
-
def __init__(self, name, data_df):
|
15
|
-
super().__init__(name, data_df)
|
14
|
+
def __init__(self, name, data_df, feats_type):
|
15
|
+
super().__init__(name, data_df, feats_type)
|
16
16
|
|
17
17
|
def extract(self):
|
18
18
|
"""Import the features."""
|
@@ -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,12 +24,12 @@ from nkululeko.utils.util import Util
|
|
23
24
|
from nkululeko.feat_extract.featureset import Featureset
|
24
25
|
|
25
26
|
|
26
|
-
class
|
27
|
+
class MosSet(Featureset):
|
27
28
|
"""Class to predict MOS (mean opinion score)"""
|
28
29
|
|
29
|
-
def __init__(self, name, data_df):
|
30
|
+
def __init__(self, name, data_df, feats_type):
|
30
31
|
"""Constructor. is_train is needed to distinguish from test/dev sets, because they use the codebook from the training"""
|
31
|
-
super().__init__(name, data_df)
|
32
|
+
super().__init__(name, data_df, feats_type)
|
32
33
|
self.device = self.util.config_val("MODEL", "device", "cpu")
|
33
34
|
self.model_initialized = False
|
34
35
|
|
@@ -8,31 +8,21 @@ import opensmile
|
|
8
8
|
|
9
9
|
|
10
10
|
class Opensmileset(Featureset):
|
11
|
-
def __init__(self, name, data_df):
|
12
|
-
super().__init__(name, data_df)
|
11
|
+
def __init__(self, name, data_df, feats_type=None, config_file=None):
|
12
|
+
super().__init__(name, data_df, feats_type)
|
13
13
|
self.featset = self.util.config_val("FEATS", "set", "eGeMAPSv02")
|
14
14
|
try:
|
15
15
|
self.feature_set = eval(f"opensmile.FeatureSet.{self.featset}")
|
16
|
-
#'eGeMAPSv02, ComParE_2016, GeMAPSv01a, eGeMAPSv01a':
|
16
|
+
# 'eGeMAPSv02, ComParE_2016, GeMAPSv01a, eGeMAPSv01a':
|
17
17
|
except AttributeError:
|
18
|
-
self.util.error(
|
19
|
-
f"something is wrong with feature set: {self.featset}"
|
20
|
-
)
|
18
|
+
self.util.error(f"something is wrong with feature set: {self.featset}")
|
21
19
|
self.featlevel = self.util.config_val("FEATS", "level", "functionals")
|
22
20
|
try:
|
23
|
-
self.featlevel = self.featlevel.replace(
|
24
|
-
|
25
|
-
)
|
26
|
-
self.featlevel = self.featlevel.replace(
|
27
|
-
"functionals", "Functionals"
|
28
|
-
)
|
29
|
-
self.feature_level = eval(
|
30
|
-
f"opensmile.FeatureLevel.{self.featlevel}"
|
31
|
-
)
|
21
|
+
self.featlevel = self.featlevel.replace("lld", "LowLevelDescriptors")
|
22
|
+
self.featlevel = self.featlevel.replace("functionals", "Functionals")
|
23
|
+
self.feature_level = eval(f"opensmile.FeatureLevel.{self.featlevel}")
|
32
24
|
except AttributeError:
|
33
|
-
self.util.error(
|
34
|
-
f"something is wrong with feature level: {self.featlevel}"
|
35
|
-
)
|
25
|
+
self.util.error(f"something is wrong with feature level: {self.featlevel}")
|
36
26
|
|
37
27
|
def extract(self):
|
38
28
|
"""Extract the features based on the initialized dataset or re-open them when found on disk."""
|
@@ -44,9 +34,7 @@ class Opensmileset(Featureset):
|
|
44
34
|
)
|
45
35
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
46
36
|
if extract or not os.path.isfile(storage) or no_reuse:
|
47
|
-
self.util.debug(
|
48
|
-
"extracting openSmile features, this might take a while..."
|
49
|
-
)
|
37
|
+
self.util.debug("extracting openSmile features, this might take a while...")
|
50
38
|
smile = opensmile.Smile(
|
51
39
|
feature_set=self.feature_set,
|
52
40
|
feature_level=self.feature_level,
|
@@ -85,9 +73,7 @@ class Opensmileset(Featureset):
|
|
85
73
|
selected_features = ast.literal_eval(
|
86
74
|
glob_conf.config["FEATS"]["os.features"]
|
87
75
|
)
|
88
|
-
self.util.debug(
|
89
|
-
f"selecting features from opensmile: {selected_features}"
|
90
|
-
)
|
76
|
+
self.util.debug(f"selecting features from opensmile: {selected_features}")
|
91
77
|
sel_feats_df = pd.DataFrame()
|
92
78
|
hit = False
|
93
79
|
for feat in selected_features:
|
@@ -10,9 +10,10 @@ import opensmile
|
|
10
10
|
class Openxbow(Featureset):
|
11
11
|
"""Class to extract openXBOW processed opensmile features (https://github.com/openXBOW)"""
|
12
12
|
|
13
|
-
def __init__(self, name, data_df, is_train=False):
|
13
|
+
def __init__(self, name, data_df, feats_type, is_train=False):
|
14
14
|
"""Constructor. is_train is needed to distinguish from test/dev sets, because they use the codebook from the training"""
|
15
|
-
super().__init__(name, data_df)
|
15
|
+
super().__init__(name, data_df, feats_type)
|
16
|
+
self.feats_types = feats_type
|
16
17
|
self.is_train = is_train
|
17
18
|
|
18
19
|
def extract(self):
|
@@ -21,11 +22,13 @@ class Openxbow(Featureset):
|
|
21
22
|
self.feature_set = eval(f"opensmile.FeatureSet.{self.featset}")
|
22
23
|
store = self.util.get_path("store")
|
23
24
|
storage = f"{store}{self.name}_{self.featset}.pkl"
|
24
|
-
extract = self.util.config_val(
|
25
|
+
extract = self.util.config_val(
|
26
|
+
"FEATS", "needs_feature_extraction", False)
|
25
27
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
26
28
|
if extract or no_reuse or not os.path.isfile(storage):
|
27
29
|
# extract smile features first
|
28
|
-
self.util.debug(
|
30
|
+
self.util.debug(
|
31
|
+
"extracting openSmile features, this might take a while...")
|
29
32
|
smile = opensmile.Smile(
|
30
33
|
feature_set=self.feature_set,
|
31
34
|
feature_level=opensmile.FeatureLevel.LowLevelDescriptors,
|
@@ -48,7 +51,13 @@ class Openxbow(Featureset):
|
|
48
51
|
# save the smile features
|
49
52
|
smile_df.to_csv(lld_name, sep=";", header=False)
|
50
53
|
# get the path of the xbow java jar file
|
51
|
-
xbow_path = self.util.config_val(
|
54
|
+
xbow_path = self.util.config_val(
|
55
|
+
"FEATS", "xbow.model", "openXBOW")
|
56
|
+
# check if JAR file exist
|
57
|
+
if not os.path.isfile(f"{xbow_path}/openXBOW.jar"):
|
58
|
+
# download using wget if not exist and locate in xbow_path
|
59
|
+
os.system(
|
60
|
+
f"git clone https://github.com/openXBOW/openXBOW")
|
52
61
|
# get the size of the codebook
|
53
62
|
size = self.util.config_val("FEATS", "size", 500)
|
54
63
|
# get the number of assignements
|
@@ -57,16 +66,12 @@ class Openxbow(Featureset):
|
|
57
66
|
if self.is_train:
|
58
67
|
# store the codebook
|
59
68
|
os.system(
|
60
|
-
f"java -jar {xbow_path}openXBOW.jar -i"
|
61
|
-
f" {lld_name} -standardizeInput -log -o"
|
62
|
-
f" {xbow_name} -size {size} -a {assignments} -B"
|
63
|
-
f" {codebook_name}"
|
69
|
+
f"java -jar {xbow_path}/openXBOW.jar -i {lld_name} -standardizeInput -log -o {xbow_name} -size {size} -a {assignments} -B {codebook_name}"
|
64
70
|
)
|
65
71
|
else:
|
66
72
|
# use the codebook
|
67
73
|
os.system(
|
68
|
-
f"java -jar {xbow_path}openXBOW.jar -i {lld_name}
|
69
|
-
f" -o {xbow_name} -b {codebook_name}"
|
74
|
+
f"java -jar {xbow_path}/openXBOW.jar -i {lld_name} -o {xbow_name} -b {codebook_name}"
|
70
75
|
)
|
71
76
|
# read in the result from disk
|
72
77
|
xbow_df = pd.read_csv(xbow_name, sep=";", header=None)
|
@@ -1,33 +1,37 @@
|
|
1
1
|
# feats_praat.py
|
2
|
-
|
2
|
+
import ast
|
3
3
|
import os
|
4
|
-
|
4
|
+
|
5
5
|
import numpy as np
|
6
|
-
import
|
6
|
+
import pandas as pd
|
7
|
+
|
7
8
|
from nkululeko.feat_extract import feinberg_praat
|
8
|
-
import
|
9
|
+
from nkululeko.feat_extract.featureset import Featureset
|
10
|
+
import nkululeko.glob_conf as glob_conf
|
9
11
|
|
10
12
|
|
11
|
-
class
|
12
|
-
"""
|
13
|
-
|
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
|
"""
|
18
20
|
|
19
|
-
def __init__(self, name, data_df):
|
20
|
-
super().__init__(name, data_df)
|
21
|
+
def __init__(self, name, data_df, feats_type):
|
22
|
+
super().__init__(name, data_df, feats_type)
|
21
23
|
|
22
24
|
def extract(self):
|
23
25
|
"""Extract the features based on the initialized dataset or re-open them when found on disk."""
|
24
26
|
store = self.util.get_path("store")
|
25
27
|
store_format = self.util.config_val("FEATS", "store_format", "pkl")
|
26
28
|
storage = f"{store}{self.name}.{store_format}"
|
27
|
-
extract = self.util.config_val(
|
29
|
+
extract = self.util.config_val(
|
30
|
+
"FEATS", "needs_feature_extraction", False)
|
28
31
|
no_reuse = eval(self.util.config_val("FEATS", "no_reuse", "False"))
|
29
32
|
if extract or no_reuse or not os.path.isfile(storage):
|
30
|
-
self.util.debug(
|
33
|
+
self.util.debug(
|
34
|
+
"extracting Praat features, this might take a while...")
|
31
35
|
self.df = feinberg_praat.compute_features(self.data_df.index)
|
32
36
|
self.df = self.df.set_index(self.data_df.index)
|
33
37
|
for i, col in enumerate(self.df.columns):
|
@@ -50,7 +54,8 @@ class Praatset(Featureset):
|
|
50
54
|
self.df = self.df.astype(float)
|
51
55
|
|
52
56
|
def extract_sample(self, signal, sr):
|
53
|
-
import audiofile
|
57
|
+
import audiofile
|
58
|
+
import audformat
|
54
59
|
|
55
60
|
tmp_audio_names = ["praat_audio_tmp.wav"]
|
56
61
|
audiofile.write(tmp_audio_names[0], signal, sr)
|