 
//====================================================
//  Vietnamese Phonemes
//====================================================


phoneme 1   //  ngang tone: level
  stress
  Tone(30, 28, envelope/p_level, NULL) // 28 29
endphoneme


phoneme 2   //  huyền tone: low falling
  stress
  Tone(20, 8, envelope/p_fall, NULL) //20 8
endphoneme


phoneme 3   //  sắc Tone(rising
  stress
  Tone(20, 50, envelope/p_rise, NULL) // 30 60
endphoneme


phoneme 4   //  hỏi Tone(curve (dipping rising)
  stress
  Tone(10, 31, envelope/p_fallrise, NULL) //33 31
endphoneme


phoneme 5   //  ngã tone: broken (creaking rising)
  stress
  Tone(34, 60,envelope/p_214, envelope/vi_5amp) // 28,58 20 80
endphoneme


phoneme 6   //  nặng Tone(drop  (constricted)
  stress
  //length 150 // ignore because it make too short sound 75  // reduce the length of the vowel
  Tone(34, 10, envelope/p_512, envelope/vi_6amp) //40 20
endphoneme


phoneme 7   //  Tone(1 (ngang) at end of clause
  stress
  Tone(30,  28, envelope/p_fall, NULL) //40 20
endphoneme



// Vowels
//=======


