TEXT TO SPEECH USING PYTHON

Converting text-to-speech 

    pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline and is compatible with both Python 2 and 3.

Installation:

pip install pyttsx3

If you receive errors such as No module named win32com.client, No module named win32, or No module named win32api, you will need to additionally install pypiwin32.

Usage:

# Text to speech using python

import pyttsx3
engine = pyttsx3.init()
# speaks what is in the parameter
engine.say("Hello World")
engine.runAndWait()

Changing voice:

# Changing voices

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
# 0 for Male voice
# 1 for Female voice

Changing volume:

# Changing volume

import pyttsx3
engine = pyttsx3.init()
volume = engine.getProperty("volume")
engine.setProperty("volume", 0.5)
# Default volume is 1
# You can setting up volume between 0 and 1

Changing speed(rate) of the speech:

# Changing rate

import pyttsx3
engine = pyttsx3.init()
rate = engine.getProperty("rate")
print(rate) # prints current speed(rate)
engine.setProperty("rate", 300) # Default rate is 200

Saving voice to a file:

# Saving voice to a file

import pyttsx3
engine = pyttsx3.init()
engine.save_to_file("Hello World", filename)
engine.runAndWait()

Refer pypi.org website

Comments

Popular posts from this blog

MOTION DETECTION AND TRACKING USING OPENCV AND PYTHON

BASIC HAND TRACKING USING PYTHON

PARANTHESIS CHECKER IMPLEMENTATION USING PYTHON - STACK APPLICATON👩‍💻👨‍💻