wangchou/SwiftSyllables

Syllable counter for iOS apps.


License
MIT

Documentation

SwiftSyllables

Version License Platform

A lightweight syllable counter written in Swift.

Background

Syllable counting does not have a simple algorithmic solution so this framework takes a combination of dictionary lookups and heuristics, in two parts:

(1) Python's Natural Language Toolkit includes a wide range of corpus for language processing. Python NLTK takes advantage of the CMU Pronunciation Dictionary which contains pronounciation transcriptions for over 100,000 words. If the word is found within the pronunciation dictionary, the first valid pronunciation is used to find the number of syllables.

(2) If the word is not found within the pronunciation dictionary, SwiftSyllables defaults to a heuristic solution. We used a straightforward implementation of Emre Aydin's heuristic syllable counting algorithm.

The current most robust algorithmic solution to syllable counting is Frank Liang's Stanford PhD dissertation -- the implementation of the algorithm for this framework is not currently planned.

Requirements

Uses Swift 3.0, run on Xcode 8.

Installation

SwiftSyllables is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftSyllables"

Example

SwiftSyllables currently has one simple API for getting the syllable count from a string:

open class func getSyllables(_ string: String) -> Int

Simply import the framework and call the getSyllables method.

import SwiftSyllables

...

var syllables : Int = SwiftSyllables.getSyllables(string)

To run the example project, clone the repo, and run pod install from the Example directory first.

Author

License

SwiftSyllables is available under the MIT license. See the LICENSE file for more info.

Acknowledgments