Mercurial > hg > emotion-detection-top-level
comparison Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/func_SnackFormants.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 [F1, F2, F3, F4, B1, B2, B3, B4, err] = func_SnackFormants(wavfile, windowlength, frameshift, preemphasis) | |
2 % [F1, F2, F3, F4, B1, B2, B3, B4, err] = func_SnackFormants(wavfile, windowlength, frameshift, preemphasis) | |
3 % Input: wavfile - input wav file | |
4 % windowlength - windowlength in seconds | |
5 % frameshift - in seconds | |
6 % preemphasis - wonder what this could be? | |
7 % Output: Fx, Bx - formant and bandwidth 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 % settings | |
17 iwantfilecleanup = 1; %delete tcl,f0,frm files when done | |
18 tclfilename = 'tclforsnackformant.tcl'; %produce tcl file to call snack | |
19 | |
20 % make the wavfile acceptable to tcl in Snack | |
21 formantfile = [wavfile(1:end-3) 'frm']; | |
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 cmds = sprintf('-windowlength %.3f -framelength %.3f -windowtype Hamming -lpctype 1 -preemphasisfactor %.3f -ds_freq 10000', windowlength, frameshift, preemphasis); | |
30 err = system(['Windows\snack.exe formant ' wavfile ' ' cmds]); | |
31 | |
32 else % for macs and possibly others | |
33 %cmd = 'tclsh'; % this is for older macs | |
34 cmd = 'wish8.4'; % seems to work for OSX Snow Leopard | |
35 %cmd = 'wish84'; % for PC | |
36 | |
37 fid = fopen(tclfilename, 'wt'); | |
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].frm w]\n', wavfile); | |
45 fprintf(fid, 'puts $fd [join [s formant -windowlength %.3f -framelength %.3f -windowtype 1 -lpctype 1 -preemphasisfactor %.3f -ds_freq 10000] \\n]\n', windowlength, frameshift, preemphasis); | |
46 fprintf(fid, 'close $fd\n\n'); | |
47 fprintf(fid, 'exit'); | |
48 fclose(fid); | |
49 | |
50 err = system([cmd ' ' tclfilename]); | |
51 end | |
52 | |
53 % change back into original file | |
54 wavfile = strrep(wavfile, '\[', '['); | |
55 wavfile = strrep(wavfile, '\]', ']'); | |
56 | |
57 % oops, error, exit now | |
58 if (err~=0) | |
59 F1 = NaN; F2 = NaN; F3 = NaN; F4 = NaN; | |
60 B1 = NaN; B2 = NaN; B3 = NaN; B4 = NaN; | |
61 if (iwantfilecleanup) | |
62 formantfile = strrep(formantfile, '\\', '\'); | |
63 if (exist(formantfile, 'file') ~= 0) | |
64 delete(formantfile); | |
65 end | |
66 | |
67 if (exist(tclfilename, 'file') ~= 0) | |
68 delete(tclfilename); | |
69 end | |
70 end | |
71 return; | |
72 end | |
73 | |
74 % snack call was successful, read out formant values | |
75 [F1,F2,F3,F4,B1,B2,B3,B4] = textread(formantfile, '%f %f %f %f %f %f %f %f'); | |
76 | |
77 if (iwantfilecleanup) | |
78 formantfile = strrep(formantfile, '\\', '\'); | |
79 if (exist(formantfile, 'file') ~= 0) | |
80 delete(formantfile); | |
81 end | |
82 | |
83 if (exist(tclfilename, 'file') ~= 0) | |
84 delete(tclfilename); | |
85 end | |
86 end |