Dawn@4
|
1 function [] = get_AudioPower( dirName, statsFileID )
|
Dawn@4
|
2
|
Dawn@4
|
3 DEBUG=0;
|
Dawn@4
|
4 % this function collates the results of all HNR values
|
Dawn@4
|
5
|
Dawn@4
|
6 % identify the speaker in the stats file
|
Dawn@4
|
7 fprintf( statsFileID, '%s ', dirName );
|
Dawn@4
|
8
|
Dawn@4
|
9 metricName = '_AP';
|
Dawn@4
|
10 metricFileName = [ dirName metricName '.txt'];
|
Dawn@4
|
11 [ metrics, nanValues ] = readValuesFromFile( statsFileID, metricFileName, metricName );
|
Dawn@4
|
12
|
Dawn@4
|
13 %---------------- GET THE VOICED FRAME VALUES -------------------
|
Dawn@4
|
14
|
Dawn@4
|
15 % only wish to consider values from voiced frames.
|
Dawn@4
|
16
|
Dawn@4
|
17 % going to disregard all unvoiced frames as these produce outliers
|
Dawn@4
|
18 [vuv] = detect_VoicedUnvoiced( [ dirName '.wav' ], 0 );
|
Dawn@4
|
19 % if vuv is longer than the pitch array, truncate.
|
Dawn@4
|
20 if( length(vuv) ~= length(nanValues) )
|
Dawn@4
|
21 if( (length(vuv) - length(nanValues)) > 1 )
|
Dawn@4
|
22 disp('EEEK!');
|
Dawn@4
|
23 end
|
Dawn@4
|
24 if( length(vuv) > length(nanValues) )
|
Dawn@4
|
25 %increase metrics
|
Dawn@4
|
26 nanValues = [ nanValues; 0 ];
|
Dawn@4
|
27 else
|
Dawn@4
|
28 vuv = [vuv; 0];
|
Dawn@4
|
29 end
|
Dawn@4
|
30 end
|
Dawn@4
|
31
|
Dawn@4
|
32
|
Dawn@4
|
33 % % remove any NaN pitch values from the voicing information
|
Dawn@4
|
34 % i=1;
|
Dawn@4
|
35 % while( i <= length(vuv) )
|
Dawn@4
|
36 %
|
Dawn@4
|
37 % if( nanValues(i) == 1 )
|
Dawn@4
|
38 % if( i == 1 )
|
Dawn@4
|
39 % vuv = vuv(2:length(vuv));
|
Dawn@4
|
40 % nanValues = nanValues(2:length(nanValues));
|
Dawn@4
|
41 % elseif(i == length(vuv) )
|
Dawn@4
|
42 % vuv = vuv(1:length(vuv)-1);
|
Dawn@4
|
43 % nanValues = nanValues(1:length(nanValues)-1);
|
Dawn@4
|
44 % else
|
Dawn@4
|
45 % vuv = [ vuv(1: i-1); vuv(i+1:end) ];
|
Dawn@4
|
46 % nanValues = [ nanValues(1: i-1); nanValues(i+1:end) ];
|
Dawn@4
|
47 % end
|
Dawn@4
|
48 % else
|
Dawn@4
|
49 % i=i+1;
|
Dawn@4
|
50 % end
|
Dawn@4
|
51 %
|
Dawn@4
|
52 % end
|
Dawn@4
|
53
|
Dawn@4
|
54 % remove the non-voiced frames (includes unvoiced and silent frames) from the metrics
|
Dawn@4
|
55
|
Dawn@4
|
56 voicedFrames = find( vuv == 1 );
|
Dawn@4
|
57 unvoicedFrames = find( vuv == 2 );
|
Dawn@4
|
58
|
Dawn@4
|
59 % find the average energies for voiced and unvoiced speech
|
Dawn@4
|
60 voicedEnergy = sum( metrics( voicedFrames )) / length( voicedFrames );
|
Dawn@4
|
61 unvoicedEnergy = sum( metrics( unvoicedFrames )) / length( unvoicedFrames );
|
Dawn@4
|
62
|
Dawn@4
|
63 metrics = metrics( voicedFrames );
|
Dawn@4
|
64
|
Dawn@4
|
65
|
Dawn@4
|
66 if(DEBUG)
|
Dawn@4
|
67 subplot(211);hold on;
|
Dawn@4
|
68 if( strfind( dirName, 'neg') )
|
Dawn@4
|
69 plot(metrics,'b');
|
Dawn@4
|
70 elseif( strfind( dirName, 'pos') )
|
Dawn@4
|
71 plot(metrics,'r');
|
Dawn@4
|
72 end
|
Dawn@4
|
73 end
|
Dawn@4
|
74
|
Dawn@4
|
75 % get basic metric set
|
Dawn@4
|
76 [ metricSet ] = basicMetricSet( metrics, statsFileID );
|
Dawn@4
|
77
|
Dawn@4
|
78 if(DEBUG)
|
Dawn@4
|
79 subplot(212);
|
Dawn@4
|
80 if( strfind( dirName, 'neg') )
|
Dawn@4
|
81 plot(metrics, 'xb'); hold on;
|
Dawn@4
|
82 elseif( strfind( dirName, 'pos') )
|
Dawn@4
|
83 plot(metrics, 'xr'); hold on;
|
Dawn@4
|
84 end
|
Dawn@4
|
85 end
|
Dawn@4
|
86
|
Dawn@4
|
87
|
Dawn@4
|
88 % get basic metric set for the first derivative
|
Dawn@4
|
89 firstDerivative = gradient( metrics );
|
Dawn@4
|
90 [ firstDerivativeMetricSet ] = basicMetricSet( firstDerivative, statsFileID );
|
Dawn@4
|
91
|
Dawn@4
|
92 % print the average voiced and unvoiced energy to file
|
Dawn@4
|
93 fprintf( statsFileID, '\t %f \t %f ', voicedEnergy, unvoicedEnergy);
|
Dawn@4
|
94
|
Dawn@4
|
95 fprintf( statsFileID, '\n'); |