FastThaiG2P: Lightning-fast Thai Grapheme-to-phoneme Conversion for Voice Agent Pipelines
Charin Polpanumas
Amazon Web Services
cs.CL
Submitted: 2026-08-13
Updated: 2026-08-14
Code: https://github.com/aws/FastThaiG2P
License: http://creativecommons.org/licenses/by-nc-sa/4.0/
The gist: FastThaiG2P provides sub-millisecond Thai grapheme-to-phoneme conversion for text-to-speech pipelines (International Phonetic Alphabet and Kokoro-TTS conventions) using a PyThaiNLP-tokenized,
Terminology
Summary
FastThaiG2P provides sub-millisecond Thai grapheme-to-phoneme conversion for text-to-speech pipelines (International Phonetic Alphabet and Kokoro-TTS conventions) using a PyThaiNLP-tokenized, extensible dictionary and normalization rules for common Central Thai speech. The approach achieves an average latency of 0.15 ms per utterance on a benchmark of 27,242 synthetically generated utterances, of which 30% is spent on tokenization, 12% on normalization, and 58% on out-of-vocabulary fallbacks (0.5% OOV rate). To demonstrate its effectiveness, we used FastThaiG2P to phonemize Som-TTS, an open dataset containing 20 hours of grapheme-and-audio pairs, then trained an 82M-parameter StyleTTS 2 model based on a Kokoro-TTS recipe. The resulting model vocalizes intelligible Thai speech suitable for prototyping and development at 0.25 real-time factor (4x real-time) with ONNX inference on CPU.
Thai text-to-speech (TTS) systems face a unique set of challenges at the grapheme-to-phoneme (G2P) stage. Unlike languages with relatively transparent orthography, alphasyllabary Thai script exhibits several properties that complicate phonemization: 1) words and sentences are written without explicit boundaries, requiring segmentation as a prerequisite to phonemization 2) Thai is a tonal language with five lexical tones whose surface realization depends on syllable structure, consonant class, vowel length, and final consonant 3) vowels are written as discontinuous graphemes that surround their onset consonant and some are polyfunctional, serving as standalone vowels as well as components of other vowels 4) multiple classes of non-transparent grapheme-to-phoneme mappings–namely leading consonant tone shift, reduced vowels absent from the orthography, context-dependent ligatures, false clusters, and homographs–mean that character-level rules alone are insufficient 5) real-world Thai text contains a dense mixture of numbers, abbreviations, symbols, English loanwords, and code-switched tokens that must be verbalized before phonemization. For real-time voice agent pipelines such as call center agents, conversational AI assistants, and live captioning systems, the G2P stage must be both comprehensive and fast. A latency budget of 500–1,000 ms for the entire TTS pipeline leaves little room for slow preprocessing.
Several tools provide Thai G2P functionality, spanning rule-based, dictionary-based, and model-based approaches. TLTK performs syllable-level G2P via a trigram-based syllable segmenter and rule-based phonological mapping. It handles regular Thai orthography well but relies entirely on rules without a pre-built dictionary, limiting accuracy on irregular words and loanwords. Its runtime recompiles regex patterns on every call, resulting in high latency for batch processing, up to 2 ms per utterance on average over our 27,242-utterance synthetic dataset. Epitran offers rule-based grapheme-to-IPA mapping for 61 languages including Thai via a character map with pre- and post-processing rewrite rules. Its Thai mode reorders leading vowels, applies coda neutralization, and maps consonants/vowels to IPA segments. However, it explicitly discards tone marks without inferring tonal values from syllable structure, requires pre-segmented word input, and does not include word segmentation or text normalization. thai-g2p uses a seq2seq, MarianMT-based model trained on Wiktionary data to predict phonemes from Thai words. It requires external word segmentation and does not include text normalization. CharsiuG2P is a ByT5-based multilingual neural G2P covering 100 languages including Thai. It achieves a phoneme error rate (PER) of 26.9% and word error rate (WER) of 59% and produces IPA with tonal notation for Thai. However, it requires pre-tokenized word input, has higher inference latency than dictionary lookup due to autoregressive decoding, and does not include text normalization. None of these tools simultaneously provide 1) a large curated IPA dictionary for Thai, 2) comprehensive text normalization for spoken forms, 3) sub-millisecond per-utterance latency, and 4) robust OOV handling, all of which are pre-requisites for inputs to phoneme-based TTS architectures.
Recent grapheme-based TTS models can synthesize Thai speech directly from text without explicit G2P. MMS-TTS provides a lightweight VITS model for Thai but suffers from high error rates (CER 18.28% on Common Voice 13 Thai test split). ThonburianTTS finetunes F5-TTS on 969 hours of Thai speech, achieving CER 8.70% on Common Voice 13 Thai test split. JaiTTS adapts VoxCPM-0.5B for Thai with CER of 1.94% on their internal benchmark. Multilingual architectures including Qwen3-TTS, OmniVoice, VoxCPM-0.5B and VoxCPM2 support Thai among many languages. However, these models require 336M–2B parameters and GPU inference. For deployment scenarios requiring CPU-only inference, sub-second latency, or minimal memory footprint such as edge devices and cost-sensitive batch pipelines, a phoneme-based approach with a compact acoustic model remains the practical choice thus the necessity of a fast and accurate phonemization front-end.
This paper presents FastThaiG2P, an open-source Thai G2P library that bridges the gap between dictionary-based accuracy and the speed required for real-time phoneme-based TTS. The system combines a 62,112-word IPA dictionary with comprehensive text normalization and a rule-based out-of-vocabulary (OOV) fallback, achieving 0.15 ms per utterance on a 27,242-utterance benchmark. Paired with a Thai-finetuned Kokoro-82M checkpoint based on StyleTTS 2, the full pipeline produces intelligible Thai speech at 0.25 real-time factor (RTF) on CPU with a total footprint of 330 MB. Our contributions are: 1) a 62,112-word IPA dictionary assembled from Wiktionary, LLM-generated transcriptions validated against phonological rules, and manual overrides 2) a text normalization pipeline covering 15 categories of non-speakable text including numbers, Thai abbreviations, units, symbols, phone numbers, emails, and time patterns 3) up to 15x latency reduction over the TLTK baseline through regex caching and import-time initialization 4) an end-to-end TTS demonstration using FastThaiG2P to train a Thai Kokoro-82M model achieving 0.25 RTF on CPU. The library is released under Apache-2.0 at github.com/aws/FastThaiG2P.
FastThaiG2P implements a four-stage pipeline, sequentially, text normalization, tokenization, phoneme dictionary lookup, and fallback G2P.
The normalizer converts non-vocalizable scripts to vocalizable ones before tokenization. This acts as the deterministic, last line of defense against invalid TTS inputs in case prompting the large language model (LLM) fails in a cascading voice agent pipeline (automatic speech recognition (ASR) → LLM → TTS). Processing occurs in a fixed order designed to prevent ambiguity: Expand maiyamok, the Thai word repetition marker; Convert Thai numerals to Arabic digits; Read email addresses; Read English abbreviations and brand names (transliteration dictionary); Read units (kg, km, °C, etc.); Read symbols (%, +, ×, etc.); Read time patterns (14:30, 23:12, etc.); Read phone numbers (digit-by-digit per group); Read alphanumeric identifiers (ORD-001); Read comma-separated numbers (1,000); Read decimal and plain numbers; Read Thai abbreviations; Read residual Latin characters. Short numbers (6 digits or shorter) use Thai place-value reading while long numbers (7 digits or longer) are read digit-by-digit, matching the Thai convention for phone numbers, account numbers, and IDs.
After normalization, the text is segmented into words using PyThaiNLP’s ‘newmm‘ (maximum matching) engine with a custom dictionary. The dictionary (‘data/dict.txt‘ and ‘data/ipa.json‘) serves both as a custom word-list for the segmentation and lookup keys for corresponding IPA entries. This coupling ensures every token produced by the word segmenter has an IPA barring OOV tokens.
The 62,112-entry IPA dictionary was built from three main sources, from highest to lowest merge priorities: Manual Overrides (sources/manual overrides.json) manually verified IPA transcriptions for words where we could not find references from Wikitionary and/or automated methods fail. This serves as a human-in-the-loop lever for continuous dictionary improvement. Wiktionary (sources/wiktionary ipa.json) about 13,000 entries extracted from the Thai Wiktionary dump. These follow the English Wiktionary IPA convention for Thai, which served as the reference standard for our transcription format. LLM Transcription (sources/generated ipa.json) approximately 49,000 entries generated by Claude Opus 4.6 via Amazon Bedrock. Generation was performed in batches of 100 words using a detailed prompt specifying the IPA convention, phonological constraints, and example transcriptions. Each response was validated by checking that every character falls within a 38-codepoint phoneme inventory whitelist (consonants, vowels, Chao tone letters, combining diacritics, and separators); entries with out-of-inventory characters or missing slash delimiters were rejected and logged to generated ipa invalid.json. Before batch generation, the prompt was validated against 500 random Wiktionary entries as a validation set. With TTS as the objective, errors were classified as non-fatal (tone mismatch, vowel length, diphthong marker, coda variant) or fatal (wrong syllable count, wrong initial consonant or vowel quality). Pali/Sanskrit loanwords with irregular readings were excluded from the fatal count since Wiktionary handles them directly. The final prompt has 78.8% exact match rate and 1.8% fatal error rate on the validation set.
Words not found in the dictionary receive IPA transcription via a rule-based fallback vendored from TLTK. The fallback segments the word into syllables using trigram statistics (‘data/fallback/sylseg.3g‘), maps each syllable to a romanized pronunciation using consonant class, vowel pattern, and tone rules, then converts the romanization to our IPA convention (Chao tone letters, aspiration, unreleased stops). The fallback always produces phonologically valid Thai IPA but may not match the conventional pronunciation of irregular words (loanwords, Pali/Sanskrit compounds with silent letters). Frequently encountered OOV words should be manually added to the dictionary. The original TLTK implementation recompiles regular expressions on every function call. The sylparse function iterates over hundreds of syllable pattern regexes, calling re.match(pattern string,...) at every character position of the input word. Python’s internal regex cache, a Least Recently Used (LRU) cache limited to 512 entries, overflows when the number of unique patterns exceeds this limit, causing repeated recompilation. In the vendored version, we introduced an explicit unbounded regex cache at all three hot loops in the fallback code: syllable parsing, syllable enumeration, and rule loading. Combined with pre-loading the syllable rules at import time rather than on first call, this reduced the overall G2P latency from approximately 2 ms per utterance to 0.15 ms per utterance, up to 15x improvement. The majority of the savings come from eliminating redundant regex compilation in the fallback path, which previously dominated wall-clock time even though it was invoked on a minority of tokens.
We follow the English Wiktionary Thai IPA transcription standard using Chao tone letters. The inventory uses 38 phoneme-related codepoints. Kokoro-82M was pretrained on English and does not natively support Thai. Its phoneme vocabulary includes four intonation markers used for English prosody; however Thai requires five tonally distinct markers. A naive mapping would force a merger between high and rising tones, which are phonemically contrastive. We repurposed an unused token ID 170 as the high tone marker, yielding the following five-tone mapping. We also stripped diacritics that only exist in IPA as well as substitute affricates and g character with the corresponding Kokoro equivalents.
Latency was measured on a corpus of 27,242 synthetically generated Thai utterances (data/synthetic/utterances.jsonl) representing conversational text, numbers, abbreviations, and domain-specific vocabulary typical of voice agent interactions. Profiling was performed using scripts/profile g2p.py which measures end-to-end latency across all utterances and per-component timing with cProfile instrumentation on a single-threaded CPU setup with Python 3.11. Despite only 0.5% of tokens being OOV, the fallback dominates wall-clock time (58%) because trigram-based syllable parsing is orders of magnitude more expensive per-token than a hash lookup. The pipeline exhibits predictable latency with no neural network inference, no disk input-output per call, and no per-call memory allocation.
To validate that FastThaiG2P enables a minimally viable Thai TTS system with CPU-only inference, we trained a Thai-finetuned Kokoro-82M checkpoint end-to-end. We used Kokoro-82M, an 82-million-parameter architecture based on StyleTTS 2. The model was Thai-finetuned using the kikiri-tts training recipe, which implements a two-stage training process: stage 1 for text-to-mel alignment and duration prediction, and stage 2 for adversarial training with a multi-scale discriminator. The model takes Kokoro-format phoneme sequences as input and produces 24 kHz audio. A voicepack vector conditions the model on a target speaker identity. We used Som-TTS, an open Thai TTS dataset containing approximately 20 hours of single-speaker recordings with aligned Thai text transcripts. FastThaiG2P was used to phonemize all transcripts, converting Thai graphemes to the Kokoro phoneme format via the IPA intermediate representation. For deployment without PyTorch, the trained checkpoint was exported to ONNX format, outputting raw audio samples plus frame durations for boundary token trimming. The resulting model produces intelligible Thai speech with recognizable tonal patterns and natural rhythm for short to medium utterances at RTF 0.25 (4x real-time) on a single-threaded CPU inference. The total memory footprint is about 330 MB. Audio quality is suitable for prototyping and development. The TTS module includes a post-processing step that removes static/noise generated during the beginning-of-sentence (BOS) and end-of-sentence (EOS) pad token windows using voicing detection to distinguish genuine speech onset from artifacts in the boundary regions.
The 62k-word dictionary covers standard Central Thai well but has gaps in regional vocabulary, recent loanwords, slang, and code-switched Thai-English text. We expect to periodically update the dictionary and allows seamless manual overrides for each use case. The rule-based fallback produces phonologically valid IPA but may err on irregular words (silent letters in Pali/Sanskrit compounds, non-standard loanword pronunciations). A hybrid approach combining rules with a small neural model could improve OOV handling. Thai tone assignment from orthography is largely rule-governed but has exceptions such as tone-mark elision in certain compounds, dialectal variation. The current system follows standard Central Thai rules; regional variants are not modeled. No formal MOS study has been conducted. A perceptual evaluation with native Thai speakers would quantify quality and enable comparison against commercial Thai TTS systems. We see FastThaiG2P as an enabler for increasingly more potent phoneme-based, CPU-only TTS systems that power hybrid voice agents, agentic systems which leverage frontier models to perform complex tasks on AWS Bedrock and Sagemaker while outsourcing simpler tasks such as ASR and TTS to local devices.
Improvements for AI systems
Improvements to AI systems:
-
Add a hybrid OOV fallback layer: Replace the rule-based fallback for out-of-vocabulary words with a lightweight neural model (e.g., a small transformer or BiLSTM) trained on the 62k dictionary entries. This improves accuracy on loanwords, Pali/Sanskrit compounds, and regional vocabulary while keeping latency under 1 ms via quantization or distillation.
-
Implement adaptive tone assignment: Extend the G2P pipeline to detect dialectal or contextual tone variations (e.g., tone-mark elision in compounds) using a learned classifier that takes syllable context and neighboring tokens as input. This enables region-specific TTS without retraining the acoustic model.
-
Add a streaming mode: Refactor the pipeline to process text incrementally (word-by-word) rather than utterance-by-utterance, enabling real-time voice agents to start synthesizing speech before the full sentence is received, reducing perceived latency.
-
Integrate a confidence score: Have FastThaiG2P output a confidence value per phoneme based on dictionary match quality, fallback rule applicability, and OOV frequency. The TTS system can then trigger human-in-the-loop dictionary updates or fallback to a slower but more accurate neural G2P for low-confidence segments.
-
Build a self-improving dictionary loop: Use the confidence scores and downstream ASR feedback (e.g., from the TTS output being transcribed) to automatically flag mispronunciations, generate candidate corrections via LLM, and propose manual overrides for review—creating a continuous improvement cycle.
-
Extend normalization to code-switched text: Add a language-detection module that identifies English/Thai code-switching and applies language-specific normalization and G2P rules per segment, improving handling of mixed-language voice agent inputs.
-
Enable multi-speaker conditioning: Use the voicepack vector in Kokoro-82M to train on multiple speakers (e.g., from Som-TTS plus other open datasets) and expose a speaker-embedding API, allowing voice agents to switch personas dynamically without retraining.
-
Add prosody-aware phoneme output: Augment the IPA output with syllable-level stress and boundary markers derived from the normalization and tokenization stages, enabling the acoustic model to produce more natural rhythm and intonation for questions, lists, and emphasis.
What the improved AI system can do:
-
Real-time conversational agents that begin speaking within 10 ms of receiving a text chunk, handle mixed Thai-English dialogue, and adapt tone to regional dialects (e.g., Central vs. Northern Thai) on the fly.
-
Self-correcting TTS pipelines that automatically improve pronunciation over time by learning from ASR misrecognitions, reducing the need for manual dictionary curation.
-
Edge-deployable voice assistants running on 330 MB memory with 4x real-time CPU inference, capable of handling phone numbers, emails, units, and abbreviations in both Thai and English without GPU support.
-
Multi-voice customer service bots that switch between speaker identities (e.g., male/female, formal/casual) per interaction, using the same compact model.
-
Live captioning and dubbing systems that produce sub-millisecond phonemization for Thai video content, including code-switched dialogue, with confidence-based fallback to higher-accuracy modes when needed.
Abstract
FastThaiG2P provides sub-millisecond Thai grapheme-to-phoneme conversion for text-to-speech pipelines (International Phonetic Alphabet and Kokoro-TTS conventions) using a PyThaiNLP-tokenized, extensible dictionary and normalization rules for common Central Thai speech. The approach achieves an average latency of 0.15 ms per utterance on a benchmark of 27,242 synthetically generated utterances, of which 30% is spent on tokenization, 12% on normalization, and 58% on out-of-vocabulary fallbacks (0.5% OOV rate). To demonstrate its effectiveness, we used FastThaiG2P to phonemize Som-TTS, an open dataset containing 20 hours of grapheme-and-audio pairs, then trained an 82M-parameter StyleTTS 2 model based on a Kokoro-TTS recipe. The resulting model vocalizes intelligible Thai speech suitable for prototyping and development at 0.25 real-time factor (4x real-time) with ONNX inference on CPU.
Sources
- JaiTTS: A Thai Voice Cloning Model
- VoxCPM: Tokenizer-Free TTS for Context-Aware Speech Generation and True-to-Life Voice Cloning
- Qwen3-TTS Technical Report
- OmniVoice: Towards Omnilingual Zero-Shot Text-to-Speech with Diffusion Language Models
- VoxCPM2 Technical Report
Related papers
- Exploring Solution Divergence and Its Effect on Large Language Model Problem Solving
- Ishigaki-IDS-Bench: A Benchmark for Generating Information Delivery Specification from BIM Information Requirements
- Subliminal Steering: Stronger Encoding of Hidden Signals
- MedStruct-S: A Benchmark for Key Discovery, Key-Conditioned QA and Semi-Structured Extraction from OCR Clinical Reports
- The End of Transformers? On Challenging Attention and the Rise of Sub-Quadratic Architectures
- Untangling the Mechanisms of Misleading Context in Medical Question Answering