PyThaiTTS
Open Source Thai Text-to-speech library in Python
Google Colab | Docs | Notebooks
License: Apache-2.0 License
Install
Install by pip:
pip install pythaitts
Usage
Basic Usage
from pythaitts import TTS
tts = TTS()
file = tts.tts("ภาษาไทย ง่าย มาก มาก", filename="cat.wav") # It will get wav file path.
wave = tts.tts("ภาษาไทย ง่าย มาก มาก",return_type="waveform") # It will get waveform.
Using Different TTS Models
PyThaiTTS supports multiple TTS models. You can specify which model to use:
from pythaitts import TTS
# Use FastThaiG2P (default) (default voice: thai_som)
# FastThaiG2P Sample Rate is 24000 Hz
tts = TTS(pretrained="fastthaig2p")
file = tts.tts("สวัสดีครับ", speaker_idx="thai_som", filename="output.wav")
# Use Lunarlist ONNX
# Sample Rate is 22050 Hz
tts = TTS(pretrained="lunarlist_onnx")
file = tts.tts("ภาษาไทย ง่าย มาก", filename="output.wav")
# Use VachanaTTS (default voices: th_f_1, th_m_1, th_f_2, th_m_2)
# Sample Rate is 22050 Hz
tts = TTS(pretrained="vachana")
file = tts.tts("สวัสดีครับ", speaker_idx="th_f_1", filename="output.wav")
# Use KhanomTan
# Sample Rate is 16000 Hz
tts = TTS(pretrained="khanomtan")
file = tts.tts("ภาษาไทย", speaker_idx="Linda", filename="output.wav")
Real-time / Streaming TTS (FastThaiG2P)
PyThaiTTS supports low-latency, real-time streaming speech synthesis with FastThaiG2P, making it ideal for conversational voice agents and LLM streaming:
1. Streaming Audio from Text
Synthesize chunk-by-chunk in real time:
from pythaitts import TTS
tts = TTS(pretrained="fastthaig2p")
# Stream audio chunks as 24kHz float32 NumPy arrays
for audio_chunk in tts.stream("สวัสดีครับ ยินดีต้อนรับสู่ระบบเรียลไทม์ทีทีเอส"):
print(f"Audio chunk shape: {audio_chunk.shape}")
# Stream raw 16-bit PCM bytes (for WebSockets or PyAudio)
for pcm_bytes in tts.stream("สวัสดีครับ", return_type="bytes"):
# send over websocket or write to audio stream
pass
2. Streaming from an LLM Token Stream
Feed tokens directly from an LLM or generator into tts.stream():
from pythaitts import TTS
tts = TTS()
def token_stream():
tokens = ["สวัสดี", "ครับ", " ", "นี่", "คือ", "การ", "สตรีม", "มิ่ง"]
for tok in tokens:
yield tok
for audio_chunk in tts.stream(token_stream()):
# Process or play chunk with low latency
pass
3. Integration with the RealtimeTTS Library
You can use FastThaiG2P as an engine with KoljaB/RealtimeTTS:
pip install pythaitts[realtime]
from RealtimeTTS import TextToAudioStream
from pythaitts.realtime import FastThaiG2PEngine
engine = FastThaiG2PEngine()
stream = TextToAudioStream(engine)
stream.feed("สวัสดีครับ วันนี้อากาศดีมาก")
stream.play()
Text Preprocessing
PyThaiTTS includes automatic text preprocessing to improve TTS quality:
- Number to Thai text conversion: Converts digits (e.g., "123") to Thai text (e.g., "หนึ่งร้อยยี่สิบสาม")
- Mai yamok (ๆ) expansion: Expands the Thai repetition character (e.g., "ดีๆ" becomes "ดีดี")
Preprocessing is enabled by default:
from pythaitts import TTS
tts = TTS()
# Automatic preprocessing: "มี 5 คนๆ" becomes "มี ห้า คนคน"
file = tts.tts("มี 5 คนๆ", filename="output.wav")
You can disable preprocessing if needed:
file = tts.tts("มี 5 คนๆ", preprocess=False, filename="output.wav")
You can also use preprocessing functions directly:
from pythaitts import num_to_thai, expand_maiyamok, preprocess_text
# Convert numbers to Thai text
print(num_to_thai("123")) # Output: หนึ่งร้อยยี่สิบสาม
# Expand mai yamok
print(expand_maiyamok("ดีๆ")) # Output: ดีดี
# Full preprocessing
print(preprocess_text("มี 5 คนๆ")) # Output: มี ห้า คนคน
You can see more at https://pythainlp.github.io/PyThaiTTS/.
Metadata
Release files for PyThaiTTS 0.8.0
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 |
|---|---|---|---|---|
| pythaitts-0.8.0.tar.gz | 7.0 MB | Without provenance | Details for pythaitts-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pythaitts-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for pythaitts-0.8.0-py3-none-any.whl |
Total release size: 14.2 MB
Release files / pythaitts-0.8.0.tar.gz
| Download URL | pythaitts-0.8.0.tar.gz |
|---|---|
| Size | 7.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85df268d181168c58c8f966fe2be66b4e59e54aabd8d9b0e14eeee784dd3508f
|
|
BLAKE2b-256 checksum How to use checksums |
63c2dfaf99990f2d1b6c940e6d891b9d4697e9529dec2fe1981d4492f37ffbc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pythaitts-0.8.0-py3-none-any.whl
| Download URL | pythaitts-0.8.0-py3-none-any.whl |
|---|---|
| Size | 7.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d0feb2392fb94ff1d43017dfa445a80af623de90c8df82e96279524d3bbcfb6
|
|
BLAKE2b-256 checksum How to use checksums |
2eaded14caed5b87c9917628fb533a6f9cbab1e3085d12fcc8d9217d7dea07fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for PyThaiTTS 0.8.0
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.