There are several ways to get Python to speak both Python3 and Python2, two great methods:
If you are using a Mac, the os module will be integrated into your computer. You can import the os module using:
import os
Then you can use os to run terminal commands using the os.system command:
os.system("Your terminal")
In the terminal, the computer forces you to speak using the "say" command, so to make the computer speak, you simply use:
os.system("say 'some text'")
If you want to use this to pronounce a variable, you can use:
os.system("say " + myVariable)
The second way to get Python to talk is to use
You will have to install this using
pip isntall pyttsx3
or for Python3
pip3 install pyttsx3
Then you can use the following code to make it speak:
import pyttsx3 engine = pyttsx3.init() engine.say("Your Text") engine.runAndWait()
Hope this helps! :)
Alex Hawking May 30 '18 at 6:52 2018-05-30 06:52
source share