0

I am trying to use python TTS with the import pyttsx3, and it is giving and error. Here is the error:

Exception has occurred: ModuleNotFoundError
No module named 'pyttsx3'
  File "C:\Users\Jacob\TTS.py", line 1, in <module>
    import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'

Here is my code:

    import pyttsx3
    
    def text_to_speech(text):
        try:
            # Initialize the TTS engine with "sapi5"
            engine = pyttsx3.init(driverName='sapi5')
            
            # Set properties (optional)
            engine.setProperty('rate', 150)  # Speed of speech (words per minute)
            engine.setProperty('volume', 1.0)  # Volume level (0.0 to 1.0)
    
            # Convert and play the text as speech
            engine.say(text)
            engine.runAndWait()
    
        except Exception as e:
            print("An error occurred:", e)
    
    if __name__ == "__main__":
        input_text = "Hello, this is a text-to-speech test with sapi5!"
        text_to_speech(input_text)

I already pip installed it. here is my current info of my pyttsx3 on my computer:

Name: pyttsx3
Version: 2.90
Summary: Text to Speech (TTS) library for Python 2 and 3. Works without internet connection or delay. Supports multiple TTS engines, including Sapi5, nsss, and espeak.
Home-page: https://github.com/nateshmbhat/pyttsx3
Author: Natesh M Bhat
Author-email: nateshmbhatofficial@gmail.com
License: UNKNOWN
Location: 

C:\Users\Jacob\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages
Requires: comtypes, pypiwin32, pywin32

Nothing I do works and I have been having this problem for a long time, Please help.

ewokx
  • 2,204
  • 3
  • 14
  • 27

0 Answers0