Phonemize
Phonemize is a multilingual grapheme-to-phoneme (G2P) conversion library built with Transformer models. It’s designed for high accuracy, fast inference, and simple integration into text-to-speech (TTS) or other speech-related systems.
Key Features
- Easy-to-use API: A simple interface for both training and inference.
- Multilingual Support: Train a single model on multiple languages.
- High Performance: Fast and accurate predictions powered by Transformer models.
- Custom Training: Effortlessly train your own models in just a few lines of code.
- Optimized for TTS: Ideal for both real-time and offline text-to-speech pipelines.
Installation
To install Phonemize, use the following command:
pip install phonemize
To train your own models, install the full package with all training dependencies:
Quickstart
Load a pre-trained model and perform phoneme prediction with this simple example:
from phonemize import Phonemizer
# Load the pre-trained model from a checkpoint
phonemizer = Phonemizer.from_checkpoint("phonemize_m1.pt")
# Phonemize an English text
result = phonemizer("Phonemizing an English text is imposimpable!", lang="en_us")
# Print the result
print(result)
Output:
foʊnɪmaɪzɪŋ æn ɪŋglɪʃ tɛkst ɪz ɪmpəzɪmpəbəl!
Training Your Own Model
You can easily train your own forward or autoregressive Transformer model. All configuration parameters are defined in a simple YAML file (e.g., configs/forward.yaml).
from phonemize.preprocess import preprocess
from phonemize.train import train
# Define your training data
train_data = [
("en_us", "young", "jʌŋ"),
("de", "benützten", "bənʏt͡stn̩")
] * 1000
# Define your validation data
val_data = [
("en_us", "young", "jʌŋ"),
("de", "benützten", "bənʏt͡stn̩")
] * 100
# Specify the configuration file
config_file = "configs/forward.yaml"
# Preprocess the data
preprocess(
config_file=config_file,
train_data=train_data,
val_data=val_data,
deduplicate_train_data=False
)
# Train the model
train(rank=0, num_gpus=1, config_file=config_file)
Checkpoints will be saved in the directory specified in your configuration file.
Inference Example
To perform inference with your trained model:
from phonemize import Phonemizer
# Load your custom model from a checkpoint
phonemizer = Phonemizer.from_checkpoint("checkpoints/best_model.pt")
# Get the phonemes for a given text
phonemes = phonemizer("Phonemizing text is simple!", lang="en_us")
print(phonemes)
To inspect detailed predictions, including confidence scores:
result = phonemizer.phonemise_list(["Phonemizing text is simple!"], lang="en_us")
for word, pred in result.predictions.items():
print(f"Word: {word}, Phonemes: {pred.phonemes}, Confidence: {pred.confidence}")
TorchScript Export
For optimized performance, you can easily export your trained Transformer model to TorchScript:
import torch
from phonemize import Phonemizer
# Load the model from a checkpoint
phonemizer = Phonemizer.from_checkpoint("checkpoints/best_model.pt")
# Convert the model to a TorchScript module
scripted_model = torch.jit.script(phonemizer.predictor.model)
phonemizer.predictor.model = scripted_model
# Run inference with the TorchScript model
phonemizer("Running the TorchScript model!")
Pre-trained Models
This model has been modified for the phonemize library.
| Model | Language | Dataset | Repo Version |
|---|---|---|---|
| phonemize_m1 | en_us | cmudict | 0.1.0 |
Acknowledgment
Phonemize is inspired by DeepPhonemizer, and has been refactored and optimized for simplicity, speed, and modern Python environments.
License
This project is released under the MIT License.
Phonemize is compatible with Python 3.8+ and distributed under the MIT license. Learn more at: https://github.com/arcosoph/phonemize
Metadata
Release files for phonemize 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| phonemize-0.2.4.tar.gz | 27.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phonemize-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.8 kB
Release files / phonemize-0.2.4.tar.gz
| Download URL | phonemize-0.2.4.tar.gz |
|---|---|
| Size | 27.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
534568a49abb1552731d7bf3557c7563c4ed6bf4646f82abf0045c6b3bc82c43
|
|
BLAKE2b-256 checksum How to use checksums |
af6458c19730843923ad0f421e469fa7780345c9693169f5325559248250f33a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / phonemize-0.2.4-py3-none-any.whl
| Download URL | phonemize-0.2.4-py3-none-any.whl |
|---|---|
| Size | 35.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61eca8467ea2e474bfcaa876105d9e6909539517b81a5aa7df407461647b07ed
|
|
BLAKE2b-256 checksum How to use checksums |
822a63c5d293eadbf313a3914bbf39ebbb01cd8db4f70d9f64542a1888b24abf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for phonemize 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.