Vietnamese Accent Restoration API
Restore Vietnamese diacritics in text typed without accents (“xin chao cac ban” → “xin chào các bạn”) using a dictionary and syllable frequencies.
The accent restoration API turns Vietnamese typed without diacritics, common in SMS, chats, old databases and product names, back into proper Vietnamese: Ngan hang Nha nuoc vua giam lai suat → Ngân hàng Nhà nước vừa giảm lãi suất. Each run of unaccented words is solved as a whole with dynamic programming: the API prefers sequences that form dictionary words of two to four syllables, then the most frequent syllables.
Capitalisation is kept (Ha Noi → Hà Nội, CONG TY → CÔNG TY), punctuation and numbers are left alone, and words that are not Vietnamese stay unchanged. alternatives=1–5 lists, for every ambiguous syllable, the other likely readings, so an interface can let the user pick (ban: bạn / bán / bàn).
It runs on a word list and frequency tables, without an AI model, in a few milliseconds. Results are good for common phrases and names; short or unusual sentences can need a human check. Text that is already partly accented is fine: syllables typed with accents are kept as they are and help choose the accents of their neighbours.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
text | body|query | string | yes | Unaccented Vietnamese text (max 20,000 characters). | |
alternatives | body|query | number | no | 0 | Other readings to list per ambiguous syllable (0–5). |
Example
curl -X POST "https://apibox.io.vn/v1/vn-diacritics" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"Ngan hang Nha nuoc vua giam lai suat dieu hanh","alternatives":2}'const res = await fetch('https://apibox.io.vn/v1/vn-diacritics', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"text": "Ngan hang Nha nuoc vua giam lai suat dieu hanh",
"alternatives": 2
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/vn-diacritics",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"text": "Ngan hang Nha nuoc vua giam lai suat dieu hanh", "alternatives": 2},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/vn-diacritics');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"text":"Ngan hang Nha nuoc vua giam lai suat dieu hanh","alternatives":2}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"input": "Ngan hang Nha nuoc vua giam lai suat dieu hanh",
"result": "Ngân hàng Nhà nước vừa giảm lãi suất điều hành",
"syllables_changed": 10,
"ambiguous_syllables": 8,
"alternatives": [
{
"word": "Ngân",
"position": 0,
"options": [
"ngân",
"ngắn",
"ngăn"
]
},
{
"word": "vừa",
"position": 19,
"options": [
"vừa",
"vua",
"vựa"
]
},
{
"word": "lãi",
"position": 28,
"options": [
"lai",
"lại",
"lãi"
]
}
],
"note": "Accents are chosen from a dictionary and syllable frequencies; ambiguous words (ban: bạn / bán / bàn) may need a human check."
}
Use cases
- Fix product names and addresses imported without accents
- Make SMS and chat messages readable
- Restore accents in old database exports
- Suggest accented text as the user types
FAQ
How accurate is it?
Common phrases come out right most of the time; ambiguous short words may be wrong, which is why alternatives are offered.
Does it use AI?
No, a dictionary of words and syllable frequencies with dynamic programming, so it is fast and deterministic.
Can I send text that already has some accents?
Yes. Syllables that already have accents are kept unchanged and only the unaccented ones are restored, e.g. “Hôm nay troi dep qua” → “Hôm nay trời đẹp quá”.
Related APIs
Text Diff
Compare two texts by lines, words, characters, sentences or JSON and get the changes, a similarity score and a unified diff patch.
a-bSlugify
Turn titles into clean URL slugs: accents removed (Vietnamese đ included), custom separator, optional case keeping and maximum length.
123Text Statistics
Count words, characters, sentences, paragraphs and lines, estimate reading and speaking time, and list the most frequent words of a text.