dict-from-pypinyin 0.0.2
Command-line interface (CLI) to create a pronunciation dictionary by looking up pinyin transcriptions using pypinyin including the possibility of ignoring punctuation and splitting words on hyphens before transcribing them.
License: MIT
Requires Python: <3.13,>=3.8
Keywords: Pronunciation,Dictionary,Chinese,Language,Pinyin,Speech Synthesis,TTS,Linguistics

# dict-from-pypinyin

[![PyPI](https://img.shields.io/pypi/v/dict-from-pypinyin.svg)](https://pypi.python.org/pypi/dict-from-pypinyin)
[![PyPI](https://img.shields.io/pypi/pyversions/dict-from-pypinyin.svg)](https://pypi.python.org/pypi/dict-from-pypinyin)
[![MIT](https://img.shields.io/github/license/stefantaubert/dict-from-pypinyin.svg)](https://github.com/stefantaubert/dict-from-pypinyin/blob/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/wheel/dict-from-pypinyin.svg)](https://pypi.python.org/pypi/dict-from-pypinyin)
[![PyPI](https://img.shields.io/pypi/implementation/dict-from-pypinyin.svg)](https://pypi.python.org/pypi/dict-from-pypinyin)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10554720.svg)](https://doi.org/10.5281/zenodo.10554720)

Command-line interface (CLI) to create a pronunciation dictionary by looking up pinyin transcriptions using [pypinyin](https://github.com/mozillazg/python-pinyin) including the possibility of ignoring punctuation and splitting words on hyphens before transcribing them.

## Installation

```sh
pip install dict-from-pypinyin --user
```

## Usage

```sh
dict-from-pypinyin-cli
```

### Example

```sh
# Create example vocabulary
cat > /tmp/vocabulary.txt << EOF
社会语言学？
㐻，
『㑐
鲜-亮。
『占斌？
『机具-机呀？
EOF

# Create dictionary from vocabulary
dict-from-pypinyin-cli \
  /tmp/vocabulary.txt \
  /tmp/result.dict \
  --split-on-hyphen

cat /tmp/result.dict
```

Output:

```txt
社会语言学？  shè huì yǔ yán xué ？
社会语言学？  shè huì yǔ yàn xué ？
社会语言学？  shè huì yǔ yín xué ？
社会语言学？  shè huì yù yán xué ？
社会语言学？  shè huì yù yàn xué ？
社会语言学？  shè huì yù yín xué ？
社会语言学？  shè kuài yǔ yán xué ？
社会语言学？  shè kuài yǔ yàn xué ？
社会语言学？  shè kuài yǔ yín xué ？
社会语言学？  shè kuài yù yán xué ？
社会语言学？  shè kuài yù yàn xué ？
社会语言学？  shè kuài yù yín xué ？
㐻，  nèi ，
『㑐  『 shū
鲜-亮。  xiān - liàng 。
鲜-亮。  xiān - liáng 。
鲜-亮。  xiǎn - liàng 。
鲜-亮。  xiǎn - liáng 。
『占斌？  『 zhàn bīn ？
『占斌？  『 zhān bīn ？
『占斌？  『 tiē bīn ？
『机具-机呀？  『 jī jù - jī ya ？
『机具-机呀？  『 jī jù - jī yā ？
『机具-机呀？  『 jī jù - jī xiā ？
『机具-机呀？  『 jī jù - wèi ya ？
『机具-机呀？  『 jī jù - wèi yā ？
『机具-机呀？  『 jī jù - wèi xiā ？
『机具-机呀？  『 wèi jù - jī ya ？
『机具-机呀？  『 wèi jù - jī yā ？
『机具-机呀？  『 wèi jù - jī xiā ？
『机具-机呀？  『 wèi jù - wèi ya ？
『机具-机呀？  『 wèi jù - wèi yā ？
『机具-机呀？  『 wèi jù - wèi xiā ？
```

## Development setup

```sh
# update
sudo apt update
# install Python 3.8, 3.9, 3.10 & 3.11 for ensuring that tests can be run
sudo apt install python3-pip \
  python3.8 python3.8-dev python3.8-distutils python3.8-venv \
  python3.9 python3.9-dev python3.9-distutils python3.9-venv \
  python3.10 python3.10-dev python3.10-distutils python3.10-venv \
  python3.11 python3.11-dev python3.11-distutils python3.11-venv \
  python3.12 python3.12-dev python3.12-distutils python3.12-venv
# install pipenv for creation of virtual environments
python3.8 -m pip install pipenv --user

# check out repo
git clone https://github.com/stefantaubert/dict-from-pypinyin.git
cd dict-from-pypinyin
# create virtual environment
python3.8 -m pipenv install --dev
```

## Running the tests

```sh
# first install the tool like in "Development setup"
# then, navigate into the directory of the repo (if not already done)
cd dict-from-pypinyin
# activate environment
python3.8 -m pipenv shell
# run tests
tox
```

Final lines of test result output:

```log
  py38: commands succeeded
  py39: commands succeeded
  py310: commands succeeded
  py311: commands succeeded
  py312: commands succeeded
  congratulations :)
```

## License

MIT License

## Acknowledgments

[pypinyin](https://github.com/mozillazg/python-pinyin)

Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – Project-ID 416228727 – CRC 1410

## Citation

If you want to cite this repo, you can use this BibTeX-entry generated by GitHub (see *About => Cite this repository*).

```txt
Taubert, S. (2024). dict-from-pypinyin (Version 0.0.2) [Computer software]. https://doi.org/10.5281/zenodo.10554720
```