<p>There are several libraries for converting Chinese characters to pinyin. If you are comfortable with programming languages (which you probably are if you are asking for an API), your choice will depend on the programming languages you know, the quality of the library and the licence under which it is available. If you need a user interface, you should probably first look at pinyin4j and ZDT. </p>

<ul>
<li><strong><a href="https://github.com/YangKuang/pinyin4net" rel="noreferrer">pinyin4net</a></strong>: C# library that supports both simplified and traditional Chinese characters. Output is hanyu pinyin. Licence: MIT. </li>
<li><strong><a href="https://github.com/kimziv/PinYin4Objc" rel="noreferrer">PinYin4Objc</a></strong>: Objective-C library (with some Ruby) that supports both simplified and traditional Chinese characters and most popular pinyin systems. Licence: Apache License 2.0.</li>
<li><strong><a href="https://github.com/teambition/HanziPinyin" rel="noreferrer">HanziPinyin</a></strong>: Swift library that supports both simplified and traditional Chinese characters. Licence: MIT License. </li>
<li><strong><a href="https://github.com/pilgr/PiPinyin" rel="noreferrer">PiPinyin</a></strong>: Java library for Android for converting Chinese characters to pinyin. I assume it supports simplified characters but could not find out if it also supports traditional characters. (The older <a href="https://code.google.com/archive/p/pinyin4android/" rel="noreferrer">pinyin4android</a> library, on which PiPinyin is based, appears to have no documentation.) Licence: Apache License 2.0.</li>
<li><strong><a href="https://github.com/handsomezhou/pinyin4cpp" rel="noreferrer">pinyin4cpp</a></strong>: C++ library. Licence: Apache License 2.0. (Possibly inspired by pinyin4j, below.)</li>
<li><strong><a href="http://pinyin4j.sourceforge.net/" rel="noreferrer">pinyin4j</a></strong>: Java library for conversion "between Chinese characters and most popular Pinyin systems". Can also ouput Wade-Giles, Yale and Gwoyeu Romatzyh! Licence: GPL v2.</li>
<li><strong><a href="http://www.sinologia.info/unihanconver/" rel="noreferrer">Unihanconver</a></strong>: a Perl library "to convert between Traditional/Simplified Chinese directly in Unicode (not GB/Big5 conversion)". It can be used through a Gtk2+ Interface and from the console. (See also the <a href="https://sourceforge.net/projects/unihanconver/" rel="noreferrer">developer site</a>.) Licence: GPL 2. </li>
<li><strong><a href="http://zdt.sourceforge.net/" rel="noreferrer">ZDT (Zhongwen Development Tool)</a></strong>, written in Java, "is an easy to use, open-source Mandarin Chinese flashcard application that can help you learn Chinese". One of its features is conversion between Chinese charactes and pinyin. (<a href="https://sourceforge.net/projects/zdt/" rel="noreferrer">Developer site</a>.) Licence: Eclipse Public License. </li>
<li><strong><a href="https://sourceforge.net/projects/zh2tone/" rel="noreferrer">zh2tone / Chinese Word to ZuYin Code</a></strong>: a tool to convert Chinese characters/words to zhuyin fuhao (bopomofo). The tool has not been updated since 2012, has no licence, ... </li>
</ul>

<p>Notes: </p>

<ul>
<li>I have not checked the quality of these libraries (alpha/beta/production-ready, test coverage, etc.) nor their completeness (how many characters they support etc.). </li>
<li>If you need such a library for professional use, I would steer clear of libraries that have no licence. Software available under Apache 2.0, MIT or BSD can be reused both in open source and commercial applications. Libraries available under a GPL licence ("GNU General Public Licence") can only be used in other GPL code.</li>
</ul>

