Return to site

Text to speech program code funny voice

broken image

If you want to use your Python program to play the file, you need to call the os.system() function. Now you can open up the file to listen to it. This saves the audio file to the same folder where your program file lives.

broken image

Now that you have the audio object specified, let’s export it to an mp3 file: audio.save('example.mp3') Now, let’s input the text to the gTTS engine and specify the language as English: audio = gTTS(text=mytext, lang='en', slow=False) 5. This is a bot speaking here, not a real human!' 4. Next, specify a piece of text you want to convert to speech.įor example: mytext = 'Hi, this is an example of converting text to audio. Now you have the necessary tools in the code file and you are ready to convert text to speech.

broken image

So add these two lines to the beginning of your Python file: from gtts import gTTS Once you have installed the gTTS module in your system, you can import it to your code project.īy the way, to use the program to play the mp3 file, you also need to import the built-in os module. Open up the command line tools and run the following command: pip install gTTS 2.

broken image