Skip to main content

A tokenizer, text cleaner, and phonemizer for many human languages.

Project description

Gruut

A tokenizer, text cleaner, and phonemizer for many human languages.

Useful for transforming raw text into phonetic pronunciations, similar to phonemizer. Unlike phonemizer, gruut looks up words in a pre-built lexicon (pronunciation dictionary) or guesses word pronunciations with a pre-trained grapheme-to-phoneme model. Phonemes for each language come from a carefully chosen inventory.

For each supported language, gruut includes a:

Supported Languages

gruut currently supports:

  • U.S. English (en-us)
  • Dutch (nl)
  • Czech (cs-cz)

The goal is to support all of voice2json's languages

Dependencies

  • Python 3.7 or higher
  • Linux
    • Test on Debian Buster
  • Babel and num2words
    • Currency/number handling
  • gruut-ipa
    • IPA pronunciation manipulation
  • phonetisaurus
    • Guessing word pronunciations outside lexicon

Installation

$ pip install gruut

for Raspberry Pi (ARM), you will first need to manually install phonetisaurus.

Usage

The gruut module can be executed with python3 -m gruut <COMMAND> <ARGS>

The commands are line-oriented, consuming/producing either text or JSONL. They can be composed to produce a pipeline for cleaning text.

You will probably want to install jq to manipulate the JSONL output from gruut.

tokenize

Takes raw text and outputs JSONL with cleaned words/tokens.

$ echo 'This, right here, is some RAW text!' \
    | python3 -m gruut en-us tokenize \
    | jq -c .clean_words
["this", ",", "right", "here", ",", "is", "some", "raw", "text", "!"]

See python3 -m gruut <LANGUAGE> tokenize --help for more options.

phonemize

Takes JSONL output from tokenize and produces JSONL with phonemic pronunciations.

$ echo 'This, right here, is some RAW text!' \
    | python3 -m gruut en-us tokenize \
    | python3 -m gruut en-us phonemize \
    | jq -c .pronunciation_text
ð ɪ s | ɹ  t h  ɹ | ɪ z s ʌ m ɹ ɑː t ɛ k s t 

See python3 -m gruut <LANGUAGE> phonemize --help for more options.

phones2phonemes

Takes IPA pronunciations (one per line) and outputs JSONL with phonemes and their descriptions.

$ echo '/ˈt͡ʃuːz/' \
    | python3 -m gruut en-us phones2phonemes --keep-stress \
    | jq .phonemes
[
  {
    "text": "t͡ʃ",
    "letters": "t͡ʃ",
    "example": "[ch]in",
    "stress": "primary",
    "type": "Consonant",
    "place": "post-alveolar",
    "voiced": false,
    "nasalated": false,
    "elongated": false
  },
  {
    "text": "uː",
    "letters": "u",
    "example": "s[oo]n",
    "stress": "none",
    "height": "close",
    "placement": "back",
    "rounded": true,
    "type": "Vowel",
    "nasalated": false,
    "elongated": true
  },
  {
    "text": "z",
    "letters": "z",
    "example": "[z]ing",
    "stress": "none",
    "type": "Consonant",
    "place": "alveolar",
    "voiced": true,
    "nasalated": false,
    "elongated": false
  }
]

See python3 -m gruut <LANGUAGE> phones2phonemes --help for more options.

coverage

Takes JSONL from from phonemize and outputs a coverage report for all singleton and phoneme pairs.

$ echo 'The quick brown fox jumps over the lazy dog.' \
    | python3 -m gruut en-us tokenize \
    | python3 -m gruut en-us phonemize \
    | python3 -m gruut en-us coverage \
    | jq -c .coverage
{"single":0.6190476190476191,"pair":0.021386430678466076}

With multiple sentences:

$ cat << EOF |
The birch canoe slid on the smooth planks.
Glue the sheet to the dark blue background.
It's easy to tell the depth of a well.
These days a chicken leg is a rare dish.
Rice is often served in round bowls.
The juice of lemons makes fine punch.
The box was thrown beside the parked truck.
The hogs were fed chopped corn and garbage.
Four hours of steady work faced us.
Large size in stockings is hard to sell.
EOF
    python3 -m gruut en-us tokenize \
    | python3 -m gruut en-us phonemize \
    | python3 -m gruut en-us coverage \
    | jq -c .coverage
{"single":0.8809523809523809,"pair":0.1364306784660767}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gruut-0.2.1.tar.gz (24.8 MB view details)

Uploaded Source

File details

Details for the file gruut-0.2.1.tar.gz.

File metadata

  • Download URL: gruut-0.2.1.tar.gz
  • Upload date:
  • Size: 24.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for gruut-0.2.1.tar.gz
Algorithm Hash digest
SHA256 37f06c2d8228cf33b4664a0d957b4066bdd8c3e7025ec28650d10b56de3860fd
MD5 a938d676e1f429889bc85bc65fb23cdc
BLAKE2b-256 9d3f28b4146581fffc33d58abd973a95d421fda274871141f557d106e710bb74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page