Skip to main content

word-to-pronunciation

PyPI PyPI MIT

Python library to help with looking up words that contain punctuation and hyphens.

Installation

pip install word-to-pronunciation

Usage

>>> from collections import OrderedDict
>>> from pronunciation_dictionary import Pronunciations, Word
>>> from word_to_pronunciation import Options, get_cached_lookup, get_pronunciations_from_word

>>> def lookup(word: Word) -> Pronunciations:
...   print(f"Trying to lookup: '{word}' ...")
...   if word == "test":
...     result = OrderedDict((
...       (("T", "E0", "S", "T"), 0.7),
...       (("T", "E1", "S", "T"), 0.3),
...     ))
...     print("Found pronunciations!")
...     return result
...   print("Found no pronunciations!")
...   return OrderedDict()

>>> options = Options(
...   trim_symbols="\".",
...   split_on_hyphen=True,
...   try_without_trimming=True,
...   try_without_splitting=True,
...   default_weight=1.0
... )

>>> cache = {}
>>> lookup_method = get_cached_lookup(lookup, cache)

>>> word = "\"test-test\"."
>>> result = get_pronunciations_from_word(word, lookup_method, options)
Trying to lookup: '"test-test".' ...
Found no pronunciations!
Trying to lookup: 'test-test' ...
Found no pronunciations!
Trying to lookup: 'test' ...
Found pronunciations!

>>> for pronunciation, weight in result.items():
...   print(f"{word} => /{'|'.join(pronunciation)}/ {weight}")
"test-test". => /"|T|E0|S|T|-|T|E0|S|T|"|./ 0.48999999999999994
"test-test". => /"|T|E0|S|T|-|T|E1|S|T|"|./ 0.21
"test-test". => /"|T|E1|S|T|-|T|E0|S|T|"|./ 0.21
"test-test". => /"|T|E1|S|T|-|T|E1|S|T|"|./ 0.09

>>> print(cache)
{'"test-test".': OrderedDict(), 'test-test': OrderedDict(), 'test': OrderedDict([(('T', 'E0', 'S', 'T'), 0.7), (('T', 'E1', 'S', 'T'), 0.3)])}

Release files for word-to-pronunciation 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for word-to-pronunciation 0.0.1
File Size Uploaded
word-to-pronunciation-0.0.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for word-to-pronunciation 0.0.1
File Interpreter ABI Platform
word_to_pronunciation-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / word-to-pronunciation-0.0.1.tar.gz

Download URL word-to-pronunciation-0.0.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fd7dd0cea5dbec13e730f1c1a8a879e62b455197a1197d7e708a5c683d605198
BLAKE2b-256 checksum
How to use checksums
32360b5386a7c94717c7acdbfe531cf68b71d4dc99c164a4fce93b4d52e49a16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / word_to_pronunciation-0.0.1-py3-none-any.whl

Download URL word_to_pronunciation-0.0.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c38ac6553a908c00b98dddd283174218d5618b6964466e80cb7e113e148722ce
BLAKE2b-256 checksum
How to use checksums
b38f5222f2ca7a642396f9609d4edd5adeae046b3a29c651a73dfa9bf2f2efb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page