Dawn@4
|
1 function [F0, V, err] = func_SnackPitch(wavfile, windowsize, frameshift, maxF0, minF0)
|
Dawn@4
|
2 % [F0, V, err] = func_SnackPitch(wavfile, windowsize, frameshift, maxF0, minF0)
|
Dawn@4
|
3 % Input: wavfile - input wav file
|
Dawn@4
|
4 % windowlength - windowlength in seconds
|
Dawn@4
|
5 % frameshift - in seconds
|
Dawn@4
|
6 % maxF0/minF0 - max and min thresholds
|
Dawn@4
|
7 % Output: F0, V - F0 and voicing vectors
|
Dawn@4
|
8 % err - error flag
|
Dawn@4
|
9 % Notes: If on Windows/PC, this function will call up the Snack executable
|
Dawn@4
|
10 % in the Windows folder. Otherwise, it will try to call up Snack - this
|
Dawn@4
|
11 % require Snack to be installed beforehand.
|
Dawn@4
|
12 %
|
Dawn@4
|
13 % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA
|
Dawn@4
|
14 % Copyright UCLA SPAPL 2009
|
Dawn@4
|
15
|
Dawn@4
|
16
|
Dawn@4
|
17 %settings
|
Dawn@4
|
18 iwantfilecleanup = 1; %delete tcl,f0,frm files when done
|
Dawn@4
|
19 tclfilename = 'tclforsnackpitch.tcl'; %produce tcl file to call snack
|
Dawn@4
|
20
|
Dawn@4
|
21 % make the wavfile acceptable to tcl in Snack
|
Dawn@4
|
22 wavfile = strrep(wavfile, '[', '\[');
|
Dawn@4
|
23 wavfile = strrep(wavfile, ']', '\]');
|
Dawn@4
|
24 wavfile = ['"' wavfile '"'];
|
Dawn@4
|
25 %wavfile = strrep(wavfile, '\', '\\'); % for PC
|
Dawn@4
|
26
|
Dawn@4
|
27 if (ispc) % pc can run snack.exe
|
Dawn@4
|
28 wavfile = strrep(wavfile, '\', '\\');
|
Dawn@4
|
29 err = system(['Windows\snack.exe pitch ' wavfile ' -method esps -framelength ' num2str(frameshift) ' -windowlength ' num2str(windowsize) ' -maxpitch ' num2str(maxF0) ' -minpitch ' num2str(minF0)]);
|
Dawn@4
|
30
|
Dawn@4
|
31 else % for macs and possibly others
|
Dawn@4
|
32 %cmd = 'tclsh'; % for older Macs and 'nixes
|
Dawn@4
|
33 cmd = 'wish8.4'; % seems to work for OSX Snow Leopard
|
Dawn@4
|
34 %cmd = 'wish84'; % for pc
|
Dawn@4
|
35
|
Dawn@4
|
36 fid = fopen(tclfilename, 'wt');
|
Dawn@4
|
37
|
Dawn@4
|
38 fprintf(fid, '#!/bin/sh\n');
|
Dawn@4
|
39 fprintf(fid, '# the next line restarts with wish \\\n');
|
Dawn@4
|
40 fprintf(fid, 'exec wish8.4 "$0" "$@"\n\n');
|
Dawn@4
|
41 fprintf(fid, 'package require snack\n\n');
|
Dawn@4
|
42 fprintf(fid, 'snack::sound s\n\n');
|
Dawn@4
|
43 fprintf(fid, 's read %s\n\n', wavfile);
|
Dawn@4
|
44 fprintf(fid, 'set fd [open [file rootname %s].f0 w]\n', wavfile);
|
Dawn@4
|
45 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
|
46 fprintf(fid, 'close $fd\n\n');
|
Dawn@4
|
47 fprintf(fid, 'exit');
|
Dawn@4
|
48 fclose(fid);
|
Dawn@4
|
49
|
Dawn@4
|
50 err = system([cmd ' ' tclfilename]);
|
Dawn@4
|
51
|
Dawn@4
|
52 end
|
Dawn@4
|
53
|
Dawn@4
|
54 % change back into original file
|
Dawn@4
|
55 wavfile = strrep(wavfile, '\[', '[');
|
Dawn@4
|
56 wavfile = strrep(wavfile, '\]', ']');
|
Dawn@4
|
57 pitchfile = [wavfile(2:end-4) 'f0']; % this should be where the F0's are stored
|
Dawn@4
|
58
|
Dawn@4
|
59 % oops, exit now
|
Dawn@4
|
60 if (err ~= 0)
|
Dawn@4
|
61 F0 = NaN;
|
Dawn@4
|
62 V = NaN;
|
Dawn@4
|
63 if (iwantfilecleanup)
|
Dawn@4
|
64 pitchfile = strrep(pitchfile, '\\', '\');
|
Dawn@4
|
65 if (exist(pitchfile, 'file') ~= 0)
|
Dawn@4
|
66 delete(pitchfile);
|
Dawn@4
|
67 end
|
Dawn@4
|
68
|
Dawn@4
|
69 if (exist(tclfilename, 'file') ~= 0)
|
Dawn@4
|
70 delete(tclfilename);
|
Dawn@4
|
71 end
|
Dawn@4
|
72 end
|
Dawn@4
|
73 return;
|
Dawn@4
|
74 end
|
Dawn@4
|
75
|
Dawn@4
|
76 % snack executed successfully, read out the F0 values
|
Dawn@4
|
77 [F0, V, dummy1, dummy2] = textread(pitchfile, '%f %f %f %f');
|
Dawn@4
|
78
|
Dawn@4
|
79 if (iwantfilecleanup)
|
Dawn@4
|
80 pitchfile = strrep(pitchfile, '\\', '\');
|
Dawn@4
|
81 if (exist(pitchfile, 'file') ~= 0)
|
Dawn@4
|
82 delete(pitchfile);
|
Dawn@4
|
83 end
|
Dawn@4
|
84
|
Dawn@4
|
85 if (exist(tclfilename, 'file') ~= 0)
|
Dawn@4
|
86 delete(tclfilename);
|
Dawn@4
|
87 end
|
Dawn@4
|
88 end
|
Dawn@4
|
89
|
Dawn@4
|
90
|