Home > data-import > import_speech_toy.m

import_speech_toy

PURPOSE ^

translate a speech transcription into two matlab-based formats

SYNOPSIS ^

function [speech] = import_speech_toy(date_or_sid,kid)

DESCRIPTION ^

 translate a speech transcription into two matlab-based formats
   import_speech(DATE, KID_ID)
       Import the speech transcription found in the directory of the
       experiment with the given KID on the given DATE.  The DATE is given
       in the usual format: a number like 20080424, YYYYMMDD.

   import_speech(SUBJECT_ID)
       Import the speech transcription found in the given subject's
       directory.

   This function generates two files, the object naming event file used by
   the visualization program (cevent_naming_event.mat), and a
   speech_transcription file (speech_trans.mat) which is more useful to
   MATLAB users.  Both are generated in the derived/ subdirectory of the
   subject dir.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [speech] = import_speech_toy(date_or_sid,kid)
0002 % translate a speech transcription into two matlab-based formats
0003 %   import_speech(DATE, KID_ID)
0004 %       Import the speech transcription found in the directory of the
0005 %       experiment with the given KID on the given DATE.  The DATE is given
0006 %       in the usual format: a number like 20080424, YYYYMMDD.
0007 %
0008 %   import_speech(SUBJECT_ID)
0009 %       Import the speech transcription found in the given subject's
0010 %       directory.
0011 %
0012 %   This function generates two files, the object naming event file used by
0013 %   the visualization program (cevent_naming_event.mat), and a
0014 %   speech_transcription file (speech_trans.mat) which is more useful to
0015 %   MATLAB users.  Both are generated in the derived/ subdirectory of the
0016 %   subject dir.
0017 
0018 
0019 if nargin == 1
0020     % the arg is just the subject ID.
0021     sid = date_or_sid;
0022     info = get_subject_info(sid);
0023     kid = info(4);
0024 elseif nargin == 2
0025     % find the subject id based on data and kid id
0026     subjects = read_subject_table(); 
0027     index = intersect(find((subjects(:,3) == date_or_sid)), find(subjects(:,4) == kid));
0028     if (isempty(index) == 1)
0029       disp('wrong subject information\n');
0030       return; 
0031     else
0032       sid = subjects(index,1); 
0033     end;
0034 else
0035     % wrong usage
0036     disp('invalid arguments\n');
0037     return;
0038 end
0039 
0040 % find the speech transcription file
0041 fname = sprintf('%s/speech_transcription_p/speech_%d_out.txt', ...
0042         get_subject_dir(sid),kid)
0043 
0044     
0045 %
0046 % data structure: speech.uts: an array of spoken utterances, with bt, et
0047 % and words
0048 % speech.stats: some statistical measures
0049 %
0050 % load the file and save it
0051 speech.uts = load_speech(fname);
0052 speech.stats = cal_word_stats(speech.uts);
0053 fname = sprintf('%s/derived/speech_trans.mat', get_subject_dir(sid));
0054 save(fname, 'speech'); 
0055 
0056 % load naming events '
0057 
0058 
0059 fname = sprintf('%s/speech_transcription_p/naming_instances.csv', ...
0060         get_subject_dir(sid)) 
0061 [name_event] = csvread(fname);
0062 % synch the time
0063 timing = get_timing(sid);
0064 name_event(:,1:2) = name_event(:,1:2) + timing.speechTime; 
0065 
0066 % save the naming events
0067 record_variable(sid, 'cevent_speech_naming_local-id', name_event);
0068 
0069 % generate speech utterance variable
0070 sdata = get_variable(sid, 'speech_trans');
0071 bt = (arrayfun(@(a) a.bt, sdata.speech.uts))';
0072 et = (arrayfun(@(a) a.et, sdata.speech.uts))';
0073 
0074 non_referent_id = 25; 
0075 utterance = [bt + timing.speechTime et+timing.speechTime ones(size(bt,1),1)*non_referent_id];
0076 
0077 for i = 1: size(utterance,1)
0078   index=  find(utterance(i,1) == name_event(:,1)); 
0079   if ~isempty(index)
0080     if size(index,1) == 1
0081       utterance(i,3) = name_event(index,3);
0082     else % more than one names
0083       utterance(i,3) = name_event(index(1),3);
0084     end;
0085   end;
0086 end;
0087 
0088 record_variable(sid, 'cevent_speech_utterance', utterance);

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005