CC BY-SA 3.0
2017-01-18T20:37:31.633Z
I used pinyin4j in a production system and it gets the job done pretty well
blackgreen
CC BY-SA 3.0
2018-04-20T10:57:53.833Z
@TXV I have checked it out and it seems to be `char` based only. How to handle tokens and text?
loretoparisi
CC BY-SA 3.0
2018-04-21T14:32:19.370Z
The OP asked for a pinyin API. Tokenization in Chinese is an entirely different beast, maybe you should open a separate thread.
blackgreen
CC BY-SA 4.0
2020-03-08T10:36:04.000Z
@loretoparisi: apparently, for correctly handling segments you would need a segmenter such as https://github.com/huaban/jieba-analysis — I don't know the underlying approach, but have seen other libraries depending on it to do segmentation.
ccpizza
CC BY-SA 3.0
2016-09-02T16:34:04.970Z
2017-08-03T14:39:31.157Z
2017-08-03T14:39:31.157Z
Tsundoku
<p>if you have programming knowledge, you may download the 國語辭典 (of taiwan),  which is under creative commons 3.0</p>

<p><a href="http://resources.publicense.moe.edu.tw/dict_reviseddict_download.html" rel="noreferrer">http://resources.publicense.moe.edu.tw/dict_reviseddict_download.html</a></p>

<p>basically, it's 3 large excel files, using bash, grep, cut would give you relevant info of characters / words; and mandarin romanisation is one of them.</p>

<p>it's about 166000+ entries, that would be enough for "normal" usage.</p>

<p>have fun :)</p>

CC BY-SA 3.0
2016-09-02T09:31:45.440Z
2016-09-02T09:31:45.440Z
水巷孑蠻
<p>Glosbe seems to offer this service:</p>

<p><a href="https://glosbe.com/transliteration/api?from=Han&amp;dest=Latin&amp;text=%E4%BD%A0%E5%A5%BD&amp;format=json" rel="nofollow">https://glosbe.com/transliteration/api?from=Han&amp;dest=Latin&amp;text=你好&amp;format=json</a></p>

<pre><code>{"result":"ok","text":"nǐ hǎo"}
</code></pre>

<p><a href="https://glosbe.com/transliteration/api?from=Han&amp;dest=Latin&amp;text=%E9%BE%9C&amp;format=json" rel="nofollow">https://glosbe.com/transliteration/api?from=Han&amp;dest=Latin&amp;text=龜&amp;format=json</a></p>

<pre><code>{"result":"ok","text":"guī"}
</code></pre>

<p>In a very small experiment the service didn't seem so smart at distinguishing characters with multiple pronunciations:</p>

<p><a href="https://glosbe.com/transliteration/api?from=Han&amp;dest=Latin&amp;text=%E9%8A%80%E8%A1%8C&amp;format=json" rel="nofollow">https://glosbe.com/transliteration/api?from=Han&amp;dest=Latin&amp;text=銀行&amp;format=json</a></p>

<pre><code>{"result":"ok","text":"yín xíng"}
</code></pre>

<p>See the documentation at <a href="https://glosbe.com/a-api" rel="nofollow">https://glosbe.com/a-api</a></p>

<p><a href="https://cloud.google.com/translate/v2/quickstart" rel="nofollow">Google Translate API</a> might also offer what you're looking for (the console at <a href="http://translate.google.com" rel="nofollow">http://translate.google.com</a> does), but that service isn't free.</p>

CC BY-SA 3.0
2017-12-25T13:53:25.770Z
The Google Translate API does not seem to support pinyin.
Matt Zeunert
CC BY-SA 3.0
2016-09-03T21:39:19.840Z
2016-09-04T08:57:52.830Z
2016-09-04T08:57:52.830Z
Gareth
<p>It might be easier just to download <a href="https://www.mdbg.net/chindict/chindict.php?page=cc-cedict" rel="nofollow noreferrer">CC-CEDICT</a> in its entirety and look up your character in it. You can turn this into an API with very little effort.</p>

CC BY-SA 3.0
2017-01-19T11:39:55.980Z
2017-01-19T11:39:55.980Z
lsusr
<p>I created a python module which converts a whole sentence into Pinyin. It also supports Cantonese/Jyutping. There's an accompanying REST API: <a href="https://github.com/lucwastiaux/python-pinyin-jyutping-sentence" rel="nofollow noreferrer">https://github.com/lucwastiaux/python-pinyin-jyutping-sentence</a> . It attempts to separate the sentence into words (which I haven't seen other chinese-to-pinyin modules do), using the jieba library.</p>

