-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
50 lines (33 loc) · 927 Bytes
/
test.py
File metadata and controls
50 lines (33 loc) · 927 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from pygame import mixer
from gtts import gTTS
#text to speech
mixer.init()
voice=r'file.mp3'
# Calling the file to voice
def play_music(voice):
"""
This function is to play the audios
"""
mixer.music.load(voice)
# Setting the volume
mixer.music.set_volume(0.7)
# Start playing the song
mixer.music.play()
while True:
query = input("Press p to pause, r to resume, e to exit")
if query == 'p':
# Pausing the music
mixer.music.pause()
elif query == 'r':
# Resuming the music
mixer.music.unpause()
elif query == 'e':
# Stop the mixer
mixer.music.stop()
break
# infinite loop
while True:
text = input("Input the text to read: ")
tts = gTTS(text, lang='en')
tts.save('file.mp3')
play_music(voice)