项目作者: nateshmbhat

项目描述 :
Offline Text To Speech synthesis for python
高级语言: Python
项目地址: git://github.com/nateshmbhat/pyttsx3.git
创建时间: 2017-06-24T12:20:26Z
项目社区:https://github.com/nateshmbhat/pyttsx3

开源协议:GNU General Public License v3.0

下载




Offline Text To Speech (TTS) converter for Python

Downloads Downloads

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline.

Buy me a coffee 😇Buy me a coffee 😇

Installation :

  1. pip install pyttsx3

If you get installation errors , make sure you first upgrade your wheel version using :
pip install --upgrade wheel

Features :

  • ✨Fully OFFLINE text to speech conversion
  • 🎈 Choose among different voices installed in your system
  • 🎛 Control speed/rate of speech
  • 🎚 Tweak Volume
  • 📀 Save the speech audio as a file
  • ❤️ Simple, powerful, & intuitive API

Linux installation requirements :

  • If you are on a Linux system and if the voice output is not working, then :

    Install espeak-ng and libespeak1 as shown below:

    1. sudo apt update && sudo apt install espeak-ng libespeak1

Usage :

  1. import pyttsx3
  2. engine = pyttsx3.init()
  3. # For Mac, If you face error related to "pyobjc" when running the `init()` method :
  4. # Install 9.0.1 version of pyobjc : "pip install pyobjc>=9.0.1"
  5. engine.say("I will speak this text")
  6. engine.runAndWait()

Single line usage with speak function with default options

  1. import pyttsx3
  2. pyttsx3.speak("I will speak this text")

Changing Voice , Rate and Volume :

  1. import pyttsx3
  2. engine = pyttsx3.init() # object creation
  3. # RATE
  4. rate = engine.getProperty('rate') # getting details of current speaking rate
  5. print (rate) # printing current voice rate
  6. engine.setProperty('rate', 125) # setting up new voice rate
  7. # VOLUME
  8. volume = engine.getProperty('volume') # getting to know current volume level (min=0 and max=1)
  9. print (volume) # printing current volume level
  10. engine.setProperty('volume',1.0) # setting up volume level between 0 and 1
  11. # VOICE
  12. voices = engine.getProperty('voices') # getting details of current voice
  13. #engine.setProperty('voice', voices[0].id) # changing index, changes voices. o for male
  14. engine.setProperty('voice', voices[1].id) # changing index, changes voices. 1 for female
  15. engine.say("Hello World!")
  16. engine.say('My current speaking rate is ' + str(rate))
  17. engine.runAndWait()
  18. engine.stop()
  19. # Saving Voice to a file
  20. # On Linux, make sure that 'espeak-ng' is installed
  21. engine.save_to_file('Hello World', 'test.mp3')
  22. engine.runAndWait()

Full documentation of the Library

https://pyttsx3.readthedocs.io

Included Text-To-Speech Engines by Operating System

Linux macOS Windows
AVSpeech ✅︎
eSpeak ✅︎ ✅︎ ✅︎
NSSpeechSynthesizer ✅︎
SAPI5 ✅︎

[!NOTE]

  • AVSpeechSynthesizer support is still experimental.
  • NSSpeechSynthesizer is deprecated by Apple.

Feel free to wrap another text-to-speech engine for use with pyttsx3.