Skip to content

Commit

Permalink
upload a syllable dictionary and code that will spit out the number o…
Browse files Browse the repository at this point in the history
…f syllables in a single word
  • Loading branch information
vmwyatt authored Apr 18, 2019
1 parent 971cb7c commit dbefb29
Show file tree
Hide file tree
Showing 2 changed files with 133,884 additions and 0 deletions.
30 changes: 30 additions & 0 deletions syllable_breakdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Syllable Counter
file referenced is a version of a dictionary from a CMU pronnunciation guide:
http://www.speech.cs.cmu.edu/cgi-bin/cmudict?in=software+design+is+hard&stress=-s
Madi Wyatt
"""

import string

#initialize the dictionary and open the CMU dictionary file
pronnunciation_dict = open("syllable_dict.txt", "r")
words = dict()

#breakdown CMU dictionary and make a new one that gives us just the syllable count
for word_entry in pronnunciation_dict:
word_list = word_entry.split()
words[word_list[0]] = "".join(word_list[1:])
count = 0
for i in range(0, len(words[word_list[0]])):
if words[word_list[0]][i] in string.digits:
count += 1
words[word_list[0]] = count

#write a function that allows you to imput a word and the syllable count is output
def syllable_count(word):
return words[word.upper()]

print(syllable_count("hello"))
Loading

0 comments on commit dbefb29

Please sign in to comment.