Dawn@4: function [F0, V, err] = func_SnackPitch(wavfile, windowsize, frameshift, maxF0, minF0) Dawn@4: % [F0, V, err] = func_SnackPitch(wavfile, windowsize, frameshift, maxF0, minF0) Dawn@4: % Input: wavfile - input wav file Dawn@4: % windowlength - windowlength in seconds Dawn@4: % frameshift - in seconds Dawn@4: % maxF0/minF0 - max and min thresholds Dawn@4: % Output: F0, V - F0 and voicing vectors Dawn@4: % err - error flag Dawn@4: % Notes: If on Windows/PC, this function will call up the Snack executable Dawn@4: % in the Windows folder. Otherwise, it will try to call up Snack - this Dawn@4: % require Snack to be installed beforehand. 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: Dawn@4: %settings Dawn@4: iwantfilecleanup = 1; %delete tcl,f0,frm files when done Dawn@4: tclfilename = 'tclforsnackpitch.tcl'; %produce tcl file to call snack Dawn@4: Dawn@4: % make the wavfile acceptable to tcl in Snack Dawn@4: wavfile = strrep(wavfile, '[', '\['); Dawn@4: wavfile = strrep(wavfile, ']', '\]'); Dawn@4: wavfile = ['"' wavfile '"']; Dawn@4: %wavfile = strrep(wavfile, '\', '\\'); % for PC Dawn@4: Dawn@4: if (ispc) % pc can run snack.exe Dawn@4: wavfile = strrep(wavfile, '\', '\\'); Dawn@4: err = system(['Windows\snack.exe pitch ' wavfile ' -method esps -framelength ' num2str(frameshift) ' -windowlength ' num2str(windowsize) ' -maxpitch ' num2str(maxF0) ' -minpitch ' num2str(minF0)]); Dawn@4: Dawn@4: else % for macs and possibly others Dawn@4: %cmd = 'tclsh'; % for older Macs and 'nixes Dawn@4: cmd = 'wish8.4'; % seems to work for OSX Snow Leopard Dawn@4: %cmd = 'wish84'; % for pc Dawn@4: Dawn@4: fid = fopen(tclfilename, 'wt'); Dawn@4: Dawn@4: fprintf(fid, '#!/bin/sh\n'); Dawn@4: fprintf(fid, '# the next line restarts with wish \\\n'); Dawn@4: fprintf(fid, 'exec wish8.4 "$0" "$@"\n\n'); Dawn@4: fprintf(fid, 'package require snack\n\n'); Dawn@4: fprintf(fid, 'snack::sound s\n\n'); Dawn@4: fprintf(fid, 's read %s\n\n', wavfile); Dawn@4: fprintf(fid, 'set fd [open [file rootname %s].f0 w]\n', wavfile); Dawn@4: fprintf(fid, 'puts $fd [join [s pitch -method esps -framelength %f -windowlength %f -maxpitch %d -minpitch %d] \\n]\n', frameshift, windowsize, maxF0, minF0); Dawn@4: fprintf(fid, 'close $fd\n\n'); Dawn@4: fprintf(fid, 'exit'); Dawn@4: fclose(fid); Dawn@4: Dawn@4: err = system([cmd ' ' tclfilename]); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: % change back into original file Dawn@4: wavfile = strrep(wavfile, '\[', '['); Dawn@4: wavfile = strrep(wavfile, '\]', ']'); Dawn@4: pitchfile = [wavfile(2:end-4) 'f0']; % this should be where the F0's are stored Dawn@4: Dawn@4: % oops, exit now Dawn@4: if (err ~= 0) Dawn@4: F0 = NaN; Dawn@4: V = NaN; Dawn@4: if (iwantfilecleanup) Dawn@4: pitchfile = strrep(pitchfile, '\\', '\'); Dawn@4: if (exist(pitchfile, 'file') ~= 0) Dawn@4: delete(pitchfile); Dawn@4: end Dawn@4: Dawn@4: if (exist(tclfilename, 'file') ~= 0) Dawn@4: delete(tclfilename); Dawn@4: end Dawn@4: end Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: % snack executed successfully, read out the F0 values Dawn@4: [F0, V, dummy1, dummy2] = textread(pitchfile, '%f %f %f %f'); Dawn@4: Dawn@4: if (iwantfilecleanup) Dawn@4: pitchfile = strrep(pitchfile, '\\', '\'); Dawn@4: if (exist(pitchfile, 'file') ~= 0) Dawn@4: delete(pitchfile); Dawn@4: end Dawn@4: Dawn@4: if (exist(tclfilename, 'file') ~= 0) Dawn@4: delete(tclfilename); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: