Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: actions/checkout@v4
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ from pythaitts import TTS
tts = TTS(pretrained="fastthaig2p")
file = tts.tts("สวัสดีครับ", speaker_idx="thai_som", filename="output.wav")

# Use MakHamTTS Paradee (standalone, single-voice 8MB quantized INT8 ONNX model, offline without download)
# MakHamTTS Paradee Sample Rate is 24000 Hz
tts = TTS(pretrained="makham_paradee")
file = tts.tts("สวัสดีค่ะ", filename="output.wav")

# Use MakHamTTS (Kokoro-82M Thai base model, voices: newvoice_female, newvoice_male)
# MakHamTTS Sample Rate is 24000 Hz
tts = TTS(pretrained="makham")
file = tts.tts("สวัสดีค่ะ", speaker_idx="newvoice_female", filename="output.wav")

# Use Lunarlist ONNX
# Sample Rate is 22050 Hz
tts = TTS(pretrained="lunarlist_onnx")
Expand Down Expand Up @@ -142,6 +152,49 @@ print(eng("project")) # Output: /proː˧.t͡ɕek̚˨˩
```


### Custom Word Pronunciation Dictionary

PyThaiTTS supports custom word dictionaries to define custom Thai pronunciation (as Thai text reading or IPA phonemes) for specific words, acronyms, or names.

Dictionaries can be passed as Python dicts, JSON files, or delimited text files (TSV, CSV, or colon-separated):

```python
from pythaitts import TTS

# 1. Provide custom Thai pronunciation (hyphenated or plain text)
custom_dict = {
"เพชรบุรี": "เพ็ด-ชะ-บุ-รี",
"สถิติ": "สะ-ถิ-ติ",
"ChatGPT": "แชตจีพีที",
}

tts = TTS(custom_dict=custom_dict)
tts.tts("ยินดีต้อนรับสู่เพชรบุรี", filename="custom.wav")

# 2. Or pass per-call or with IPA phonemes directly
tts.tts(
"ผมไปเพชรบุรี",
custom_dict={"เพชรบุรี": "/pʰet̚˨˩.t͡ɕʰa˦˥.bu˨˩.riː˧/"},
filename="ipa.wav",
)

# 3. Add or update custom words dynamically
tts.add_custom_dict({"ก.พ.": "กอ-พอ"})

# 4. Load from a JSON or TSV file
tts.set_custom_dict("my_words.json")
```

You can also use custom dictionaries with G2P directly:

```python
from pythaitts.pretrained.fastthaig2p import G2P

g2p = G2P(custom_dict={"เพชรบุรี": "เพ็ด-ชะ-บุ-รี"})
print(g2p.convert("ผมไปเพชรบุรี"))
```


### Text Preprocessing

PyThaiTTS includes automatic text preprocessing to improve TTS quality:
Expand Down
7 changes: 7 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def main():
print(f"✓ Waveform generated successfully!")
print(f"Waveform shape: {waveform.shape}")
print()

# Demonstrate custom word pronunciation dictionary
print("Demonstrating custom word pronunciation dictionary...")
custom_dict = {"พายไทยทีทีเอส": "พาย-ไทย-ที-ที-เอส"}
waveform_custom = tts.tts(text, custom_dict=custom_dict, return_type="waveform")
print(f"✓ Custom pronunciation waveform generated! Shape: {waveform_custom.shape}")
print()

print("=" * 60)
print("Demo completed successfully!")
Expand Down
2 changes: 1 addition & 1 deletion demo_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main():
# 1. Initialize TTS model
print("Initializing FastThaiG2P TTS model...")
t_start = time.time()
tts = TTS(pretrained="fastthaig2p")
tts = TTS(pretrained="makham_paradee")
print(f"✓ Model loaded in {time.time() - t_start:.2f}s")
print()

Expand Down
10 changes: 10 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ PyThaiTTS provides English-to-Thai-IPA Grapheme-to-Phoneme (G2P) conversion for

.. autofunction:: en_ipa_to_thai_ipa

MakHamTTS Models
----------------
MakHamTTS models powered by Kokoro-82M Thai and Paradee 1.1 distillation.

.. autoclass:: MakHamTTS
:members:

.. autoclass:: MakHamTTSParadee
:members:

FastThaiG2P Components
----------------------

Expand Down
2 changes: 1 addition & 1 deletion example_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
print("-" * 50)

# Initialize FastThaiG2P TTS
tts = TTS(pretrained="fastthaig2p")
tts = TTS(pretrained="makham_paradee")

# 1. Stream speech from text string chunk-by-chunk
text = "สวัสดีครับ ยินดีต้อนรับสู่ระบบสังเคราะห์เสียงภาษาไทยแบบเรียลไทม์"
Expand Down
Binary file added output.wav
Binary file not shown.
Loading
Loading