Python Chinese Pronounce
- 文字轉注音、漢語發音
- 注音、漢語發音轉文字
- 尋找相似、相同發聲字/單詞
資料來源:政府開放資料, 超齊百萬字典檔, 教育部國語辭典公眾授權網
Install
From PyPI
pip install py-chinese-pronounce
From Repo
pip install -U git+https://github.com/p208p2002/py-chinese-pronounce.git
Usage
from py_chinese_pronounce import Word2Pronounce,Pronounce2Word
w2p = Word2Pronounce()
p2w = Pronounce2Word()
Word2Pronounce
字元轉注音
w2p.to_chewin("我") # ㄨㄛˇ
字元轉漢語發音
w2p.to_han("我") # wo3
句子轉注音
w2p.sent_to_chewin("你來扮演這個角色")
# ['ㄋㄧˇ', 'ㄌㄞˊ', 'ㄅㄢˋ', 'ㄧㄢˇ', 'ㄓㄜˋ', '˙ㄍㄜ', 'ㄐㄩㄝˊ', 'ㄙㄜˋ']
句子轉漢語發音
w2p.sent_to_han("你來扮演這個角色")
# ['ni3', 'lai2', 'ban4', 'yan3', 'zhe4', 'ge5', 'jue2', 'se4']
感謝 @Evanston0624 實作此功能
發音相似度比較
w2p.char_pronounce_similar(a,b)
w2p.sent_pronounce_similar(sent_a, sent_b)
# 數值區間落在[0-1]
其他轉換
- Word2Pronounce._word2unicode(self, x)
- Word2Pronounce._uni2word(self,uni)
- Word2Pronounce._cns2word(self,cns)
- Word2Pronounce._uni2cns(self, uni)
CNS: 中文標準交換碼
Pronounce2Word
注音找字元
p2w.chewin2word("ㄨㄛˇ")
# ['䰀', '婑', '捰', '㦱', '我', '䂺']
漢語發音找字元
p2w.han2word("wo3")
# ['䰀', '婑', '捰', '㦱', '我', '䂺']
字元找同發音
p2w.find_same("我")
# ['䰀', '婑', '捰', '㦱', '䂺']
字元找近似發音
p2w.find_similar("我")
# ['蠖', '臥', '䇶', '䂺', '䪝', '捾', '偓', '握', '捰', '卧', '雘', '㦱', '濣', '䠎', '楃', '沃', '渥', '䁊', '涴', '幄', '龌', '㓇', '矱', '斡', '㠛', '肟', '齷', '仴', '䰀', '婑', '喔', '腛', '䀑']
相似發聲詞
p2w.find_similar_vocab("汽車") # 去除聲調找相似
# ['七尺', '棋車', '棋车', '气车', '氣車', '汽车', '騎車', '骑车']
p2w.find_similar_vocab_level("清晨",level=1) # 發音編輯距離找相似
# ['傾城', '清城', '清澄', '青城', '清淳', '清純', '清纯', '清醇', '清神', '青神', '星塵', ...
相同發聲詞
p2w.find_same_vocab("汽車")
# ['气车', '氣車', '汽车']
其他轉換
-
Pronounce2Word._find_similar_han_pronounces(self,han,level=1)
尋找相似發音
- han: 漢語發音
- level: 編輯距離(越大越寬鬆)
Metadata
Release files for py-chinese-pronounce 0.1.14
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 | Actions |
|---|---|---|---|---|
| py_chinese_pronounce-0.1.14.tar.gz | 19.2 MB | Without provenance | Details for py_chinese_pronounce-0.1.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_chinese_pronounce-0.1.14-py3-none-any.whl | Python 3 | none | any | Details for py_chinese_pronounce-0.1.14-py3-none-any.whl |
Total release size: 38.4 MB
Release files / py_chinese_pronounce-0.1.14.tar.gz
| Download URL | py_chinese_pronounce-0.1.14.tar.gz |
|---|---|
| Size | 19.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff81666e813e7b48aba96638c451765d5449dbe1721ae40148e87b26c31f66ef
|
|
BLAKE2b-256 checksum How to use checksums |
7843aee4eb0f5bd2771068e12c5b6f4417ec30c93fdbcb38db4e6dc80f4b9695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.13 Linux/6.5.0-1022-azure
|
Release files / py_chinese_pronounce-0.1.14-py3-none-any.whl
| Download URL | py_chinese_pronounce-0.1.14-py3-none-any.whl |
|---|---|
| Size | 19.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c53e7e42b106e7686879a487349ddc50473c904c45610e889325e84fd09e7b17
|
|
BLAKE2b-256 checksum How to use checksums |
cffa55c49602843699d17a0e233f091140749bf62385b67f16e8654426a8cc48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.13 Linux/6.5.0-1022-azure
|
Security for py-chinese-pronounce 0.1.14
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.