# HG changeset patch # User Dawn Black # Date 1347264833 -3600 # Node ID a3d62264030cb16b74724fdcd71ba8b597c5e031 # Parent ea0c737c63239e60a183af9de5cae0c2cb25550c tested and working diff -r ea0c737c6323 -r a3d62264030c Code/Collation/get_PRAAT.m --- a/Code/Collation/get_PRAAT.m Thu Jul 26 14:46:25 2012 +0100 +++ b/Code/Collation/get_PRAAT.m Mon Sep 10 09:13:53 2012 +0100 @@ -2,170 +2,74 @@ % this function collates the results of all values calculated using the PRAAT software +% For jitter and shimmer PRAAT returns only a single value, not a +% frame-by-frame calculation. Therefore we cannot find the varience etc. + + % identify the speaker in the stats file fprintf( statsFileID, '%s ', dirName ); % -------------- get the jitter metrics ------------------- % JITTER: ddp \t local \t ppq5 \t rap \t - FileName = [ dirName '_jitter_ddp.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING JITTER DDP METRICS FILE'); - fprintf( statsFileID, '\t ddp missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); + + metricName = '_jitter_ddp'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); - FileName = [ dirName '_jitter_local.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING JITTER LOCAL METRICS FILE'); - fprintf( statsFileID, '\t local missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); - - FileName = [ dirName '_jitter_ppq5.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING JITTER PPQ5 METRICS FILE'); - fprintf( statsFileID, '\t ppq5 missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); - - FileName = [ dirName '_jitter_rap.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING JITTER RAP METRICS FILE'); - fprintf( statsFileID, '\t rap missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); - + metricName = '_jitter_local'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); + + metricName = '_jitter_ppq5'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); + + metricName = '_jitter_rap'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); %-------------- get the shimmer metrics ---------------------- % SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 - FileName = [ dirName '_shimmer_local.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING SHIMMER METRICS FILE'); - fprintf( statsFileID, '\t local missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); + + metricName = '_shimmer_local'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); + + metricName = '_shimmer_dda'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); - FileName = [ dirName '_shimmer_dda.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING SHIMMER METRICS FILE'); - fprintf( statsFileID, '\t dda missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); + metricName = '_shimmer_apq3'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); - FileName = [ dirName '_shimmer_apq3.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING SHIMMER METRICS FILE'); - fprintf( statsFileID, '\t apq3 missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); + metricName = '_shimmer_apq5'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); - FileName = [ dirName '_shimmer_apq5.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING SHIMMER METRICS FILE'); - fprintf( statsFileID, '\t apq5 missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); - - FileName = [ dirName '_shimmer_apq11.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING SHIMMER METRICS FILE'); - fprintf( statsFileID, '\t apq11 missing'); - else - shimmer = fscanf( FileID, '%f', inf ); - fprintf( statsFileID, '\t %f ', shimmer ); - end - fclose(FileID); + metricName = '_shimmer_apq11'; + metricFileName = [ dirName metricName '.txt']; + readValueFromFile( statsFileID, metricFileName, metricName ); %-------------- get the formant metrics ---------------------- +% PRAAT returns a frame-by-frame value + % need to discard all formant information for unvoiced and silent frames. + vuv = detect_VoicedUnvoiced( [dirName '.wav'], 0 ); - % need to discard all formant information for unvoiced frames. + metricName = '_Formant_Burg'; + metricFileName = [ dirName metricName '.txt']; + readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ); - FileName = [ dirName '_Formant.txt']; - FileID = fopen( FileName ); - if( FileID <= 0 ) %does the file exist? - % if not - disp('WARNING: MISSING FORMANT METRICS FILE'); - fprintf( statsFileID, '\t formant missing'); - else - % file format is not straight forward - noOfValues = 0; - formants = []; - while( ~(feof(FileID)) ) - - % search for numberOfFormants - thestr = fgetl(FileID);%, '%s', 1); - - if( strfind( thestr , 'numberOfFormants' ) > 0 ) - noOfValues = noOfValues + 1; - %numberOfFormants found - pos = find( thestr == '=' ); - numberOfFormants = str2num(thestr(pos+2:end)); - formants( noOfValues, 1 ) = numberOfFormants; - % discard the 'formant []' line - thestr = fgetl(FileID); - % now read the formant positions - for (i=0:numberOfFormants-1) - thestr = fgetl(FileID); - pos = find( thestr == '=' ); - formants( noOfValues, i+2 ) = str2num(thestr( pos+2 : end )); - end - - % discard the 'bandwidth []' line - thestr = fgetl(FileID); - % now read the formant bandwidths - for (i=0:numberOfFormants-1) - thestr = fgetl(FileID); - pos = find( thestr == '=' ); - formants( noOfValues, i+2+numberOfFormants ) = str2num(thestr( pos+2 : end )); - end - - end - end - fclose(FileID); - end - + metricName = '_Formant_all'; + metricFileName = [ dirName metricName '.txt']; + readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ); + + metricName = '_Formant_robust'; + metricFileName = [ dirName metricName '.txt']; + readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ); + + + fprintf( statsFileID, '\n'); \ No newline at end of file diff -r ea0c737c6323 -r a3d62264030c Code/Descriptors/Matlab/Common/detect_VoicedUnvoiced.m --- a/Code/Descriptors/Matlab/Common/detect_VoicedUnvoiced.m Thu Jul 26 14:46:25 2012 +0100 +++ b/Code/Descriptors/Matlab/Common/detect_VoicedUnvoiced.m Mon Sep 10 09:13:53 2012 +0100 @@ -1,10 +1,10 @@ -function [vuv] = Detect_VoicedUnvoiced( sampleWavFileName, x, fs, frameLength, noOfFrames ) +function [vuv] = detect_VoicedUnvoiced( sampleWavFileName, OVERWRITE ) sampleFileName = sampleWavFileName( 1 : length( sampleWavFileName ) - 4 ); fileName = [ sampleFileName '_VUV.txt']; fileID = fopen( fileName ); % -if( fileID < 0 ) +if( (fileID < 0) || (OVERWRITE) ) %---------------- GET THE SILENT FRAME VALUES ------------------- % only wish to consider pitch values from voiced frames. @@ -13,6 +13,7 @@ segmentFrames = detect_Silence( sampleFileName, 0 ); % remove the silent frames + [x, fs, frameLength, noOfFrames] = openFile( [ sampleFileName '.wav' ] ); [ silentFrames ] = removeSilentData( segmentFrames, noOfFrames ); % [vuv] = voicingByClustering( nonSilentAudio, fs, noOfFrames, frameLength ); diff -r ea0c737c6323 -r a3d62264030c Code/ProcessDatabase.m --- a/Code/ProcessDatabase.m Thu Jul 26 14:46:25 2012 +0100 +++ b/Code/ProcessDatabase.m Mon Sep 10 09:13:53 2012 +0100 @@ -255,13 +255,25 @@ case 'getPRAAT' % collate all Shimmer values statsFileName = '../../../../../../../TestResults/singingPRAATStats.txt'; - statsFileID = fopen( statsFileName, 'w' ); + % Add a header row if( firstfileOpen == 1 ) + statsFileID = fopen( statsFileName, 'w' ); fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' ); - fprintf( statsFileID, ' name \t JITTER: ddp \t local \t ppq5 \t rap \t SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 \t FORMANTS: number of formants \t positions \t bandwidths \n'); + fprintf( statsFileID, ' name \t JITTER: ddp \t local \t ppq5 \t rap \t SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 \n'); + fprintf( statsFileID, 'For each of the BURG FORMANTS: numberOfFormants \t meanFrequency \t varFrequency \t minFrequency \t maxFrequency \n'); + fprintf( statsFileID, 'meanFrequencyDerivative \t varienceFrequencyDerivative \t minFrequencyDerivative \t max FrequencyDerivative \n'); + fprintf( statsFileID, 'meanFrequency2ndDerivative \t varienceFrequency2ndDerivative \t minFrequency2ndDerivative \t max Frequency2ndDerivative \n'); + fprintf( statsFileID, 'meanBandwidth \t varBandwidth \t minBandwidth \t maxBandwidth \n'); + fprintf( statsFileID, 'meanBandwidthDerivative \t varBandwidthDerivative \t minBandwidthDerivative \t maxBandwidthDerivative \n'); + fprintf( statsFileID, 'meanBandwidth2ndDerivative \t varBandwidth2ndDerivative \t minBandwidth2ndDerivative \t maxBandwidth2ndDerivative \n'); + fprintf( statsFileID, 'For the mean of all three formants: meanFrequency \t varFrequency \t minFrequency \t maxFrequency \n'); + fprintf( statsFileID, 'meanFrequencyDerivative \t varienceFrequencyDerivative \t minFrequencyDerivative \t max FrequencyDerivative \n'); + fprintf( statsFileID, 'meanFrequency2ndDerivative \t varienceFrequency2ndDerivative \t minFrequency2ndDerivative \t max Frequency2ndDerivative \n'); firstfileOpen = 0; - end + else + statsFileID = fopen( statsFileName, 'a' ); + end get_PRAAT( newDirName, statsFileID ); fclose( statsFileID );