phoneme a
  vwl starttype #@ endtype #@
  	IF nextPhW(p) THEN
	length 142
  ELIF nextPhW(t[) THEN
	length 126
  ELIF nextPhW(c) THEN
	length 136
  ELIF nextPhW(m) THEN
	length 155
  ELIF nextPhW(n) THEN
	length 185
  ELIF nextPhW(N) THEN
	length 173
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELSE
	length 180
  ENDIF
	IF nextPh(N) OR nextPh(c) THEN
	FMT(vnasal/a_n)
	ELSE
	FMT(vietnam/a_2)  //a_4)
	
	ENDIF
endphoneme

phoneme a:
  vwl starttype #a endtype #a
  IF nextPhW(p) THEN
	length 142
  ELIF nextPhW(t[) THEN
	length 126
  ELIF nextPhW(c) THEN
	length 136
  ELIF nextPhW(m) THEN
	length 155
  ELIF nextPhW(n) THEN
	length 185
  ELIF nextPhW(N) THEN
	length 173
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 333
  ELSE
	length 180
  ENDIF
    //FMT(vowel/a_8)
	FMT(vietnam/aa)
endphoneme


phoneme E
  vwl starttype #e endtype #e
  
  IF nextPhW(p) THEN
	length 143
  ELIF nextPhW(t[) THEN
	length 107
  ELIF nextPhW(c) THEN
	length 141
  ELIF nextPhW(m) THEN
	length 128
  ELIF nextPhW(n) THEN
	length 160
  ELIF nextPhW(N) THEN
	length 187
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 352
  ELSE
	length 180
  ENDIF
  //FMT(vowel/e_e)   //ee_3)
  FMT(vietnam/e_e)
endphoneme

phoneme e
  vwl starttype #e endtype #e
  IF nextPhW(p) THEN
	length 114
  ELIF nextPhW(t[) THEN
	length 126
  ELIF nextPhW(c) THEN
	length 140
  ELIF nextPhW(n^) THEN
	length 120
  ELIF nextPhW(m) THEN
	length 148
  ELIF nextPhW(n) THEN
	length 163
  ELIF nextPhW(N) THEN
	length 115
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 324
  ELSE
	length 180
  ENDIF
  IF nextPh(n^) THEN
	FMT(vowel/e)
  ELSE
	FMT(vietnam/e_2)
  ENDIF	
endphoneme


phoneme e-
   vwl starttype #e endtype #a
   length 140
   //FMT(vietnam/e_short_2)
   FMT(vdiph/aai_3)
endphoneme

phoneme i
  vwl  starttype #i  endtype #i
    IfNextVowelAppend(;)
  IF prevPhW(w) THEN
    VowelStart(w/wi)
  ENDIF
  IF nextPhW(p) THEN
	length 131
  ELIF nextPhW(t[) THEN
	length 113
  ELIF nextPhW(c) OR nextPhW(n^) THEN
	length 72
  ELIF nextPhW(m) THEN
	length 120
  ELIF nextPhW(n) THEN
	length 128
  ELIF nextPhW(N) THEN
	length 97
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 310
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 363
  ELSE
	length 180
  ENDIF
  IF nextPh(n^) OR nextPh(c) THEN
  //FMT(vnasal/ii_n)
  FMT(vietnam/i)
  ELSE
	//FMT(vowel/i_4)
	FMT(vietnam/i_2)
ENDIF
endphoneme


phoneme O
  vwl starttype #o endtype #o
    IF nextPhW(p) THEN
	length 129
  ELIF nextPhW(t[) THEN
	length 125
  ELIF nextPhW(c) THEN
	length 80
  ELIF nextPhW(m) THEN
	length 133
  ELIF nextPhW(n) THEN
	length 158
  ELIF nextPhW(N) THEN
	length 102
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 331
  ELSE
	length 180
  ENDIF
    //FMT(vdiph2/o_oo) //vowel/oo)
	FMT(vietnam/oo)
endphoneme

phoneme O+
  vwl starttype #o endtype #o
    IF nextPh(kh) OR nextPh(N) THEN 
	length 80
	ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 180
	ENDIF
    FMT(vowel/o) //vowel/oo)
endphoneme

phoneme o
  vwl starttype #o endtype #o
  IF nextPhW(p) THEN
	length 140
  ELIF nextPhW(t[) THEN
	length 113
  ELIF nextPhW(c) THEN
	length 88
  ELIF nextPhW(m) THEN
	length 134
  ELIF nextPhW(n) THEN
	length 168
  ELIF nextPhW(N) THEN
	length 99
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 310
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 363
  ELSE
	length 180
  ENDIF
  //FMT(vowel/o)  // o_2)
  FMT(vietnam/o)
endphoneme


phoneme u
  vwl starttype #u endtype #u
  
  IF nextPhW(p) THEN
	length 110
  ELIF nextPhW(t[) THEN
	length 94
  ELIF nextPhW(c) THEN
	length 83
  ELIF nextPhW(m) THEN
	length 141
  ELIF nextPhW(n) THEN
	length 177
  ELIF nextPhW(N) THEN
	length 80
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 333
  ELSE
	length 180
  ENDIF
  //FMT(vnasal/u_n) //vowel/u_5)
  FMT(vietnam/u)
endphoneme

phoneme y
  vwl starttype #u endtype #u
  IF nextPhW(p) THEN
	length 102
  ELIF nextPhW(t[) THEN
	length 76
  ELIF nextPhW(c) THEN
	length 70
  ELIF nextPhW(m) THEN
	length 143
  ELIF nextPhW(n) THEN
	length 136
  ELIF nextPhW(N) THEN
	length 101
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 328
  ELSE
	length 180
  ENDIF
  //FMT(vowel/u#_5)
  FMT(vietnam/y)
endphoneme



phoneme @
  vwl  starttype #@  endtype #a
	IF nextPhW(p) THEN
	length 123
  ELIF nextPhW(t[) THEN
	length 123
  ELIF nextPhW(c) THEN
	length 139
  ELIF nextPhW(m) THEN
	length 127
  ELIF nextPhW(n) THEN
	length 160
  ELIF nextPhW(N) THEN
	length 156
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELSE
	length 180
  ENDIF
  // FMT(vowel/V)   //vowel/@_2)
  FMT(vietnam/V_2)
endphoneme


phoneme @:
  vwl  starttype #@  endtype #@
  IF nextPhW(p) THEN
	length 123
  ELIF nextPhW(t[) THEN
	length 123
  ELIF nextPhW(c) THEN
	length 139
  ELIF nextPhW(m) THEN
	length 127
  ELIF nextPhW(n) THEN
	length 160
  ELIF nextPhW(N) THEN
	length 156
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 300
  ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordStart) THEN
	length 240
  ELIF thisPh(isWordStart) AND thisPh(isWordEnd) THEN
     length 333
  ELSE
	length 180
  ENDIF
  //FMT(vowel/@_2)
  FMT(vietnam/@_2)
endphoneme



// Diphthongs
//===========

phoneme aI
  vwl starttype #a endtype #i
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/&i_2)
endphoneme


phoneme a:I
  vwl starttype #a endtype #i
  length 240  //250
  FMT(vdiph/ai)
endphoneme


phoneme @I
  vwl starttype #@ endtype #i
  length 240 //250
  FMT(vdiph/@i)
endphoneme


phoneme @:I
  vwl starttype #@ endtype #i
  length 240 //250
  FMT(vdiph/y#i)
endphoneme


phoneme eI
  vwl starttype #e endtype #i
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/ei)
endphoneme


phoneme EI
  vwl starttype #e endtype #i
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/eei)
endphoneme


phoneme OI
  vwl starttype #o endtype #i
  length 240
  FMT(vdiph/ooi_4)
endphoneme


phoneme oI
  vwl starttype #o endtype #i
  length 240
  FMT(vdiph/oi)
endphoneme


phoneme uI
  vwl starttype #u endtype #i
  length 240
  FMT(vdiph/ui)
endphoneme

phoneme yI
  vwl starttype #u endtype #i
  length 240
  FMT(vdiph/u-i)
endphoneme




phoneme aU
  vwl starttype #a endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/aau_4)
endphoneme


phoneme a:U
  vwl starttype #a endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/au)
endphoneme


phoneme eU
  vwl starttype #e endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/eu)
endphoneme


phoneme EU
  vwl starttype #e endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/eeu)
endphoneme

phoneme iU
  vwl starttype #i endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph2/iu)
endphoneme

phoneme @U
  vwl  starttype #@  endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/@u_3)
endphoneme

phoneme @:U
  vwl  starttype #@  endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/@u)
endphoneme



phoneme i@
  vwl  starttype #i  endtype #@
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph2/ii@_3)
endphoneme

phoneme y@
  vwl  starttype #i  endtype #@
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph2/y-y#)
endphoneme

phoneme u@
  vwl  starttype #u  endtype #@
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph2/uu@)
endphoneme

// Addition Dipthongs

phoneme o# // ông
  vwl  starttype #o  endtype #o
  IF nextPhW(k) THEN
	length 120
	ELIF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 360
	ELSE
	length 200
	ENDIF
  //FMT(vnasal/a#u_n)
    FMT(vietnam/o#)
endphoneme

phoneme O# // ong
  vwl  starttype #o  endtype #o
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELIF nextPh(k) THEN
	length 140
	ELSE
	length 200
	ENDIF
  //FMT(vnasal/&u_n)
  FMT(vietnam/O_short)
endphoneme


phoneme o@
  vwl  starttype #o endtype #a
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph2/oa)
endphoneme

phoneme o&
  vwl  starttype #o endtype #o
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vietnam/oe)
endphoneme

phoneme iE // iê : viết, giệc
  vwl  starttype #i  endtype #e
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vietnam/ie_2)
endphoneme

phoneme Oi // oai sound
  vwl  starttype #o  endtype #i
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 200
	ENDIF
  FMT(vdiph/ooi_3)
endphoneme

// Vowel and Dipthong for south dialect

phoneme O- // ôi southern sound
  vwl  starttype #o  endtype #i
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 180
	ENDIF
  FMT(vnasal/oi_n)
endphoneme

phoneme @- // ơi southern sound
  vwl  starttype #o  endtype #i
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 180
	ENDIF
  FMT(vdiph/@i_3)
endphoneme

phoneme u- // u southern sound
  vwl  starttype #u  endtype #u
  IF thisPh(isFirstVowel) AND thisPh(isFinalVowel) AND thisPh(isWordEnd) THEN
	length 240
	ELSE
	length 180
	ENDIF
  FMT(vowel/u_3,70)
endphoneme

phoneme kh
  vls vel frc
  lengthmod 3
  Vowelin f1=0  f2=2300 200 400  f3=200 80 len=30
  Vowelout f1=0 f2=2300 300 400  f3=200 80  rms=20
    WAV(ustop/k_unasp)  //ufric/x, 50)
endphoneme

phoneme k
  vls vel frc
  lengthmod 3
  Vowelin f1=0  f2=2300 200 400  f3=200 80 len=30
  Vowelout f1=0 f2=2300 300 400  f3=200 80  rms=20
    WAV(ustop/c)
endphoneme

phoneme N // si**ng** 
  vcd lbv nas
  Vowelout f1=3 f2=2300 300 400  f3=-200 80  len=40 rms=20 brk
  lengthmod 12            // longer than 'n'
  length 163
  FMT(n/nm)
endphoneme

phoneme l
  liquid
  Vowelin f1=0  f2=1700 -300 300  f3=-100 80 len=15
  //lengthmod 7
   //IF nextPh(isNotVowel) THEN
   // ChangePhoneme(l/2)
  //ENDIF
  //CALL vowelstart_l

  FMT(l/l_vi)
endphoneme

phoneme t
  vls alv stp
  //voicingswitch d
  lengthmod 2
  Vowelin f1=0  f2=1700 -300 300  f3=-100 80 len=15
  Vowelout f1=0 f2=1700 -300 250  f3=-100 80  rms=20

  WAV(vietnam/th, 50)
endphoneme

phoneme cr
  vls pla afr sib
  //voicingswitch dZ
  lengthmod 2
  Vowelin f1=0  f2=2300 200 400  f3=-100 80 len=15

  
  WAV(vietnam/tr,10)
endphoneme

phoneme d_
  vcd alv stp
    //	lengthmod 5
	ipa ɗ
	length 50
 Vowelin f1=1  f2=1700 -300 300  f3=-100 80 len=15
  Vowelout f1=2 f2=1700 -300 300  f3=-100 80 brk len=30
WAV(vietnam/dd)
 endphoneme
 
 phoneme c
  vls pal stp pzd
  //voicingswitch J
  lengthmod 2
  length 50
    Vowelin f1=0  f2=2700 400 600  f3=300 80 len=15 brk
  Vowelout f1=1  f2=2700 400 600  f3=200 70 len=15 colr=1

  
  WAV(vietnam/ch,5)
endphoneme


phoneme p
  vls blb stp
    lengthmod 2
	length 15
  Vowelin  f1=0  f2=1000 -50 -100  f3=-200 80 amp=11
  Vowelout f1=0  f2=1000 -500 -350  f3=-300 80 rms=22

    WAV(ustop/p_unasp_,10)
  
endphoneme

phoneme t[        // dental variant of /t/
  IF thisPh(isWordEnd) THEN
	vls alv stp
	voicingswitch d
	lengthmod 2
	length 15
	Vowelin f1=1  f2=1500 -250 250  f3=-100 80  amp=16 len=15
	Vowelout f1=0 f2=1500 -300 250  f3=-100 80  rms=20 len=15
	WAV(ustop/t, 50)
  ELSE
	vls dnt stp
	voicingswitch d[
	lengthmod 2
	length 15
	Vowelin f1=1  f2=1500 -250 250  f3=-100 80  amp=16 len=15
	Vowelout f1=0 f2=1500 -300 250  f3=-100 80  rms=20 len=15

	IF nextPh(isPause2) THEN
	WAV(ustop/t_unasp2, 5)
	ENDIF
	WAV(ustop/t_hi, 70)
  ENDIF
endphoneme

phoneme w
  liquid
  length 20
  starttype #u
  
  IF nextPh(isVowel) THEN
    NextVowelStarts
      VowelStart(w/w@)
      VowelStart(w/wa)
      VowelStart(w/we)
      VowelStart(w/wi)
      VowelStart(w/wo)
      VowelStart(w/wu)
    EndSwitch

    VowelEnding(w/xw, -30)
	IF nextPh(isVowel) AND prevPhW(t[) THEN
		FMT(vnasal/u_n, 60)
	ENDIF
    IF prevPhW(isNasal) THEN
      FMT(w/w)
    ELSEIF prevPhW(h) THEN
      // none,  [hw]
    ELSE
      FMT(w/_w)
    ENDIF
  ELSE
    // no vowel follows
    Vowelout len=50
    IF prevPh(#i) THEN
      FMT(w/iw_)
    ENDIF
    FMT(w/w_)
  ENDIF
endphoneme