📅  最后修改于: 2023-12-03 14:46:48.693000             🧑  作者: Mango
pyttsx3 is a Python library for text-to-speech conversion. It is compatible with both Python 2 and 3. It uses the Text-to-Speech (TTS) engine to convert the text into spoken words.
Pyttsx3 can be easily installed using pip
.
pip install pyttsx3
Here's a quick example showing how to use pyttsx3.
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello world!")
engine.runAndWait()
Pyttsx3 has several features which make it a highly recommended text-to-speech library for Python.
Pyttsx3 is a cross-platform library and supports the following platforms:
Pyttsx3 supports multiple TTS engines which include:
Pyttsx3 lets you control the properties of the voice such as voice rate, volume, and voice choice.
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty("voices")
# set the male voice
engine.setProperty("voice", voices[0].id)
# set the female voice
engine.setProperty("voice", voices[1].id)
# set the rate of speech
engine.setProperty("rate", 150)
# set the volume
engine.setProperty("volume", 0.8)
engine.say("Hello world!")
engine.runAndWait()
Pyttsx3 has a simple syntax which makes it easy to integrate into your Python projects.
import pyttsx3
def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
Although pyttsx3 is a powerful TTS library for Python, it has some limitations which include:
If you need a simple, yet powerful Python text-to-speech library, you should definitely check out pyttsx3. It is easy to use, cross-platform, and supports multiple TTS engines.