Takes a string and returns the number of syllables.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install syllable_counter
To get the number of syllables for a string:
SyllableCounter.get_syllables("Text to be evaluated goes here") #=> 10
The algorithm is not corpus-based but based upon phonemic complementary distributions as they exist in American English. This is an introductory set that will keep growing. Suggestions for additions are absolutely welcome! Email me at firstname.lastname@example.org.
- Assumes at least one obligatory vowel per syllable
- Final /e/ is not realized unless the final /e/ is preceded by an /l/ or /r/ and a consonant (ie. -dle, -cre).
- Final /ed/ suffix is not realized when preceeded by a /t/ or /d/
- Final /es/ plural suffix is realized after /s/ /z/ /sh/ /dg/ /ch/ /[aeiou]g/
- Two consecutive vowels outside of /[aeiouy]o/ are combined as one syllable
- /[aeiuy]o/ does not get merged as one syllable (ie. aon, ion, eon)
- /iu/ combinations are two syllables
- Exceptions: "maybe", "Wednesday"
- Dialect-specific versions for English