Mercurial > hg > emotion-detection-top-level
comparison Code/Collation/get_PRAAT.m @ 1:a3d62264030c
tested and working
author | Dawn Black <dawn.black@eecs.qmul.ac.uk> |
---|---|
date | Mon, 10 Sep 2012 09:13:53 +0100 |
parents | ea0c737c6323 |
children |
comparison
equal
deleted
inserted
replaced
0:ea0c737c6323 | 1:a3d62264030c |
---|---|
1 function [] = get_PRAAT( dirName, statsFileID ) | 1 function [] = get_PRAAT( dirName, statsFileID ) |
2 | 2 |
3 % this function collates the results of all values calculated using the PRAAT software | 3 % this function collates the results of all values calculated using the PRAAT software |
4 | |
5 % For jitter and shimmer PRAAT returns only a single value, not a | |
6 % frame-by-frame calculation. Therefore we cannot find the varience etc. | |
7 | |
4 | 8 |
5 % identify the speaker in the stats file | 9 % identify the speaker in the stats file |
6 fprintf( statsFileID, '%s ', dirName ); | 10 fprintf( statsFileID, '%s ', dirName ); |
7 | 11 |
8 % -------------- get the jitter metrics ------------------- | 12 % -------------- get the jitter metrics ------------------- |
9 % JITTER: ddp \t local \t ppq5 \t rap \t | 13 % JITTER: ddp \t local \t ppq5 \t rap \t |
10 FileName = [ dirName '_jitter_ddp.txt']; | 14 |
11 FileID = fopen( FileName ); | 15 metricName = '_jitter_ddp'; |
12 if( FileID <= 0 ) %does the file exist? | 16 metricFileName = [ dirName metricName '.txt']; |
13 % if not | 17 readValueFromFile( statsFileID, metricFileName, metricName ); |
14 disp('WARNING: MISSING JITTER DDP METRICS FILE'); | |
15 fprintf( statsFileID, '\t ddp missing'); | |
16 else | |
17 shimmer = fscanf( FileID, '%f', inf ); | |
18 fprintf( statsFileID, '\t %f ', shimmer ); | |
19 end | |
20 fclose(FileID); | |
21 | 18 |
22 FileName = [ dirName '_jitter_local.txt']; | 19 metricName = '_jitter_local'; |
23 FileID = fopen( FileName ); | 20 metricFileName = [ dirName metricName '.txt']; |
24 if( FileID <= 0 ) %does the file exist? | 21 readValueFromFile( statsFileID, metricFileName, metricName ); |
25 % if not | 22 |
26 disp('WARNING: MISSING JITTER LOCAL METRICS FILE'); | 23 metricName = '_jitter_ppq5'; |
27 fprintf( statsFileID, '\t local missing'); | 24 metricFileName = [ dirName metricName '.txt']; |
28 else | 25 readValueFromFile( statsFileID, metricFileName, metricName ); |
29 shimmer = fscanf( FileID, '%f', inf ); | 26 |
30 fprintf( statsFileID, '\t %f ', shimmer ); | 27 metricName = '_jitter_rap'; |
31 end | 28 metricFileName = [ dirName metricName '.txt']; |
32 fclose(FileID); | 29 readValueFromFile( statsFileID, metricFileName, metricName ); |
33 | |
34 FileName = [ dirName '_jitter_ppq5.txt']; | |
35 FileID = fopen( FileName ); | |
36 if( FileID <= 0 ) %does the file exist? | |
37 % if not | |
38 disp('WARNING: MISSING JITTER PPQ5 METRICS FILE'); | |
39 fprintf( statsFileID, '\t ppq5 missing'); | |
40 else | |
41 shimmer = fscanf( FileID, '%f', inf ); | |
42 fprintf( statsFileID, '\t %f ', shimmer ); | |
43 end | |
44 fclose(FileID); | |
45 | |
46 FileName = [ dirName '_jitter_rap.txt']; | |
47 FileID = fopen( FileName ); | |
48 if( FileID <= 0 ) %does the file exist? | |
49 % if not | |
50 disp('WARNING: MISSING JITTER RAP METRICS FILE'); | |
51 fprintf( statsFileID, '\t rap missing'); | |
52 else | |
53 shimmer = fscanf( FileID, '%f', inf ); | |
54 fprintf( statsFileID, '\t %f ', shimmer ); | |
55 end | |
56 fclose(FileID); | |
57 | |
58 | 30 |
59 | 31 |
60 %-------------- get the shimmer metrics ---------------------- | 32 %-------------- get the shimmer metrics ---------------------- |
61 % SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 | 33 % SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 |
62 FileName = [ dirName '_shimmer_local.txt']; | 34 |
63 FileID = fopen( FileName ); | 35 metricName = '_shimmer_local'; |
64 if( FileID <= 0 ) %does the file exist? | 36 metricFileName = [ dirName metricName '.txt']; |
65 % if not | 37 readValueFromFile( statsFileID, metricFileName, metricName ); |
66 disp('WARNING: MISSING SHIMMER METRICS FILE'); | 38 |
67 fprintf( statsFileID, '\t local missing'); | 39 metricName = '_shimmer_dda'; |
68 else | 40 metricFileName = [ dirName metricName '.txt']; |
69 shimmer = fscanf( FileID, '%f', inf ); | 41 readValueFromFile( statsFileID, metricFileName, metricName ); |
70 fprintf( statsFileID, '\t %f ', shimmer ); | |
71 end | |
72 fclose(FileID); | |
73 | 42 |
74 FileName = [ dirName '_shimmer_dda.txt']; | 43 metricName = '_shimmer_apq3'; |
75 FileID = fopen( FileName ); | 44 metricFileName = [ dirName metricName '.txt']; |
76 if( FileID <= 0 ) %does the file exist? | 45 readValueFromFile( statsFileID, metricFileName, metricName ); |
77 % if not | |
78 disp('WARNING: MISSING SHIMMER METRICS FILE'); | |
79 fprintf( statsFileID, '\t dda missing'); | |
80 else | |
81 shimmer = fscanf( FileID, '%f', inf ); | |
82 fprintf( statsFileID, '\t %f ', shimmer ); | |
83 end | |
84 fclose(FileID); | |
85 | 46 |
86 FileName = [ dirName '_shimmer_apq3.txt']; | 47 metricName = '_shimmer_apq5'; |
87 FileID = fopen( FileName ); | 48 metricFileName = [ dirName metricName '.txt']; |
88 if( FileID <= 0 ) %does the file exist? | 49 readValueFromFile( statsFileID, metricFileName, metricName ); |
89 % if not | |
90 disp('WARNING: MISSING SHIMMER METRICS FILE'); | |
91 fprintf( statsFileID, '\t apq3 missing'); | |
92 else | |
93 shimmer = fscanf( FileID, '%f', inf ); | |
94 fprintf( statsFileID, '\t %f ', shimmer ); | |
95 end | |
96 fclose(FileID); | |
97 | 50 |
98 FileName = [ dirName '_shimmer_apq5.txt']; | 51 metricName = '_shimmer_apq11'; |
99 FileID = fopen( FileName ); | 52 metricFileName = [ dirName metricName '.txt']; |
100 if( FileID <= 0 ) %does the file exist? | 53 readValueFromFile( statsFileID, metricFileName, metricName ); |
101 % if not | |
102 disp('WARNING: MISSING SHIMMER METRICS FILE'); | |
103 fprintf( statsFileID, '\t apq5 missing'); | |
104 else | |
105 shimmer = fscanf( FileID, '%f', inf ); | |
106 fprintf( statsFileID, '\t %f ', shimmer ); | |
107 end | |
108 fclose(FileID); | |
109 | |
110 FileName = [ dirName '_shimmer_apq11.txt']; | |
111 FileID = fopen( FileName ); | |
112 if( FileID <= 0 ) %does the file exist? | |
113 % if not | |
114 disp('WARNING: MISSING SHIMMER METRICS FILE'); | |
115 fprintf( statsFileID, '\t apq11 missing'); | |
116 else | |
117 shimmer = fscanf( FileID, '%f', inf ); | |
118 fprintf( statsFileID, '\t %f ', shimmer ); | |
119 end | |
120 fclose(FileID); | |
121 | 54 |
122 %-------------- get the formant metrics ---------------------- | 55 %-------------- get the formant metrics ---------------------- |
56 % PRAAT returns a frame-by-frame value | |
57 % need to discard all formant information for unvoiced and silent frames. | |
58 vuv = detect_VoicedUnvoiced( [dirName '.wav'], 0 ); | |
123 | 59 |
124 % need to discard all formant information for unvoiced frames. | 60 metricName = '_Formant_Burg'; |
61 metricFileName = [ dirName metricName '.txt']; | |
62 readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ); | |
125 | 63 |
126 FileName = [ dirName '_Formant.txt']; | 64 metricName = '_Formant_all'; |
127 FileID = fopen( FileName ); | 65 metricFileName = [ dirName metricName '.txt']; |
128 if( FileID <= 0 ) %does the file exist? | 66 readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ); |
129 % if not | 67 |
130 disp('WARNING: MISSING FORMANT METRICS FILE'); | 68 metricName = '_Formant_robust'; |
131 fprintf( statsFileID, '\t formant missing'); | 69 metricFileName = [ dirName metricName '.txt']; |
132 else | 70 readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ); |
133 % file format is not straight forward | |
134 noOfValues = 0; | |
135 formants = []; | |
136 while( ~(feof(FileID)) ) | |
137 | |
138 % search for numberOfFormants | |
139 thestr = fgetl(FileID);%, '%s', 1); | |
140 | |
141 if( strfind( thestr , 'numberOfFormants' ) > 0 ) | |
142 noOfValues = noOfValues + 1; | |
143 %numberOfFormants found | |
144 pos = find( thestr == '=' ); | |
145 numberOfFormants = str2num(thestr(pos+2:end)); | |
146 formants( noOfValues, 1 ) = numberOfFormants; | |
147 % discard the 'formant []' line | |
148 thestr = fgetl(FileID); | |
149 % now read the formant positions | |
150 for (i=0:numberOfFormants-1) | |
151 thestr = fgetl(FileID); | |
152 pos = find( thestr == '=' ); | |
153 formants( noOfValues, i+2 ) = str2num(thestr( pos+2 : end )); | |
154 end | |
155 | |
156 % discard the 'bandwidth []' line | |
157 thestr = fgetl(FileID); | |
158 % now read the formant bandwidths | |
159 for (i=0:numberOfFormants-1) | |
160 thestr = fgetl(FileID); | |
161 pos = find( thestr == '=' ); | |
162 formants( noOfValues, i+2+numberOfFormants ) = str2num(thestr( pos+2 : end )); | |
163 end | |
164 | |
165 end | |
166 end | |
167 fclose(FileID); | |
168 end | |
169 | |
170 | 71 |
171 | 72 |
73 fprintf( statsFileID, '\n'); | |
74 | |
75 |