-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPhonemSearch.m
93 lines (84 loc) · 3.32 KB
/
PhonemSearch.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
% function to search for certain phonems
% Usage: [FolderName, FileName, SampleBegin, SampleEnd, Sentence] = ...
% PhonemSearch('iy')
% Input parameter:
% phonem: search for this phonem (write as string)
% Output parameter:
% Phonem_FolderName: all folders phonem can be found in
% Phonem_FileName: all audio files phonem can be found in
% Phonem_SampleBegin: begin of phonem (in samples)
% Phonem_SampleEnd: end of phonem (in samples)
% Phonem_Sentence: sentences where phonem appears
% Output:
% None
% Author: Christoph Eike, Johannes Lühring, Max Zimmermann
% Version History:
% 1.0: first implementation 25.04.2015 CE JL MZ
% 1.01: commentation 28.04.2015 CE JL MZ
% ------------------------------------------------------------------------
function [Phonem_FolderName, Phonem_FileName, Phonem_SampleBegin, ...
Phonem_SampleEnd, Phonem_Sentence] = PhonemSearch(phonem)
Phonem_SampleBegin = [];
Phonem_SampleEnd = [];
Phonem_FileName = [];
Phonem_Sentence = [];
Phonem_FolderName = [];
begin = [];
fin = [];
cd timit/'TIMIT MIT'
y = dir;
folders = [];
for folderidx = 1:length(y)
folders = [folders regexp(y(folderidx).name,'.+-.+','match')];
%save person folders in variable
end
for searchidx=1:length(folders)
cd(char(folders(searchidx)))
x = dir;
names = [];
for nameidx=1:length(x)
names = [names regexp(x(nameidx).name,'.+\.phn','match')];
%get phonem files
end
for fileidx=1:length(names)
fid = fopen(char(names(fileidx)));
data = textscan(fid, '%s %s %[^0123456789]');
%seperate by number(begin in samples), number(end in samples),
%text(phonem)
fclose(fid);
for phnidx=1:length(data{3})
phn = data{3}{phnidx};
if length(phonem) == length(char(phn(1:end-1)))
%phonems can only be compared if same length
if phonem == char(phn(1:end-1))
Phonem_FolderName = [Phonem_FolderName ; ...
folders(searchidx)];
%person
begin = [begin '.' data{1}{phnidx}];
SampleBegin2 = strsplit(begin, '.');
Phonem_SampleBegin = SampleBegin2(2:end)';
%save sample number of begins in one vector
fin = [fin '.' data{2}{phnidx}];
SampleEnd2 = strsplit(fin,'.');
Phonem_SampleEnd = SampleEnd2(2:end)';
%save sample number of ends in one vector
rec = char(names(fileidx));
rec2 = strcat(rec(1:end-3),'wav');
Phonem_FileName = [Phonem_FileName; {rec2}];
%records of person
file = char(names(fileidx));
file = [file(1:end-3) 'txt'];
fid = fopen(file);
SenData = textscan(fid, '%s %s %[^0]');
fclose(fid);
sen = SenData{3}{1};
Phonem_Sentence = [Phonem_Sentence; cellstr(sen)];
%sentences with phonems
end
end
end
end
cd ..
end
cd ../..
end