-
Notifications
You must be signed in to change notification settings - Fork 0
/
synthesizeVowels.m~
78 lines (71 loc) · 3.09 KB
/
synthesizeVowels.m~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function vowelWav = synthesizeVowels(vowelID, flag, folder)
switch vowelID %%% formants - denote the formant frequencies, df1, df2 and df3 denote the allowable range
%%% of formant frequencies for a particular vowel %%%
case 1 %%% vowel IY - example beet %%%
formants = [270 2290 3010]; df = [100 500 100];
case 2 %%% vowel I - example bit %%%
formants = [390 1990 2550]; df = [200 650 100];
case 3 %%% vowel E - example bet %%%
formants = [530 1840 2480]; df = [200 600 100];
case 4 %%% vowel AE - example bat %%%
formants = [660 1720 2410]; df = [300 600 100];
case 5 %%% vowel UH - example but %%%
formants = [520 1190 2390]; df = [250 400 100];
case 6 %%% vowel A - example hot %%%
formants = [730 1090 2440]; df = [200 300 100];
case 7 %%% vowel OW - example bought %%%
formants = [440 1020 2240]; df = [100 250 100];
case 8 %%% vowel U - example foot %%%
formants = [300 870 2240]; df = [50 200 100];
case 9 %%% vowel OO - example boot %%%
formants = [570 840 2410]; df = [50 200 100];
case 10 %%% vowel ER - example bird %%%
formants = [490 1350 1690]; df = [100 100 100];
end
R = [0.95 0.97 0.93]; dr=0.01;
%%%% Designing the source %%%%%
if flag == 1; %%% Synthesize only one instance %%%%
vowelWav = synthesizeVowelInstance(formants, R);
else
for j = 1 : 10;
signVal = ones(1,3);
randVal = rand(1,3); signVal(randVal < 0.5) = -1; randVal = randVal.*signVal;
formants = formants + randVal.*(0.5*df) ;
%R = R + randVal.*dr;
vowelWav = synthesizeVowelInstance(formants, R);
outFile = [folder '/vowel_' num2str(vowelID) '_instance_' num2str(j) '_f1_' num2str(floor(formants(1))) '_f2_' num2str(floor(formants(2))) ...
'_f3_' num2str(floor(formants(3)))];
wavwrite(vowelWav, 16000, outFile);
end
end
end
function vowelWav = synthesizeVowelInstance(formants, R)
%% Funtion to synthesize a vowel using the formants and radius of the formant poles as the argument %%%
sr = 16000;
f0 = 220*ones(20,1);
eng = 0.9*ones(20,1);
frameShift = 0.015*sr;
frameSize = 0.025*sr;
t1 = 0.004; t2 = 0.002;
glotWav=createImpulse(f0, eng ,frameShift,t1,t2,1);
%%
nsamps = 16000;
f0 = 200; % Pitch in Hz
w0T = 2*pi*f0/sr; % radians per sample
nharm = floor((sr/2)/f0); % number of harmonics
sig = zeros(1,nsamps);
n = 0:(nsamps-1);
% Synthesize bandlimited impulse train
for i=1:nharm,
sig = sig + cos(i*w0T*n);
end;
%glotWav = sig;
%%%% Create Vocal Tract system %%%%
formantsAngleZ = 2*pi*formants/sr;
formantsRadius = R;
polesZ = formantsRadius.*exp(1j*formantsAngleZ);
tractFilter = real(poly([polesZ,conj(polesZ)]));
%%%% synthesis of vowel %%%%%
vowelWav = filter(1, tractFilter, glotWav);
vowelWav = vowelWav/(1.1*max(abs(vowelWav)));
end