Skip to content

Commit 3209cfc

Browse files
committed
First commit
1 parent 8dda163 commit 3209cfc

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Project Required
2+
temp/
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# cli-tts
2+
23
Command Line Text-To-Speech using Google TTS

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gTTS
2+
simpleaudio

tts.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from gtts import gTTS as gtts
2+
import simpleaudio as sa
3+
import subprocess
4+
import os
5+
import sys
6+
7+
temp = './temp/'
8+
9+
10+
while (True):
11+
s = input('> ')
12+
13+
print('Generating...', end='')
14+
sys.stdout.flush()
15+
try:
16+
os.remove(temp + 'speech.mp3')
17+
except:
18+
pass
19+
tts = gtts(s)
20+
tts.save(temp + 'speech.mp3')
21+
22+
print(' Decoding...', end='')
23+
sys.stdout.flush()
24+
try:
25+
os.remove(temp + 'speech.wav')
26+
except:
27+
pass
28+
subprocess.run(['ffmpeg', '-i', temp + 'speech.mp3', temp + 'speech.wav'],
29+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
30+
31+
print(' Playing...', end='')
32+
sys.stdout.flush()
33+
wave = sa.WaveObject.from_wave_file(temp + 'speech.wav')
34+
wave.play()
35+
36+
print('\n')

0 commit comments

Comments
 (0)