PyThaiTTS
Open Source Thai Text-to-speech library in Python
- class pythaitts.TTS(pretrained='lunarlist_onnx', mode='last_checkpoint', version='1.0', device: str = 'cpu')[source]
- __init__(pretrained='lunarlist_onnx', mode='last_checkpoint', version='1.0', device: str = 'cpu') None[source]
- Parameters:
- Options for mode
last_checkpoint (default) - last checkpoint of model
best_model - Best model (best loss)
You can see more about khanomtan tts at https://github.com/wannaphong/KhanomTan-TTS-v1.0 and https://github.com/wannaphong/KhanomTan-TTS-v1.1 If you want to use khanomtan tts, you must to install coqui-tts before use the model by pip install coqui-tts.
For lunarlist tts model, you must to install nemo before use the model by pip install nemo_toolkit[‘tts’]. You can see more about lunarlist tts at https://link.medium.com/OpPjQis6wBb
For lunarlist_onnx tts model, You can see more about lunarlist tts at https://github.com/PyThaiNLP/thaitts-onnx
For vachana tts model, You can see more about vachana tts at https://github.com/VYNCX/VachanaTTS2
- tts(text: str, speaker_idx: str = 'Linda', language_idx: str = 'th-th', return_type: str = 'file', filename: str | None = None, preprocess: bool = True)[source]
speech synthesis
- Parameters:
text (str) – text
speaker_idx (str) – speaker (default is Linda for khanomtan, th_f_1 for vachana)
language_idx (str) – language (default is th-th)
return_type (str) – return type (default is file)
filename (str) – path filename for save wav file if return_type is file.
preprocess (bool) – whether to preprocess text (convert numbers to Thai text and expand ๆ). Default is True.
Text Preprocessing
PyThaiTTS provides text preprocessing functions to improve TTS quality.
- pythaitts.preprocess_text(text: str, expand_numbers: bool = True, expand_maiyamok_char: bool = True) str[source]
Preprocess Thai text for TTS by converting numbers to text and expanding ๆ.
- Parameters:
- Returns:
Preprocessed text
- Return type:
- Examples:
>>> preprocess_text("ฉันมี 123 บาท") 'ฉันมี หนึ่งร้อยยี่สิบสาม บาท' >>> preprocess_text("ดีๆ") 'ดีดี' >>> preprocess_text("มี 5 คนๆ") 'มี ห้า คนคน'
- pythaitts.num_to_thai(num_str: str) str[source]
Convert number string to Thai text. Supports integers and decimals.
- Parameters:
num_str (str) – Number string to convert (e.g., “123”, “1234”, “12.5”)
- Returns:
Thai text representation
- Return type:
- Examples:
>>> num_to_thai("0") 'ศูนย์' >>> num_to_thai("123") 'หนึ่งร้อยยี่สิบสาม' >>> num_to_thai("1000") 'หนึ่งพัน'
- pythaitts.expand_maiyamok(text: str) str[source]
Expand Thai repetition character (ๆ) by repeating the previous word or syllable.
The mai yamok (ๆ) is a Thai repetition mark that indicates the previous word or syllable should be repeated.
- Examples:
>>> expand_maiyamok("ช้าๆ") 'ช้าช้า' >>> expand_maiyamok("ดีๆ") 'ดีดี'