comparison Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/func_SnackPitch.m @ 4:92ca03a8fa99 tip

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