Python For Text To Speech Applications!

LeMaster Tech
183 followers
1 Video View·Apr 21, 2025
This quick and easy tutorial shows you how to use python code to write a basic text to speech program! This is a fun way to use the prebuilt python Text to speech (ttsx3) module for easily turning in typed text into spoken words.
Happy Holidays and Merry Christmas, thank you so much to everyone in the LeMaster Tech squad for an awesome 2022!! This was the first full year for LeMaster Tech and the growth and support has been awesome.
Be sure to let me know in the comments what you hope to see more of in the next year, and don't forget to leave a like and subscribe to the channel if you haven't already. Thanks for watching and good luck with your projects!
what's up you guys welcome back to the
channel in today's video I'm going to
show you how to make a simple text to
speech program welcome to Lemaster Tech
YouTube
[Music]
alright so text-to-speech is something
super fun uh to incorporate in a lot of
programs obviously uh there's a lot of
applications for data science and other
sorts of things and it's just kind of
fun to know how to do this and so to do
this we're going to use a module called
Pi text to speech and this is kind of
the third revision that's come out so
you need to import Pi TTS X3 if you
don't have that installed already you'll
want to run pip and install that I have
a whole video on the channel on how to
use pip and what to do if Pip's not
working so I'm not going to dive into
pip in this video but the first thing to
do according to the documentation for
this module you can find online is set
up an engine to use for text to speech
and so it's just engine equals Pi TTS X3
dot in it just like that and so we're
gonna store that in this variable engine
and initially let's make a variable that
will be the text we want to have spoken
and we'll just make it these open
quotations
um and let's set up a very simple while
loop that's just basically going to let
us keep having the computer speak things
that we type until we type in exit so
we'll say while text to speech is not
equal to and then just all lowercase
exit Okay so this program will run over
and over again until we type in the word
exit and so what we'll do then is we'll
say our variable text to speak is equal
to an input that we'll get from the user
and we'll just call it what should I say
so that's going to be the prompt that
pops up and then the user responds with
some text and then the computer needs to
say that text and it couldn't be easier
with the pi TTS X3 module it's just
engine dot say and then you pass in the
string you want it to say in this case
it's our variable text to speak but you
could just type your text directly in
there and then this command engine Dot
and it's run and wait and the and and
the wait have Capital first letters so
just be careful about the formatting if
you're using a good ide when you start
typing in like run it should Auto
populate with the rest of it so just pay
attention to syntax there and then at
the end of every time it runs this Loop
we'll just say type exit to leave the
program like this so This should let us
essentially have the program run as many
times as we want say as many things as
we want until we're ready to exit by
typing in exit so let's go ahead and run
this and see if that really is all we
need to do what should I say let's say
welcome to the Master Tech whoop spelled
it wrong
lemster attack
all right let's try that
welcome to limpster Tech said lemster
but that still sounds very good okay it
tells us type exit to leave the program
what should I say uh leave a like And
subscribe if this was useful leave a
like And subscribe if this was useful
okay so this right there is all you need
to know to create python uh text to
speech in your programs there are other
things that you can do with this you can
change the voice to be male or female
you can change the volume you can change
the speed they talk at all of that
documentation is readily available
online but if there's enough interest in
this just ask me uh what you would like
to see more of regarding this
text-to-speech kind of module and I can
do a follow-up to this in the near
future so let's go ahead and type exit
make sure that works
oh he said exit but then but then we uh
left the program so there we go uh the
reason that he still said the word exit
was because this what should I say
prompt is inside this while loop so he's
gonna say the word exit and then the
program will actually finish okay so
that is everything you need for this
very basic tutorial the holidays are
coming up so merry Christmas happy
holidays whatever you celebrate I hope
you found this video enjoyable and
useful please consider leaving a like on
the video subscribing the channel if you
found it useful and let me know in the
comments what you'd like to see more of
in the future thanks for watching and
good luck with your projects thanks bye
