Mercurial > hg > emotion-detection-top-level
diff Code/Collation/get_PRAAT.m @ 0:ea0c737c6323
first commit
author | Dawn Black <dawn.black@eecs.qmul.ac.uk> |
---|---|
date | Thu, 26 Jul 2012 14:46:25 +0100 |
parents | |
children | a3d62264030c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Code/Collation/get_PRAAT.m Thu Jul 26 14:46:25 2012 +0100 @@ -0,0 +1,171 @@ +function [] = get_PRAAT( dirName, statsFileID ) + +% this function collates the results of all values calculated using the PRAAT software + + % 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); + + 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); + + + +%-------------- 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); + + 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); + + 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); + + 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); + +%-------------- get the formant metrics ---------------------- + + % need to discard all formant information for unvoiced frames. + + 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 + + + \ No newline at end of file