-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaux_functions.py
54 lines (42 loc) · 1.69 KB
/
aux_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from pathlib import Path
import pandas as pd
from sklearn.externals import joblib
from sklearn.preprocessing import StandardScaler
import numpy as np
def save_scaled_scaler():
# latest csv path
for mfcc_size in [12,15,20]:
csv_path = f'csv/whisper/data_experiment_2_mfcc_{mfcc_size}.csv'
data_csv = pd.read_csv(csv_path)
data_no_fileName = data_csv.drop(['filename'], axis=1)
only_features = np.array(data_no_fileName.iloc[:, :-1], dtype=float)
scaler = StandardScaler()
scaler.fit(only_features)
scaler_filenPath = f'saved_scalers/scaler_mfcc_{mfcc_size}.save'
joblib.dump(scaler, scaler_filenPath)
def load_scaler_and_test():
for mfcc_size in [12,15,20]:
csv_path = f'csv/whisper/data_experiment_2_mfcc_{mfcc_size}.csv'
scaler_filenPath = f'saved_scalers/scaler_mfcc_{mfcc_size}.save'
scaler = joblib.load(scaler_filenPath)
# load csv
data_csv = pd.read_csv(csv_path)
data_no_fileName = data_csv.drop(['filename'], axis=1)
only_features = np.array(data_no_fileName.iloc[:, :-1], dtype=float)
print(only_features[0,:])
print("and now scaled: ")
scaled = scaler.transform(only_features)
print(scaled[0, :])
def test_sort():
path_test = Path("examined_files")
wave_file_paths = sorted(path_test.glob('**/*.wav')) # <class 'generator'>
to_sort = []
for file in wave_file_paths:
print(file)
to_sort.append(str(file))
print("now sorted:")
print(sorted(to_sort,key=len))
if __name__ == "__main__":
# save_scaled_scaler()
#load_scaler_and_test()
test_sort()