-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathText_Speech.py
More file actions
28 lines (22 loc) · 772 Bytes
/
Text_Speech.py
File metadata and controls
28 lines (22 loc) · 772 Bytes
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
# Import the required module for text
# to speech conversion
from gtts import gTTS
from playsound import playsound
# This module is imported so that we can
# play the converted audio
import os
# The text that you want to convert to audio
mytext = 'My Baby samraddhi is playing with my mobile phone.Amazing my dear!'
# Language in which you want to convert
language = 'en'
# 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("mpg321 welcome.mp3")
playsound("welcome.mp3")