Python pyttsx3 – Change text to speech pitch

In this post we will be creating a Python script that will change the pitch 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 pitch. We start by initializing a new instance of the pyttsx3 engine which will be used to synthesize speech. We then set our pitch tag to 10. This is a relatively high value, resulting in a higher-pitched speech output. 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.say('<pitch middle="10">Hello World</pitch>')

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

Leave a Reply