A tool for translating Persian text to IPA (International Phonetic Alphabet)A small example package
Project description
persian_phonemizer
A tool for translating Persian text to IPA (International Phonetic Alphabet).
In Persian, one written word can have different pronunciations and different meanings according to the pronunciation. This library helps with disambiguation of such words.
A few examples of use cases of this library are:
- Input for TTS systems
- Helping people in learning Persian
- Adding pronunciation for Persian words in texts of other languages
Installation
pip install persian_phonemizer
Usage
Fast start:
>>> from persian_phonemizer import Phonemizer
>>> phonemizer = Phonemizer()
>>> phonemizer.phonemize("آن مرد مرد.")
'ʔɒːn mæɾd moɾd .'
>>> phonemizer.phonemize("دوچرخه جدید علی گم شد.")
'dovtʃʰæɾxeje dʒædiːde ʔæliː ɡom ʃod .'
you can set the package to output Persian text with eraab instead of IPA:
>>> phonemizer = Phonemizer(output_format='eraab')
>>> phonemizer.phonemize("آن مرد مرد.")
'آن مَرد مُرد .'
What's inside?
- A database containing words, part-of-speech, pronunciation and meaning according to Moen dictionary
- script for parsing Dehkhoda dictionary is available in the dataset directory. Still, the results are not used in the package because some pronunciations are outdated and will do more harm than good.
- A Part-of-Speech tagger and a Dependency Parser trained on Universal Dependencies dataset using spaCy
- A Grapheme to Phoneme model using a seq-to-seq neural network implemented in Pytorch. More info is provided in g2p_fa repo. These assets were created to be used in this repo but each one has the ability to be used separately.
How does it work?
This package uses several approaches for finding the proper pronunciation.
- Input text gets normalized and tokenized
- Root word for each word in input is calculated using a lemmatizer to cover complex verbs and nouns
- Each word is looked up for pronunciations in the database.
- If there is no pronunciation available, pronounce is predicted using g2p_fa.
- If there is one pronunciation, that one is used.
- If there is more than one pronunciation, the correct one is chosen based on the Part-of-Speech tag for that word.
- Suffix and prefix pronunciations are added for each word
- Add
eorjebetween words when needed using the dependency parser
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file persian_phonemizer-0.4.0-py3-none-any.whl.
File metadata
- Download URL: persian_phonemizer-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d21fb92eb5577f082e6b0872428e89489911e639331fef32a92bfea454d25c2
|
|
| MD5 |
f0e49451d76dce42ced0ef1d0a1282a5
|
|
| BLAKE2b-256 |
65d47050f5fd7bed93c43561dfcdd2aaa779768ee5a68c96a17a8d7ed5de4d21
|