Skip to content

Commit 12cebd1

Browse files
Add gtts
'Google Text To Speech' library in python
1 parent 1289aeb commit 12cebd1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

_gtts.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from playsound import playsound
2+
from io import BytesIO
3+
from gtts import gTTS
4+
import tempfile
5+
6+
def tts_file(text, lang='en', slow=False):
7+
with tempfile.TemporaryFile() as temp_handler:
8+
engine = gTTS(text=text, lang=lang, slow=slow)
9+
engine.save(temp_handler.name)
10+
playsound(temp_handler.name)
11+
12+
def tts_direct(text, lang='en', slow=False):
13+
io = BytesIO()
14+
engine = gTTS(text=text, lang=lang, slow=slow)
15+
engine.write_to_fp(io)

0 commit comments

Comments
 (0)