Skip to content

PyThaiNLP/PyThaiTTS

Repository files navigation

PyThaiTTS

Open Source Thai Text-to-speech library in Python

Google Colab | Docs | Notebooks Download

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.

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/.

About

Open Source Thai Text-to-speech library in Python

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •