Skip to content

Fix ModuleNotFoundError for missing TTS package in khanomtan_tts#24

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-module-not-found-error
Draft

Fix ModuleNotFoundError for missing TTS package in khanomtan_tts#24
Copilot wants to merge 2 commits intomainfrom
copilot/fix-module-not-found-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

khanomtan_tts.py had a top-level from TTS.utils.synthesizer import Synthesizer import, causing an immediate ModuleNotFoundError for any user without coqui-tts installed — even when using unrelated pretrained models like lunarlist_onnx.

Changes

  • pythaitts/pretrained/khanomtan_tts.py: Moved Synthesizer import from module-level into load_synthesizer(), wrapped in try/except ImportError with a clear install hint. Matches the existing lazy-import pattern in lunarlist_model.py.
def load_synthesizer(self, mode):
    try:
        from TTS.utils.synthesizer import Synthesizer
    except ImportError:
        raise ImportError(
            "You must install coqui-tts before using this model: pip install coqui-tts"
        )
  • tests/test_khanomtan.py: Adds a test verifying the ImportError is raised with the expected message when the TTS package is absent.
Original prompt

This section details on the original issue you should resolve

<issue_title>ModuleNotFoundError: No module named 'TTS'</issue_title>
<issue_description>Code raises error when trying to follow the official snippets.

/Users/sarit/.pyenv/versions/learn_typhoon_ocr/bin/python /Users/sarit/fullstack/learn_typhoon_ocr/test_pythaitts.py 
Traceback (most recent call last):
  File "/Users/sarit/fullstack/learn_typhoon_ocr/test_pythaitts.py", line 34, in <module>
    tts = TTS(pretrained="khanomtan")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sarit/.pyenv/versions/learn_typhoon_ocr/lib/python3.12/site-packages/pythaitts/__init__.py", line 40, in __init__
    self.load_pretrained(version=version)
  File "/Users/sarit/.pyenv/versions/learn_typhoon_ocr/lib/python3.12/site-packages/pythaitts/__init__.py", line 50, in load_pretrained
    from pythaitts.pretrained.khanomtan_tts import KhanomTan
  File "/Users/sarit/.pyenv/versions/learn_typhoon_ocr/lib/python3.12/site-packages/pythaitts/pretrained/khanomtan_tts.py", line 12, in <module>
    from TTS.utils.synthesizer import Synthesizer
ModuleNotFoundError: No module named 'TTS'

Process finished with exit code 1
import sounddevice as sd
import soundfile as sf
from pythaitts import TTS

tts = TTS()

tts = TTS(pretrained="khanomtan")
file = tts.tts("ภาษาไทย", speaker_idx="Linda", filename="kanontan.wav")
data, samplerate = sf.read(file)
print(f"เล่นจากไฟล์: {file}")
sd.play(data, samplerate)
sd.wait()  # รอจนเล่นเสร็จ

pythaitts==0.4.2

</issue_description>

Comments on the Issue (you are @copilot in this section)

@wannaphong Thank you for you report! It is weird bug because I still can use pythaitts in [google colab](https://colab.research.google.com/github/PyThaiNLP/PyThaiTTS/blob/dev/notebook/use_lunarlist_model.ipynb).

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…l error message

Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PyThaiNLP/PyThaiTTS/sessions/6b50b263-9513-4a9b-affa-fb2acb325811
Copilot AI changed the title [WIP] Fix ModuleNotFoundError for TTS module Fix ModuleNotFoundError for missing TTS package in khanomtan_tts Mar 26, 2026
Copilot AI requested a review from wannaphong March 26, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModuleNotFoundError: No module named 'TTS'

2 participants