forked from adi0509/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_to_speech.py
29 lines (23 loc) · 1.11 KB
/
text_to_speech.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Import the required module for text
# to speech conversion
#pip install gtts
#Resource: https://www.geeksforgeeks.org/convert-text-speech-python/
from gtts import gTTS
# This module is imported so that we can
# play the converted audio
import os
# The text that you want to convert to audio
mytext = 'Welcome to my GitHub please also check out my YouTube channels, for programming https://www.youtube.com/channel/UCbmb5IoBtHZTpYZCDBOC1CA and for computer science, https://www.youtube.com/user/randerson112358 !'
# Language in which you want to convert
#language = 'pt-br' #Portuguese (Brazil)
language = 'en' #English
# Passing the text and language to the engine,
# here we have marked slow=False. Which tells
# the module that the converted audio should
# have a high speed
myobj = gTTS(text=mytext, lang=language, slow=False)
# Saving the converted audio in a mp3 file named
# welcome
myobj.save("welcome.mp3")
# Playing the converted file
os.system("start welcome.mp3") #This command is for windows only for either operating systems download mpg321 and use os.system("mpg321 welcome.mp3")