<p><strong>Installing the module</strong></p>

<p><code>pip install pinyin_jyutping_sentence</code></p>

<p><strong>Mandarin / simplified characters</strong></p>

<pre><code>&gt;&gt;&gt; import pinyin_jyutping_sentence
&gt;&gt;&gt; pinyin_jyutping_sentence.pinyin("提高口语")
'tígāo kǒuyǔ'
</code></pre>

<p><strong>Cantonese / traditional characters</strong></p>

<pre><code>&gt;&gt;&gt; import pinyin_jyutping_sentence
&gt;&gt;&gt; pinyin_jyutping_sentence.jyutping("我出去攞野食")
'ngǒ cēothêoi ló jěsik'
</code></pre>

<p><strong>Calling the REST API</strong></p>

<p><strong>Mandarin</strong></p>

<pre><code>import requests
import json

url = "http://api.mandarincantonese.com/pinyin/办所有的事情"
response = requests.get(url)
print(json.loads(response.content)["pinyin"])
&gt;&gt;&gt; bàn suǒyǒu de shìqíng
</code></pre>

<p><strong>Cantonese</strong></p>

<pre><code># calling the API from python
import requests
import json

url = "http://api.mandarincantonese.com/jyutping/我哋盪失咗"
response = requests.get(url)
print(json.loads(response.content)["jyutping"])
&gt;&gt;&gt; ngǒ déi dongsāt zó
</code></pre>

CC BY-SA 4.0
2019-04-19T15:13:26.217Z
2019-04-19T15:13:26.217Z
Luc
<p>Why would you want to use an external API for static data that does not change over time? </p>

<p>The translation map is a constant, and all the libraries and services just wrap those maps. </p>

<p>As far as Chinese Traditional/Simplified to Pinyin goes there are a variety of free mappings available — here is one I've found to be the most complete and up-to-date which I 'ported' to javascript: <a href="https://github.com/glowinthedark/Simplified-and-Traditional-Chinese/blob/master/gb2312-big5/js/pinyin.js" rel="nofollow noreferrer">https://github.com/glowinthedark/Simplified-and-Traditional-Chinese/blob/master/gb2312-big5/js/pinyin.js</a> — this can be easily adapted to whatever programming language you need. </p>

<p>Or, as suggested in another answer, you can extract your own map from CEDICT.</p>

<h3>Python-based identifier and conversion tool</h3>

<ul>
<li><a href="https://github.com/tsroten/dragonmapper" rel="nofollow noreferrer">https://github.com/tsroten/dragonmapper</a></li>
</ul>

<h3>Ruby-based conversion tool:</h3>

<ul>
<li><a href="https://github.com/plexus/ting" rel="nofollow noreferrer">https://github.com/plexus/ting</a></li>
</ul>

<h3>Other resources</h3>

<p>The <a href="https://www.wechat.com/en/" rel="nofollow noreferrer">wechat app for android</a> comes with built-in conversion tables for chinese2pinyin and traditional2simplified which you can peek at by renaming the apk file to zip, unzipping it, and then looking under the <code>assets/fts</code> folder where you will find <code>fts_py.txt</code> and <code>fts_t2s.txt</code> corrrespondingly. (<em>Note that this might change in future versions.</em>)</p>

CC BY-SA 4.0
2019-12-06T07:23:21.990Z
2020-03-08T11:37:59.217Z
2020-03-08T11:37:59.217Z
ccpizza
<p>I was wondering if anyone here is aware of an API out there on the net anywhere that can receive a traditional character and send back the pinyin for it in JSON?</p>

CC BY-SA 3.0
2017-07-28T13:31:04.060Z
Out of curiosity: which approach or solution did you end up using?
Tsundoku
CC BY-SA 3.0
2017-07-28T15:49:25.083Z
None yet, I am busy with other projects at the moment.  This one is still in the idea stage :)
zeeple
<pinyin><traditional-characters>
API for transliterating a traditional character (writing the pinyin)?
# API for transliterating a traditional character (writing the pinyin)?

