www.xbdev.net
xbdev - software development
Thursday April 17, 2025
Home | Contact | Support | Python Language... Power of the Snake .. ..
     
 

Python Language...

Power of the Snake .. ..

 


Python > Text to Speed (Offline)


The `pyttsx3` python library is a free and offline text-to-speech tool! Just so simple and cool!

First things first, make sure you have it installed:

pip install pyttsx3


Second, give it a test run:

import pyttsx3
engine pyttsx3.init()
engine.say("Once upon a time ... ")
engine.runAndWait()


If all went well, you should be hearing the words 'Once upon a time..'. Just make sure your computer volume isn't muted or turned down to 0!

Let's take it a bit further - play a few different types of voices - see what you've got installed (loop over the installed voiced on your computer).

engine pyttsx3.init()
voices engine.getProperty('voices')
for 
voice in voices:
   
engine.setProperty('voice'voice.id)
   
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()


This is were it gets interesting - you might want to save the audio to a file for later on, you'd do that like this:

import pyttsx3
engine pyttsx3.init()
engine.save_to_file('Hello World' 'test.mp3')
engine.runAndWait()


Things to Try


You've got things up and running and you now have the power to create audio files! You can download your favourite book - parse the text and generate audio files for the different blocks of text!!

• Generate random words (create a world library and read out words in random order) - identify any words which are pronounced incorrectly, then build a lookup dictionary that will provide an alternative word format so it is spoken correctly.
• Read a few sentences - but do a pre-read phase that checks for any words that need replacing with an alternative version so they sound correct
• Experiment with inserting special characters to emulate 'pauses' or 'delays' in the speech
• Create 3 seperate images and 3 seperate blocks of text - then have the text converted to 'mp3' files. Build a simple html webpage with each page showing a full screen image (bottom middle to scroll forward or backward to the next page). Then in the top right add a play button to play the text for the image begin shown.
• Try mixing the text-to-speech with a fractal poetry generator (generates small poems and reads them out) - see the details for fractal poetry here (LINK)

Resources & Links


• pyttsx3 homepage and documentation (LINK)
• Fractal words, sentences and poems (LINK)




 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.