Metadata-Version: 2.4
Name: pyenglish2pinyin
Version: 0.1.1
Summary: Convert English words to numbered Pinyin using CMUdict IPA.
Author: Davy Chen
License-Expression: MIT
Project-URL: Homepage, https://coderhome.com/
Project-URL: Repository, https://github.com/davychxn/PYENGLISH2PINYIN
Keywords: english,pinyin,ipa,cmudict,pronunciation
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Dynamic: license-file

# PYENGLISH2PINYIN

[English](README.md) | [中文](README.cn.md) | [Français](README.fr.md)

Convert English words to numbered Pinyin(mandarin/chinese phonetic system) through CMUdict IPA.

## Input and Output Examples

### English word to Pinyin (12 verified examples)

| English Word | Pinyin Output |
|---|---|
| record | ruo5 kao1 r5 de5 |
| communication | ka5 mu5 yu4 na5 kui1 sha5 en5 |
| in | yi5 en5 |
| securing | xi5 ke5 yu1 rui5 eng5 |
| prime | po5 ruo1 mu5 |
| foreign | fan1 ruo5 en5 |
| aldinger | ao1 ao5 di5 eng5 r5 |
| engleman | yi1 eng5 a5 ao5 ma5 en5 |
| legacy | lai1 ga5 xi5 |
| blotting | bo5 la1 ti5 eng5 |
| english | yi1 eng5 ge5 li5 shi5 |
| banana | ba5 nai1 na5 |

### IPA to Pinyin

| IPA Input | Pinyin Output |
|---|---|
| AE2 P L AH0 K EY1 SH AH0 N | ai4 po5 la5 kui1 sha5 en5 |
| S IH0 K Y UH1 R IH0 NG | xi5 ke5 yu1 rui5 eng5 |
| L EH1 G AH0 S IY0 | lai1 ga5 xi5 |

This is especially helpful when training FastSpeech2 speech synthesis for mixed Chinese and English text, because it reduces dataset preparation effort for text normalization and phoneme alignment while keeping pronunciation labels consistent.

## Install

```bash
pip install pyenglish2pinyin
```

## Usage

```python
from english2pinyin import english2ipa, english2pinyin, ipa2pinyin

print(english2ipa("application"))
# AE2 P L AH0 K EY1 SH AH0 N

print(english2pinyin("application"))
# ai4 po5 la5 kui1 sha5 en5

print(ipa2pinyin("S IH0 K Y UH1 R IH0 NG"))
# xi5 ke5 yu1 rui5 eng5
```

## API

- `english2ipa(word, dict_path=None)` -> `str | None`
- `english2pinyin(word, dict_path=None, throw_if_missing=False)` -> `str`
- `ipa2pinyin(ipa_text)` -> `str`

## Development

```bash
pip install -e .[dev]
pytest
```
