Python pyttsx3 – Change text to speech rate

In this post we will be creating a Python script that will change the rate of our text to speech converter using the pyttsx3 library. The pyttsx3 library allows us to convert text into speech using different speech engines. The library provides an easy-to-use interface for synthesizing speech in a variety of voices and languages. Using pyttsx3 we can create applications that can read text aloud. This makes it a useful tool for accessibility, language learning, and other purposes.

The snippet of Python code below uses the pyttsx3 library to convert text to speech and adjust the rate of speech. We start by initializing a new instance of the pyttsx3 engine which will be used to used to synthesize speech. Using the ‘setProperty()’ method we set the speech rate to 250 words per minute. We use the ‘say()’ method to convert our ‘Hello world’ text into an audio output. Using the ‘runAndWait()’ method we instruct the text-to-speech engine to start speaking the text.

import pyttsx3

engine = pyttsx3.init()

engine.setProperty('rate', 250)

engine.say("Hello world, how are you?")
engine.runAndWait()

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply