Skip to content

Commit 03280c0

Browse files
committed
Exception handled by me
1 parent 4cccb71 commit 03280c0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

voice.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from gtts import gTTS
2+
from colorama import Fore
23
import os
34

45
# Define the text you want to convert to speech
56
text = "Hello! This is a sample text to convert to speech."
67

7-
# Create a gTTS object
8-
tts = gTTS(text=text, lang="en")
8+
try:
9+
# Create a gTTS object
10+
tts = gTTS(text=text, lang="en")
911

10-
# Save the audio file
11-
tts.save("output.mp3")
12+
# Save the audio file
13+
tts.save("output.mp3")
1214

13-
# Play the audio file
14-
os.system("start output.mp3")
15+
# Play the audio file
16+
os.system("start output.mp3")
17+
except Exception as e:
18+
print(Fore.RED, e, Fore.RESET)

0 commit comments

Comments
 (0)