forked from yueyuzhao/gyrophone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_speaker_features_and_labels.m
43 lines (36 loc) · 1.63 KB
/
get_speaker_features_and_labels.m
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
function [feature_matrix, labels] = ...
get_speaker_features_and_labels(db, field_name)
% Extracts features and labels from all the samples corresponding
% to the specified speakers.
% db - Database of samples generated by gendb()
% speakers - List of speakers for which to extract features
% feature_matrix - Feature matrix for input to Diffusion Maps
% labels - Label for each column of feature_matrix
unique_field_values = get_field(db, field_name);
if (strcmp(field_name, 'digit'))
unique_field_values = cell2mat(unique_field_values);
unique_field_values(:, 2) = '*';
unique_field_values = mat2cell(unique_field_values, ...
ones(size(unique_field_values,1), 1));
unique_field_values = unique(unique_field_values);
end
feature_matrix = [];
labels = [];
total_entries = 0; % counter of handled entries
progressbar;
NUM_OF_UNIQUE_VALUES = length(unique_field_values);
for k = 1:NUM_OF_UNIQUE_VALUES
speaker_db = filterdb(db, field_name, unique_field_values{k});
% extract features for all speaker samples
func = @calc_mfcc;
% func = @calc_stft;
[features, num_of_success] = extract_features(speaker_db, func);
if num_of_success > 0
labels = [labels; ones(num_of_success, 1) * k];
feature_matrix = [feature_matrix features];
total_entries = total_entries + num_of_success;
end
progressbar(k/NUM_OF_UNIQUE_VALUES);
end
fprintf('Handled %d entries\n', total_entries);
end