-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconvert_ali3.m
125 lines (105 loc) · 4.22 KB
/
convert_ali3.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function convert_ali3(basic_ali,pdf_ali,phone_ali,phone_seq,wavscp,model,phones,transcript,savefile,audiodir)
% Convert alignment data to a mat file.
% If audiodir is given, write wav files there and store the audiodir
% in dat.audiodir, and the wav file names in dat.wav.
% This version assumes alignments have been converted with prepare_ali.sh,
% and so does not run kaldi locally. See load_ali3 for loading.
% Conversion stores information which allows display or markup using a
% token index.
% Default arguments
if nargin < 1
expbase = '/projects/speech/sys/kaldi-trunk/egs/librispeech/s5_word/exp/tri3b_ali_clean_100_CAN';
basic_ali = [expbase '/' 'ali.all.t'];
pdf_ali = [expbase '/' 'pdf_ali'];
phone_ali = [expbase '/' 'phone_ali'];
phone_seq = [expbase '/' 'phone_seq'];
wavscp = '/projects/speech/sys/kaldi-trunk/egs/librispeech/s5_word/data/train_clean_100_V/wav.scp';
model = 0;
phones = '/projects/speech/sys/kaldi-trunk/egs/librispeech/s5_word/data/lang_nosp/phones.txt';
transcript = '/projects/speech/sys/kaldi-trunk/egs/librispeech/s5_word/data/train_clean_100_CAN/text';
savefile = '/Volumes/gray/matlab/matlab-mat/lsCAN2';
audiodir = 0;
end
% Read wav file and alignment for all the utterance IDs.
% Map from uid to wav launch pipes.
% This is not used if audio is not written (audiodir=0).
Scp = load_kaldi_wavscp(wavscp);
% Read transcript.
Tra = load_kaldi_transcript(transcript);
% For mapping back and forth between phones and their indices.
P = PhoneIndexer(phones);
disp(P)
% Load the alignments in various formats.
% Cell array of Uid, and cell array of alignment vectors.
[Uid,Basic,Align_pdf,Align_phone,Phone_seq] = load_ali3(basic_ali,pdf_ali,phone_ali,phone_seq);
dat.scp = Scp; % Map indexed by uid, e.g. dat.scp(dat.uid{10}).
dat.tra = Tra; % Map indexed by uid, e.g. dat.tra(dat.uid{10}).
dat.phone_indexer = P;
dat.uid = Uid; % Cell array indexid by nat, e.g. dat.uid{10} is 10th uid.
dat.basic = Basic; % Cell array indexed by nat, value is a cell vector with char contents.
% It should be a vector of nat.
dat.pdf = Align_pdf;
dat.align_phone = Align_phone;
dat.phone_seq = Phone_seq;
% Number of utterances, indices are [1:N].
[~,N] = size(Uid)
dat.N = N;
% Map from uid to index, used when indexing by token.
dat.um = containers.Map;
for j = [1:N]
uid = Uid{j};
dat.um(uid) = j;
end
if (audiodir ~= 0)
dat.audiodir = audiodir;
Wav = {};
convert_audio(N);
dat.wav = Wav;
end
disp(savefile);
save(savefile, 'dat', '-v7.3');
function convert_audio(n)
for j = 1:n
uid = Uid{j};
scp = Scp(Uid{j});
wav = [audiodir '/' uid '.wav'];
Wav{j} = [uid '.wav'];
cmd = [Scp(uid), ' cat > ' wav];
%disp(j);
%disp(cmd);
%disp(scp);
%disp(wav)
% This somehow fixes flacLIB problem.
setenv('DYLD_LIBRARY_PATH','');
setenv('PATH', '/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin');
system(cmd);
end
end
function convert_korean_audio(n)
for j = 1:n
% ko_4012_100291-100365
uid = Uid{j};
A = strsplit(uid,'_');
wavid = [A(1),'_',A(2)];
% Name of wav file to write
wav = [audiodir '/' uid '.wav'];
Wav{j} = [uid '.wav'];
cmd = [Scp(wavid), ' cat > ' wav];
disp(j);
disp(cmd);
disp(scp);
disp(wav)
% This somehow fixes flacLIB problem.
setenv('DYLD_LIBRARY_PATH','');
setenv('PATH', '/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin');
system(cmd);
end
end
end
% Dependencies
% matlab.codetools.requiredFilesAndProducts('convert_ali.m')
%'/local/matlab/Kaldi-alignments-matlab/convert_ali.m'
%'/local/matlab/Kaldi-alignments-matlab/load_ali2.m'
%'/local/matlab/Kaldi-alignments-matlab/load_kaldi_transcript.m'
%'/local/matlab/Kaldi-alignments-matlab/load_kaldi_wavscp.m'
%'/local/matlab/Kaldi-alignments-matlab/phone_indexer.m'