📜  pyttsx3 - Python (1)

📅  最后修改于: 2023-12-03 14:46:48.693000             🧑  作者: Mango

pyttsx3 - Python

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.

Installation

Pyttsx3 can be easily installed using pip.

pip install pyttsx3
Usage

Here's a quick example showing how to use pyttsx3.

import pyttsx3

engine = pyttsx3.init()
engine.say("Hello world!")
engine.runAndWait()
Features

Pyttsx3 has several features which make it a highly recommended text-to-speech library for Python.

Platform Support

Pyttsx3 is a cross-platform library and supports the following platforms:

  • Windows
  • macOS
  • Linux
Multiple TTS Engines Support

Pyttsx3 supports multiple TTS engines which include:

  • Microsoft Speech API (SAPI5)
  • eSpeak
  • nsss - Default on macOS
  • espeak-ng
  • MBROLA (experimental)
Voice Control

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()
Simple Syntax

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()
Limitations

Although pyttsx3 is a powerful TTS library for Python, it has some limitations which include:

  • Limited support for languages other than English.
  • Limited customization of TTS output.
  • Limited integration with other speech recognition software.
Conclusion

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.