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?
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.