
//====================================================
//  Portuguese  - based on Base2
//====================================================

// This phonemes file is refered as "pt" in language and voice files.
// The phonemes defined here are also used in the file `ph_portugal`.


// Vowels

phoneme &
  vwl starttype #@ endtype #@
  length 180
  ipa ɐ
  FMT(vowel/a#_3)
endphoneme

phoneme &/       // Used for final "a" when next word starts with "a"
  vwl starttype #@ endtype #@
  length 180
  ipa ɐ
  IF nextPh(isVowel) THEN
    ChangePhoneme(NULL)
  ENDIF
  FMT(vowel/a#_3)
endphoneme

phoneme A            // for "al" in European Portuguese, don't reduce to [&]
  vwl starttype #a endtype #a
  length 200
  FMT(vowel/a_2)
endphoneme

phoneme e
  vwl starttype #e endtype #e
  length 160
  FMT(vowel/e)
endphoneme

phoneme E
  vwl starttype #e endtype #e
  length 170
  FMT(vowel/ee_3)
endphoneme

phoneme i"           // unstressed /i/ for European Portuguese
  vwl starttype #@ endtype #@
  length 130
  ipa ɨ
  FMT(vowel/i#_5)
endphoneme

phoneme i/           // changes to [j] before a vowel
  vwl starttype #i endtype #i
  length 150
  IF nextPh(isVowel) THEN
    ChangePhoneme(j)
  ENDIF
  IfNextVowelAppend(;)
  FMT(vowel/ii_6)
endphoneme

phoneme I            // unstressed /i/ for Brazilian Portuguese
  vwl starttype #i endtype #i
  ipa ɪ
  length 110
  IfNextVowelAppend(;)
  FMT(vowel/ii_6)
endphoneme

phoneme I/           // very short [i] used for epenthesis in Brasil
  vwl starttype #i endtype #i
  ipa NULL
  unstressed nsy
  length 80
  FMT(vowel/ii_6)
endphoneme

phoneme y            // old unstressed /i/ kept for backward compatibility
  CALL pt/I
endphoneme

phoneme O
  vwl starttype #o endtype #o
  length 170
  FMT(vowel/0)
endphoneme

phoneme u
  vwl starttype #u endtype #u
  length 160
  FMT(vowel/u_bck)
endphoneme

phoneme U
  vwl starttype #u endtype #u
  length 140
  IF thisPh(isWordEnd) AND thisPh(isUnstressed) THEN
    IF NOT prevPh(w) AND nextPh(isVowel) THEN
      ChangePhoneme(w)
    ENDIF
  ENDIF
  FMT(vowel/uu_bck)
endphoneme


// Nasal Vowels

phoneme &~
  vwl  starttype #@ endtype #@
  ipa ɐU+0303
  length 180
  IF thisPh(isFinalVowel) THEN
    FMT(vnasal/a#_n2)
  ELSE
    FMT(vnasal/a#_n)
  ENDIF
endphoneme

phoneme e~
  vwl starttype #e endtype #e
  length 180
  FMT(vnasal/e_n)
endphoneme

phoneme i~
  vwl starttype #i endtype #i
  length 180
  IfNextVowelAppend(;)
  FMT(vnasal/i_n)
endphoneme

phoneme o~
  vwl starttype #o endtype #o
  length 180
  FMT(vnasal/o_n)
endphoneme

phoneme u~
  vwl starttype #u endtype #u
  length 180
  FMT(vnasal/u_n)
endphoneme


// Diththongs

phoneme aI
  vwl starttype #a endtype #i
  length 230
  IfNextVowelAppend(;)
  FMT(vdiph/ai)
endphoneme

phoneme eI
  vwl starttype #e endtype #i
  length 230
  IfNextVowelAppend(;)
  FMT(vdiph/ei)
endphoneme

phoneme eU
  vwl starttype #e endtype #u
  length 230
  FMT(vdiph/eu)
endphoneme

phoneme EU
  vwl starttype #e endtype #u
  length 230
  FMT(vdiph/eeu)
endphoneme

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

phoneme OI
  vwl starttype #o endtype #i
  length 230
  IfNextVowelAppend(;)
  FMT(vdiph/0i)
endphoneme

phoneme oU
  vwl starttype #o endtype #u
  length 230
  FMT(vdiph/ou)
endphoneme

phoneme uI
  vwl starttype #u endtype #i
  length 230
  IfNextVowelAppend(;)
  FMT(vdiph/ui_4)
endphoneme


// Nasal Diththongs

phoneme &U~
  vwl  starttype #@ endtype #u
  ipa ɐU+0303ʊU+0303
  length 240
  IF thisPh(isDiminished) THEN
    FMT(vnasal/au_n)
  ENDIF
  FMT(vnasal/a#u_n)
endphoneme

phoneme oI~
  vwl starttype #o endtype #i
  ipa oU+0303ɪU+0303
  length 240
  FMT(vnasal/oi_n)
endphoneme

phoneme uI~
  vwl starttype #u endtype #i
  ipa uU+0303ɪU+0303
  length 240
  FMT(vnasal/uI_n)
endphoneme


// Asyllabic vowels

phoneme j/           // asyllabic vowel similar to [j] used with MBrola voices
  vwl starttype #i endtype #i
  ipa j
  length 150
  unstressed nsy
  FMT(vowel/i)
endphoneme

phoneme w/           // asyllabic vowel similar to [w] used with Mbrola voices
  vwl starttype #u endtype #u
  ipa w
  length 150
  unstressed nsy
  FMT(vowel/u_bck)
endphoneme


// Lateral Consonants

phoneme l
  import_phoneme en/l   // 'dark' /l/ used in coda for European Portuguese
endphoneme

phoneme l^
  liquid pal
  lengthmod 7
  ipa ʎ
  CALL base1/l
  CALL base1/j
endphoneme


// Sibilant Consonants

phoneme S
  CALL base1/S
  ipa ʃ
endphoneme

phoneme Z
  CALL base1/Z
  ipa ʒ
endphoneme


// Rhotic Consonants

phoneme x            // old strong /R/ kept for backward compatibility
  CALL base1/h       // this glotal rhotic has coarticulation with vowels
  ipa x
endphoneme

phoneme X            // to be used in dialects such as from Rio
  CALL base1/X
  ipa χ
endphoneme

phoneme Q"           // to be used in dialects such as from Lisbon
  CALL base1/Q"
  ipa ʁ
endphoneme

phoneme *            // weak /r/ in syllable onset or coda
  vcd alv flp rhotic
  lengthmod 3
  ipa ɾ
  Vowelin f1=1  f2=1700 -300 300  f3=-100 80
  Vowelout f1=2 f2=1700 -300 300  f3=-100 80

  IF prevPhW(isNotVowel) OR thisPh(isWordStart) THEN
    InsertPhoneme(@-) // ineffective after change
  ELIF nextPhW(isNotVowel) AND NOT nextPhW(j) AND NOT nextPhW(w) THEN
    AppendPhoneme(@-)
  ENDIF
  FMT(d/tap2) addWav(x/d, 60)
endphoneme

phoneme @-           // very short schwa used along with weak /r/ only
  vwl starttype #@  endtype #@
  unstressed nsy
  ipa NULL
  length 20
  FMT(vowel/@-)
endphoneme


// Nasal Consonants

procedure Nn
  CALL base2/n
  length 50
  ipa n
endprocedure

procedure Nm
  CALL base2/m
  length 50
  ipa m
endprocedure

procedure NN
  CALL base2/N
  length 50
  ipa ŋ
endprocedure

procedure Nw
  CALL base2/w
  ipa w
endprocedure

phoneme N            // polimorphic nasal consonant used in syllable onset
  vcd nas

  IF NOT thisPh(isWordEnd) AND nextPh(isVowel) THEN
    ChangePhoneme(n)
  ENDIF

  IF thisPh(isWordEnd) AND nextPh(isVowel) THEN
    IF prevPh(o~) OR prevPh(u~) THEN
      CALL Nw
    ELSE
      CALL NN
    ENDIF
    RETURN
  ENDIF

  IF nextPh(isPause) THEN
    IF prevPh(#i) THEN
      CALL NN
    ELSE
      CALL Nm
    ENDIF
    RETURN
  ELIF nextPh(k) OR nextPh(g) THEN
    CALL NN
  ELIF nextPh(p) OR nextPh(b) THEN
    CALL Nm
  ELSE
    CALL Nn
  ENDIF
endphoneme


// Special Consonants for Dialectal Variation

phoneme l#           // special phoneme for /l/ or /w/ in coda
  virtual
  IF NOT nextPhW(isVowel) OR nextPh(isWordEnd) THEN
    ChangePhoneme(w)
  ENDIF
  ChangePhoneme(l)
endphoneme

phoneme s#           // special phoneme for /s/ or /z/ in coda
  virtual
  IF nextPh(isVoiced) THEN
    ChangePhoneme(z)
  ENDIF
  ChangePhoneme(s)
endphoneme

phoneme R#           // special phoneme for strong /R/ in onset
  virtual
  ChangePhoneme(x)
endphoneme

phoneme r#           // special phoneme for weak /r/ in coda
  virtual
  ChangePhoneme(*)
endphoneme

phoneme d#           // special phoneme for /d/ or /dZ/
  virtual
  IF nextPhW(#i) THEN
    ChangePhoneme(dZ)
  ELIF thisPh(isWordEnd) THEN
    ChangePhoneme(dZ)
  ENDIF
  ChangePhoneme(d)
endphoneme

phoneme t#           // special phoneme for /t/ or /tS/
  virtual
  IF nextPhW(#i) THEN
    ChangePhoneme(tS)
  ELIF thisPh(isWordEnd) THEN
    ChangePhoneme(tS)
  ENDIF
  ChangePhoneme(t)
endphoneme

