Last active
July 18, 2023 12:57
-
-
Save jeffThompson/26396f49a127c85171b3f52c92794a08 to your computer and use it in GitHub Desktop.
Splits a word into syllables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
SPLIT SYLLABLES | |
Jeff Thompson | 2016 | jeffreythompson.org | |
Requires this modified version of the CMU Pronouncing | |
dictionary by Susan Bartlett, Grzegorz Kondrak and Colin Cherry: | |
https://webdocs.cs.ualberta.ca/~kondrak/cmudict.html | |
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('##'): | |
continue | |
try: | |
word, phones = line.split(' ') | |
syll = phones.split(' - ') | |
syllable_dict[word] = syll | |
except: | |
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