Lightweight library to count syllables in words, based on the excellent Java implementation found at https://github.com/m09/syllable-counter
Swift 5.3 or newer on macOS or Linux.
Add the following dependency to your project's Package.swift
:
.package(url: "https://github.com/wfreitag/syllable-counter-swift.git", .revision("08cd024da5f30ac32939e718a2a964445a4aab4a"))
SyllableCounter uses a shared instance that is initialized on first use.
There is one public method: count()
, which takes a string.
let syllableCount = SyllableCounter.shared.count(word: "wonderful")
print("There are \(syllableCount) syllables in 'wonderful'.")
... or you can use the extension on String
:
let syllableCount = "wonderful".syllables
print("There are \(syllableCount) syllables in 'wonderful'.)
The original Java implementation has a caching option. This feature was not ported over to this implementation.
Licensed under the Apache 2.0 License. Feel free to use and modify according to the terms expressed in the license. Contributions welcome.