Dawn@4: function [] = get_AudioPower( dirName, statsFileID ) Dawn@4: Dawn@4: DEBUG=0; Dawn@4: % this function collates the results of all HNR values Dawn@4: Dawn@4: % identify the speaker in the stats file Dawn@4: fprintf( statsFileID, '%s ', dirName ); Dawn@4: Dawn@4: metricName = '_AP'; Dawn@4: metricFileName = [ dirName metricName '.txt']; Dawn@4: [ metrics, nanValues ] = readValuesFromFile( statsFileID, metricFileName, metricName ); Dawn@4: Dawn@4: %---------------- GET THE VOICED FRAME VALUES ------------------- Dawn@4: Dawn@4: % only wish to consider values from voiced frames. Dawn@4: Dawn@4: % going to disregard all unvoiced frames as these produce outliers Dawn@4: [vuv] = detect_VoicedUnvoiced( [ dirName '.wav' ], 0 ); Dawn@4: % if vuv is longer than the pitch array, truncate. Dawn@4: if( length(vuv) ~= length(nanValues) ) Dawn@4: if( (length(vuv) - length(nanValues)) > 1 ) Dawn@4: disp('EEEK!'); Dawn@4: end Dawn@4: if( length(vuv) > length(nanValues) ) Dawn@4: %increase metrics Dawn@4: nanValues = [ nanValues; 0 ]; Dawn@4: else Dawn@4: vuv = [vuv; 0]; Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % % remove any NaN pitch values from the voicing information Dawn@4: % i=1; Dawn@4: % while( i <= length(vuv) ) Dawn@4: % Dawn@4: % if( nanValues(i) == 1 ) Dawn@4: % if( i == 1 ) Dawn@4: % vuv = vuv(2:length(vuv)); Dawn@4: % nanValues = nanValues(2:length(nanValues)); Dawn@4: % elseif(i == length(vuv) ) Dawn@4: % vuv = vuv(1:length(vuv)-1); Dawn@4: % nanValues = nanValues(1:length(nanValues)-1); Dawn@4: % else Dawn@4: % vuv = [ vuv(1: i-1); vuv(i+1:end) ]; Dawn@4: % nanValues = [ nanValues(1: i-1); nanValues(i+1:end) ]; Dawn@4: % end Dawn@4: % else Dawn@4: % i=i+1; Dawn@4: % end Dawn@4: % Dawn@4: % end Dawn@4: Dawn@4: % remove the non-voiced frames (includes unvoiced and silent frames) from the metrics Dawn@4: Dawn@4: voicedFrames = find( vuv == 1 ); Dawn@4: unvoicedFrames = find( vuv == 2 ); Dawn@4: Dawn@4: % find the average energies for voiced and unvoiced speech Dawn@4: voicedEnergy = sum( metrics( voicedFrames )) / length( voicedFrames ); Dawn@4: unvoicedEnergy = sum( metrics( unvoicedFrames )) / length( unvoicedFrames ); Dawn@4: Dawn@4: metrics = metrics( voicedFrames ); Dawn@4: Dawn@4: Dawn@4: if(DEBUG) Dawn@4: subplot(211);hold on; Dawn@4: if( strfind( dirName, 'neg') ) Dawn@4: plot(metrics,'b'); Dawn@4: elseif( strfind( dirName, 'pos') ) Dawn@4: plot(metrics,'r'); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: % get basic metric set Dawn@4: [ metricSet ] = basicMetricSet( metrics, statsFileID ); Dawn@4: Dawn@4: if(DEBUG) Dawn@4: subplot(212); Dawn@4: if( strfind( dirName, 'neg') ) Dawn@4: plot(metrics, 'xb'); hold on; Dawn@4: elseif( strfind( dirName, 'pos') ) Dawn@4: plot(metrics, 'xr'); hold on; Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % get basic metric set for the first derivative Dawn@4: firstDerivative = gradient( metrics ); Dawn@4: [ firstDerivativeMetricSet ] = basicMetricSet( firstDerivative, statsFileID ); Dawn@4: Dawn@4: % print the average voiced and unvoiced energy to file Dawn@4: fprintf( statsFileID, '\t %f \t %f ', voicedEnergy, unvoicedEnergy); Dawn@4: Dawn@4: fprintf( statsFileID, '\n');