Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Splits a word into syllables
Jeff Thompson | 2016 |
Requires this modified version of the CMU Pronouncing
dictionary by Susan Bartlett, Grzegorz Kondrak and Colin Cherry:
Download and save to your project directory, or somewhere you can
easily reference it.
dict_filename = 'cmudict.rep'
syllable_dict = {}
with open(dict_filename) as f:
for line in f:
line = line.strip()
line = line.lower()
# ignore comments
if line.startswith('##'):
word, phones = line.split(' ')
syll = phones.split(' - ')
syllable_dict[word] = syll
print 'error parsing word ' + word
print syllable_dict['the']
print syllable_dict['beautiful']
print syllable_dict['serious']
print syllable_dict['seriously']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.