0

I have the following code:

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()

Note: I have already installed the pyttsx3 module using the command pip install pyttsx3

Errors:

1. Visual Studio

Traceback (most recent call last):

  File "c:/Users/Arashi__/.ipynb_checkpoints/jarvis.py", line 1, in
<module>
    import pyttsx3 ModuleNotFoundError: No module named 'pyttsx3' ```

2.Jupyter notebook I executed the code line by line and got errors on the second line (around 100 lines of error of which, here, I show the last line for brevity sake):

KeyErrorTraceback (most recent call last) TypeError: item 2 in
_argtypes_ passes a union by value, which is unsupported.** this large error ```

3.after using engine= pyttsx3.init('dummy') instead of the engine= pyttsx3.init() my error is resolved but no output is generated.

How can I fix the above issues?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Laxman Patel
  • 1
  • 1
  • 4

3 Answers3

0

This is not how you use pyttsx3. This program should be using speak("Whatever goes here") and it should say it but I suggest you look at some tutorials on how to use pyttsx3 and take some python tutorials as well. It's quite easy once you look at some examples. Something else I did with pyttsx3 is this...

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)


def speak(audio):
    engine.say(audio)
    engine.runAndWait()

Use def speak for the easier speak function. I put this at the top of my program. On an unrelated note, you can change the gender of the voice by changing the value 0 being Male and 1 being female.

Redgar Tech
  • 347
  • 3
  • 13
0

I had exactly the same problem on Ubuntu 20.04. Resolved by installing eSpeak:

    sudo apt-get install espeak

Before you install check and set the python version to 3 by:

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1

in between and after installs be sure to run:

    apt-get update

More info about this visit: https://github.com/nateshmbhat/pyttsx3

Hope this works for your too!

Kind Regards!

0

Try making a virtual environment of it and then install pyttsx3 for it

command to do so : Open terminal in vs code and type

python -m venv (Your file address)/venv
Yu Hao
  • 119,891
  • 44
  • 235
  • 294