Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meooow25/syllable
A Python library to count syllables in English
https://github.com/meooow25/syllable
python syllable
Last synced: 8 days ago
JSON representation
A Python library to count syllables in English
- Host: GitHub
- URL: https://github.com/meooow25/syllable
- Owner: meooow25
- License: mit
- Created: 2020-09-28T19:17:27.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-13T16:05:42.000Z (almost 4 years ago)
- Last Synced: 2023-04-03T21:42:20.250Z (over 1 year ago)
- Topics: python, syllable
- Language: Jupyter Notebook
- Homepage:
- Size: 521 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# syllable
A Python library to count syllables in EnglishThis is a small fun project to count syllables and detect syllable patterns, inspired by [u/haikusbot](https://www.reddit.com/r/haikusbot/).
The library uses a model trained on the [CMUdict](https://github.com/cmusphinx/cmudict/) dictionary of pronunciations, and has an accuracy of ~95%.
The model is intentionally small in size, so that it can run fast.The model is probably terrible for non-English words.
```py
>>> from syllable import CmudictSyllableCounter, ModelSyllableCounter
>>> csc, msc = CmudictSyllableCounter(), ModelSyllableCounter()
>>> csc.count_syllables('family')
(2, 3)
>>> msc.count_syllables('family')
(3,)
>>>
>>> from syllable import CompositeSyllableCounter, SyllablePatternMatcher
>>> comp = CompositeSyllableCounter([csc, msc])
>>> matcher = SyllablePatternMatcher(comp, (5, 7, 5)) # or SyllablePatternMatcher.haiku(comp)
>>> matcher.match("family can be two or three syllables, but thisweirdword's just three")
[['family', 'can', 'be'], ['two', 'or', 'three', 'syllables,', 'but'], ["thisweirdword's", 'just', 'three']]