Dawn@4: function [F1, F2, F3, F4, B1, B2, B3, B4, err_msg] = func_OtherFormants(wavfile, handles) Dawn@4: % [F0, err] = func_SnackPitch(wavfile, windowsize, frameshift, maxF0, minF0) Dawn@4: % Input: wavfile - input wav file Dawn@4: % Output: F1, F2, F3, F4, B1, B2, B3, B4 Dawn@4: % err_msg - message of error Dawn@4: % Notes: Function attempts to call an external command to produce a formant Dawn@4: % output file which is read back as a vector. Formant output file format should Dawn@4: % be 8 columns of formant values for each frame Dawn@4: % Dawn@4: % Warning: experimental function Dawn@4: % Dawn@4: % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA Dawn@4: % Copyright UCLA SPAPL 2009 Dawn@4: Dawn@4: % get settings and commands Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: outfile = [wavfile(1:end-3) 'fmt']; Dawn@4: Dawn@4: C = textscan(VSData.vars.FormantsOtherCommand, '%s', 'delimiter', ' '); Dawn@4: C = C{1}; Dawn@4: Dawn@4: command = []; Dawn@4: F1 = NaN; F2 = NaN; F3 = NaN; F4 = NaN; Dawn@4: B1 = NaN; B2 = NaN; B3 = NaN; B4 = NaN; Dawn@4: err_msg = []; Dawn@4: Dawn@4: for k=1:length(C) Dawn@4: if (strcmp(C{k}, '$wavfile')) Dawn@4: command = [command wavfile ' ']; Dawn@4: elseif (strcmp(C{k}, '$outfile')) Dawn@4: command = [command outfile ' ']; Dawn@4: else Dawn@4: command = [command C{k} ' ']; Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: % attempt to run command Dawn@4: [status, results] = system(command); Dawn@4: Dawn@4: % error occured, exit Dawn@4: if (status ~= 0) Dawn@4: err_msg = 'Unable to execute command.'; Dawn@4: Dawn@4: % try to clean up files Dawn@4: if (exist(outfile, 'file') ~= 0) Dawn@4: delete(outfile); Dawn@4: end Dawn@4: Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: % now check if outfile exists Dawn@4: if (exist(outfile, 'file') == 0) Dawn@4: err_msg = 'Unable to find formant file.'; Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: % if file exists, read in the vectors Dawn@4: fid = fopen(outfile, 'rt'); Dawn@4: if (fid == -1) Dawn@4: err_msg = 'Unable to open formant file.'; Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: C = textscan(fid, '%f %f %f %f %f %f %f %f', 'delimiter', '\n'); Dawn@4: fclose(fid); Dawn@4: F1 = C{1}; Dawn@4: F2 = C{2}; Dawn@4: F3 = C{3}; Dawn@4: F4 = C{4}; Dawn@4: B1 = C{5}; Dawn@4: B2 = C{6}; Dawn@4: B3 = C{7}; Dawn@4: B4 = C{8}; Dawn@4: Dawn@4: Dawn@4: % clean up Dawn@4: delete(outfile); Dawn@4: