Skip to content

eoleedi/syllabify

Repository files navigation

Syllabify

PyPI Python 3.x License

Automatically convert plain text into phonemes (US English pronunciation) and syllabify.

Modified from the repository set up by Andrew Caines with some key changes, itemised below:

  • Environment management using uv
  • Python 3.10+ compatibility
  • Easy to access class and function interfaces
  • Use up-to-date cmudict versioned by python-cmudict

Credits: Many thanks for @cainesap's work on porting and fixes & the original author @anthonysgevans

Set up

Requires Python 3 (Anthony Evans used Python 2: if that's what you prefer, see his repo).

pip install syllabify

Usage

Package interface

from syllabify import syllabify
word = syllabify("linguistics")
print(word)
L IH0 NG {onset: L, nucleus: IH0, coda: NG}
G W IH1 {onset: GW, nucleus: IH1, coda: empty}
S T IH0 K S {onset: ST, nucleus: IH0, coda: KS}

You can get the onset, nucleus, and coda of each syllable:

from syllabify import syllabify

word = syllabify("linguistics")
for syllable in word.syllables:
    print(f"Onset: {syllable.onset}")
    print(f"Nucleus: {syllable.nucleus}")
    print(f"Coda: {syllable.coda}")
Onset: L
Nucleus: IH0
Coda: NG
Onset: GW
Nucleus: IH1
Coda: empty
Onset: ST
Nucleus: IH0
Coda: KS

Command line interface

One word at a time:

syllabify linguistics
📝 Input: linguistics
🔤 Syllabification:

LIH0NG [L.IH0.NG] | ˈGWIH1 [GW.IH1.∅] | STIH0KS [ST.IH0.KS]

📖 Legend:
  [onset.nucleus.coda] = syllable structure
  ∅ = empty position
  ˈ = primary stress
  ˌ = secondary stress
  | = syllable boundary

Or several (space-separated):

syllabify colorless green ideas
📝 Input: colorless green ideas
🔤 Syllabification:

  ˈKAH1L [K.AH1.L] | ER0 [∅.ER0.∅] | LAH0S [L.AH0.S]
  ˈGRIY1N [GR.IY1.N]
  AY0 [∅.AY0.∅] | ˈDIY1 [D.IY1.∅] | AH0Z [∅.AH0.Z]

📖 Legend:
  [onset.nucleus.coda] = syllable structure
  ∅ = empty position
  ˈ = primary stress
  ˌ = secondary stress
  | = syllable boundary

About

Automatically convert plain text into phonemes (US English pronunciation) and syllabify

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages