forked from yzyouzhang/AIR-ASVspoof
-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_LA_data.m
96 lines (80 loc) · 3.87 KB
/
process_LA_data.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
44
45
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
clear; close all; clc;
% This code is modified from the baseline system for ASVspoof 2019
% add required libraries to the path
addpath(genpath('LFCC'));
addpath(genpath('CQCC_v1.0'));
% set here the experiment to run (access and feature type)
access_type = 'LA';
feature_type = 'LFCC';
% set paths to the audio files database and protocols
pathToASVspoof2019Data = 'D:\Users\Suchit\Desktop\Acad\EED 305 Digital Signal Processing\DSP Project\DS_10283_3336';
%path to DS_10283_3336 folder.
pathToFeatures = horzcat('D:\Users\Suchit\Desktop\Acad\EED 305 Digital Signal Processing\DSP Project\DS_10283_3336\anti-spoofing\ASVspoof2019\', access_type, '\Features\');
%path to the folder where you want mat file(.m) outputs.
pathToDatabase = fullfile(pathToASVspoof2019Data, access_type);
trainProtocolFile = fullfile(pathToDatabase, horzcat('ASVspoof2019_', access_type, '_cm_protocols'), horzcat('ASVspoof2019.', access_type, '.cm.train.trn.txt'));
devProtocolFile = fullfile(pathToDatabase, horzcat('ASVspoof2019_', access_type, '_cm_protocols'), horzcat('ASVspoof2019.', access_type, '.cm.dev.trl.txt'));
evalProtocolFile = fullfile(pathToDatabase, horzcat('ASVspoof2019_', access_type, '_cm_protocols'), horzcat('ASVspoof2019.', access_type, '.cm.eval.trl.txt'));
% read train protocol
trainfileID = fopen(trainProtocolFile);
trainprotocol = textscan(trainfileID, '%s%s%s%s%s');
fclose(trainfileID);
trainfilelist = trainprotocol{2};
% read dev protocol
devfileID = fopen(devProtocolFile);
devprotocol = textscan(devfileID, '%s%s%s%s%s');
fclose(devfileID);
devfilelist = devprotocol{2};
% read eval protocol
evalfileID = fopen(evalProtocolFile);
evalprotocol = textscan(evalfileID, '%s%s%s%s%s');
fclose(evalfileID);
evalfilelist = evalprotocol{2};
%% Feature extraction for training data
% extract features for training data and store them
disp('Extracting features for training data...');
trainFeatureCell = cell(length(trainfilelist), 3);
for i=1:length(trainfilelist)
filePath = fullfile(pathToDatabase,['ASVspoof2019_' access_type '_train\flac'],[trainfilelist{i} '.flac']);
[x,fs] = audioread(filePath);
[stat,delta,double_delta] = extract_lfcc(x,fs,20,512,20);
LFCC = [stat delta double_delta]';
filename_LFCC = fullfile(pathToFeatures, 'train', horzcat('LFCC_', trainfilelist{i}, '.mat'));
disp(trainfilelist{i});
parsave(filename_LFCC, LFCC)
LFCC = [];
end
disp('Extracted features for train data!');
%% Feature extraction for development data
% extract features for development data and store them
disp('Extracting features for development data...');
for i=1:length(devfilelist)
filePath = fullfile(pathToDatabase,['ASVspoof2019_' access_type '_dev\flac'],[devfilelist{i} '.flac']);
[x,fs] = audioread(filePath);
[stat,delta,double_delta] = extract_lfcc(x,fs,20,512,20);
LFCC = [stat delta double_delta]';
filename_LFCC = fullfile(pathToFeatures, 'dev', horzcat('LFCC_', devfilelist{i}, '.mat'));
disp(trainfilelist{i});
parsave(filename_LFCC, LFCC)
LFCC = [];
end
disp('Extracted features for development data!');
%% Feature extraction for evaluation data
% extract features for evaluation data and store them
disp('Extracting features for evaluation data...');
for i=1:length(evalfilelist)
filePath = fullfile(pathToDatabase,['ASVspoof2019_' access_type '_eval\flac'],[evalfilelist{i} '.flac']);
[x,fs] = audioread(filePath);
[stat,delta,double_delta] = extract_lfcc(x,fs,20,512,20);
LFCC = [stat delta double_delta]';
filename_LFCC = fullfile(pathToFeatures, 'eval', horzcat('LFCC_', evalfilelist{i}, '.mat'));
disp(trainfilelist{i});
parsave(filename_LFCC, LFCC)
LFCC = [];
end
disp('Extracted features for evaluation data!');
%% supplementary function
function parsave(fname, x)
save(fname, 'x')
end
disp('Completed processing data!');