(Asked by: username_0 on 2016-09-02)

I was wondering if anyone here is aware of an API out there on the net anywhere that can receive a traditional character and send back the pinyin for it in JSON?

**Tags:** pinyin, traditional-characters

> **Comments:**
> **username_1**: Out of curiosity: which approach or solution did you end up using?  
> **username_0**: None yet, I am busy with other projects at the moment.  This one is still in the idea stage :)  

---

## 6 answers

### Answer by username_1 on 2016-09-02. Score: 10

There are several libraries for converting Chinese characters to pinyin. If you are comfortable with programming languages (which you probably are if you are asking for an API), your choice will depend on the programming languages you know, the quality of the library and the licence under which it is available. If you need a user interface, you should probably first look at pinyin4j and ZDT.

* **[pinyin4net](https://github.com/YangKuang/pinyin4net)**: C# library that supports both simplified and traditional Chinese characters. Output is hanyu pinyin. Licence: MIT.
* **[PinYin4Objc](https://github.com/kimziv/PinYin4Objc)**: Objective-C library (with some Ruby) that supports both simplified and traditional Chinese characters and most popular pinyin systems. Licence: Apache License 2.0.
* **[HanziPinyin](https://github.com/teambition/HanziPinyin)**: Swift library that supports both simplified and traditional Chinese characters. Licence: MIT License.
* **[PiPinyin](https://github.com/pilgr/PiPinyin)**: Java library for Android for converting Chinese characters to pinyin. I assume it supports simplified characters but could not find out if it also supports traditional characters. (The older [pinyin4android](https://code.google.com/archive/p/pinyin4android/) library, on which PiPinyin is based, appears to have no documentation.) Licence: Apache License 2.0.
* **[pinyin4cpp](https://github.com/handsomezhou/pinyin4cpp)**: C++ library. Licence: Apache License 2.0. (Possibly inspired by pinyin4j, below.)
* **[pinyin4j](http://pinyin4j.sourceforge.net/)**: Java library for conversion "between Chinese characters and most popular Pinyin systems". Can also ouput Wade-Giles, Yale and Gwoyeu Romatzyh! Licence: GPL v2.
* **[Unihanconver](http://www.sinologia.info/unihanconver/)**: a Perl library "to convert between Traditional/Simplified Chinese directly in Unicode (not GB/Big5 conversion)". It can be used through a Gtk2+ Interface and from the console. (See also the [developer site](https://sourceforge.net/projects/unihanconver/).) Licence: GPL 2.
* **[ZDT (Zhongwen Development Tool)](http://zdt.sourceforge.net/)**, written in Java, "is an easy to use, open-source Mandarin Chinese flashcard application that can help you learn Chinese". One of its features is conversion between Chinese charactes and pinyin. ([Developer site](https://sourceforge.net/projects/zdt/).) Licence: Eclipse Public License.
* **[zh2tone / Chinese Word to ZuYin Code](https://sourceforge.net/projects/zh2tone/)**: a tool to convert Chinese characters/words to zhuyin fuhao (bopomofo). The tool has not been updated since 2012, has no licence, ...

Notes:

* I have not checked the quality of these libraries (alpha/beta/production-ready, test coverage, etc.) nor their completeness (how many characters they support etc.).
* If you need such a library for professional use, I would steer clear of libraries that have no licence. Software available under Apache 2.0, MIT or BSD can be reused both in open source and commercial applications. Libraries available under a GPL licence ("GNU General Public Licence") can only be used in other GPL code.

> **Comments:**
> **username_2**: I used pinyin4j in a production system and it gets the job done pretty well  
> **username_3**: @TXV I have checked it out and it seems to be `char` based only. How to handle tokens and text?  
> **username_2**: The OP asked for a pinyin API. Tokenization in Chinese is an entirely different beast, maybe you should open a separate thread.  
> **username_4**: @username_3: apparently, for correctly handling segments you would need a segmenter such as https://github.com/huaban/jieba-analysis — I don't know the underlying approach, but have seen other libraries depending on it to do segmentation.  

---

### Answer by username_5 on 2016-09-02. Score: 5

if you have programming knowledge, you may download the 國語辭典 (of taiwan), which is under creative commons 3.0

<http://resources.publicense.moe.edu.tw/dict_reviseddict_download.html>

basically, it's 3 large excel files, using bash, grep, cut would give you relevant info of characters / words; and mandarin romanisation is one of them.

it's about 166000+ entries, that would be enough for "normal" usage.

have fun :)


---

### Answer by username_6 on 2016-09-03. Score: 4

Glosbe seems to offer this service:
https://glosbe.com/transliteration/api?from=Han&dest=Latin&text=你好&format=json
{"result":"ok","text":"nǐ hǎo"}

https://glosbe.com/transliteration/api?from=Han&dest=Latin&text=龜&format=json
{"result":"ok","text":"guī"}

In a very small experiment the service didn't seem so smart at distinguishing characters with multiple pronunciations:
https://glosbe.com/transliteration/api?from=Han&dest=Latin&text=銀行&format=json
{"result":"ok","text":"yín xíng"}

See the documentation at https://glosbe.com/a-api
Google Translate API might also offer what you're looking for (the console at http://translate.google.com does), but that service isn't free.

> **Comments:**
> **username_7**: The Google Translate API does not seem to support pinyin.  

---

### Answer by username_8 on 2017-01-19. Score: 2

It might be easier just to download [CC-CEDICT](https://www.mdbg.net/chindict/chindict.php?page=cc-cedict) in its entirety and look up your character in it. You can turn this into an API with very little effort.


---

### Answer by username_9 on 2019-04-19. Score: 1

I created a python module which converts a whole sentence into Pinyin. It also supports Cantonese/Jyutping. There's an accompanying REST API: https://github.com/lucwastiaux/python-pinyin-jyutping-sentence . It attempts to separate the sentence into words (which I haven't seen other chinese-to-pinyin modules do), using the jieba library.
Installing the module
pip install pinyin_jyutping_sentence
Mandarin / simplified characters
>>> import pinyin_jyutping_sentence
>>> pinyin_jyutping_sentence.pinyin("提高口语")
'tígāo kǒuyǔ'

Cantonese / traditional characters
>>> import pinyin_jyutping_sentence
>>> pinyin_jyutping_sentence.jyutping("我出去攞野食")
'ngǒ cēothêoi ló jěsik'

Calling the REST API
Mandarin
import requests
import json

url = "http://api.mandarincantonese.com/pinyin/办所有的事情"
response = requests.get(url)
print(json.loads(response.content)["pinyin"])
>>> bàn suǒyǒu de shìqíng

Cantonese
# calling the API from python
import requests
import json

url = "http://api.mandarincantonese.com/jyutping/我哋盪失咗"
response = requests.get(url)
print(json.loads(response.content)["jyutping"])
>>> ngǒ déi dongsāt zó


---

### Answer by username_4 on 2019-12-06. Score: 0

Why would you want to use an external API for static data that does not change over time?

The translation map is a constant, and all the libraries and services just wrap those maps.

As far as Chinese Traditional/Simplified to Pinyin goes there are a variety of free mappings available — here is one I've found to be the most complete and up-to-date which I 'ported' to javascript: <https://github.com/glowinthedark/Simplified-and-Traditional-Chinese/blob/master/gb2312-big5/js/pinyin.js> — this can be easily adapted to whatever programming language you need.

Or, as suggested in another answer, you can extract your own map from CEDICT.

### Python-based identifier and conversion tool

* <https://github.com/tsroten/dragonmapper>

### Ruby-based conversion tool:

* <https://github.com/plexus/ting>

### Other resources

The [wechat app for android](https://www.wechat.com/en/) comes with built-in conversion tables for chinese2pinyin and traditional2simplified which you can peek at by renaming the apk file to zip, unzipping it, and then looking under the `assets/fts` folder where you will find `fts_py.txt` and `fts_t2s.txt` corrrespondingly. (*Note that this might change in future versions.*)


---

