Text to voice converter - python

 Hello guys,

in today's blog, I am going to show you how you can make your own text-to-speech converter.

this project is actually very easy to understand because we have already a pre-built library we just wanna use that library to make this project

ok before diving into the project we need some pre-requirements :

1. install gtts library (open your vs code editor -> open terminal -> new terminal ->type - pip install gtts

2. a basic understanding of Python syntax

now let's see the code for the project:

first, you need to import the gtts file previously installed 

from gtts import gTTS

once you install next create a function for taking user input


def user_input():

    text = input("enter the text which you wanna change into speech")

    text_to_speech(text)

create a function called text to speech pass the text that is user-entered. 

next call the function for achieving our project : 


def text_to_speech(text):

#create an output file to convert text into speech

#now call gTTS inside the gTTS

#assign text to store the text we wanna change into speech

#assign lang to setting the language

#assign slow = False for the speed of the voice


    output_file = gTTS(text = text , lang = "en" , slow = False )

#Now save the file as mp3

    output_file.save("speech.mp3")

Now we have completed this project code here is the full code :


from gtts import gTTS




def text_to_speech(text):

    output_file = gTTS(text = text , lang = "en" , slow = False )

    output_file.save("speech.mp3")


def user_input():

    text = input("enter the text which you wanna change into speech:::")

    text_to_speech(text)



user_input()


once you run the code the output will be like this : 









once you enter the text immediately it creates a file called speech.mp3











Conclusion:

I hope you found this project easy to understand and fun to work on! If you have any questions or run into any problems, don't hesitate to reach out.  Happy coding 😊

don't forget to follow me on Instagram✌ 






Comments

Popular Posts