đź”´ Let's Build A Text-To-Audio Generator in PYTHON for Beginners (Live Coding)

Phil Choi builds a text-to-speech generator in Python using pyttsx3. He sets up a virtual environment, installs the package, writes a script that reads user input aloud, and shows how to change voice and speaking rate to 75.
Chapters
Video hello, thanks for watching. Let fill text to speech generator code video. That's pretty funny. So last time we did an audio to text generator and this time from the comments from the audio text generator, someone asked to do a text audio generator and some other comments said to do it in Python or Rust. So we can do the text to audio generator in Python. I thought this time. So from here I have my terminal open and I have the package that I will use open. So just we'll make a directory called Text to audio generator. The CDN detects the audio generator pip freeze and I just to make sure we have virtual environment in our Python, we'll say virtual and VNV virtual environment venv doesn't matter what you name the second part, but usually VNV is pretty good. Then we'll do source VNV bin activate to activate our virtual environment. And then now you'll see that if we run pip freeze we have no Python packages. So virtual environments are like package JSON inside of Python or it's just like opening a different book so none of your packages conflict with each other. From here we're going to use Py3 text to speech 3.5. So first thing I'll do is I'll say Ted Touch text to audio generator Py and that'll be our Python file and we'll split a pin down and we'll code like this, half and half. So if we just go down here and we go vi text to text to audio generator. I print text to audio. All right, save it now. Python text audio generator and it'll say text to audio right here like so. So down here. Next thing we want to do is let's just exit out of this real quick. We want to pip install py3 dash tts. This is text to speech. It uses a. I think the new package is called Py TTS X files 3. But I had a bug earlier just installing that and seemed that this one will work. So originally it was this Py TTS x3, but now it's Py3 TTS. So the best part about this is it works offline and it's very simple and it has a lot of different configurations like the current speaking rate, volume and voice. So voices engine get property voices zero is a male and one is female. And you can also save voice to file here. So let's get started. Make sure. Let's go pip install py3tts. It's going to take a little while. So while that's going we can read a little bit. So it says if you get installation errors, make sure you first upgrade your wheel version using tip install upgrade wheel. And that's only if we have installation errors. We're not using Linux, so we don't need that. So the usage is import pytts x3 engine equals pytts x3. We just init it. Init it and then say. And it'll speak the text, see if it'll. So just wait. It seems like it's done installing. You do have a new release of PIP is available. So let's run this. But I'll need to do that outside of my virtual environment. I think I'll do it later. So from here we'll just vi text audio generator. I think I have to fix that. All right. Insert import pyttsx3 say we'll get the user input equals input input text to turn into audio like this. And that'll ask in the shell the user something and then they could type something and then that what they type will be inside of this variable. User input select prompt in node js and from here we can say engine equals pytx py ttsx3.init and then we can say engine. Say on user input and whoops undo and engine dot run and wait. So let's give it a whirl. Python Python Text to audio generator. Hello world, my name is Phil. Oops. Enter hello world, my name is Phil. That's that. And it seemed like it's a woman, a female voice. So let's try to change it to a male voice. So maybe we can go here. So when we. After we init the engine, we can say engine or first we need voices equals engine dot get property property voices and then we can say engine dot set property voice and we can say voices and we can turn it into a male because it was just female and dot ID and what else we want. I think the volume is already pretty high and I think the. It was pretty fast. So let's slow it down. So rate equals engine get property rate. Engine.set property on rate. Setting up new voice rate. Let's just do it to 75 and let's give it a. Let's try it out. Python Text to speech generator. Hello, thanks for watching. Let fill text to X2 audio generator tutorial. I don't know if it's a tutorial code. Oh, we do have an error. Name voices is not defined. Did you mean voice? So it says on line nine engine that name voices are not defined. Oh, yes. So let's go. Oops. What is this Oops voice. Oh, this one voice. Where am I? Ah, let me just go here. Let's call this voices. I think that should work. Hello, thanks for watching. Lead fill text to speech generator. Hello, thanks for watching. Let fill text to speech generator community. That's pretty funny. Let's go. Continue class. I think rate means speed. Hello. Hello. Hello. Hello. Hello. Hello. Okay, thank you.
More from Phil

day in the life of a software engineer | 5 hour productivity | building my dev agency 🔥

day in the life of a software engineer | 3 hour productivity | coding my 6-figure community startup

day in the life of a software engineer | 5 hour productivity | coding our sns startup app LFG

day in the life of a software engineer | 5 hour productivity | creating apps that makes big money






