-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
58 lines (55 loc) · 1.81 KB
/
__main__.py
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
51
52
53
54
55
56
57
58
from gtts import gTTS
import gui
import time
from tkinter import filedialog
import re
def TTS():
# Obtain text from GUI
text = gui.top.Text1.get("1.0","end-1c")
if (text.replace("\n", "").replace(" ", "") == ""):
print("Text is empty, nothing to translate")
return
# Obtain lang from GUI
lang = gui.top.TCombobox1.get()
if (lang == ""):
print("Warn: Empty language, setting to 'en'")
lang = "en"
# Obtain TTS audio from Google
print("Synthesizing voices...")
out = gTTS(text, lang=lang)
while(out == ""): time.sleep(0.5)
# Ask the user where to save the file
print("Saving the output...")
filename = filedialog.asksaveasfilename(title="Saving audio...",filetypes=[("MPEG Layer 3 Audio file",".mp3")])
if (filename == ""):
print("No filename specified, cancelled.")
return
if not (filename.endswith(".mp3")):
filename += ".mp3"
# Save the file
print("Saving to " + filename)
out.save(filename)
print("Done!")
return
def StatsCounter(event):
# Figure out the word count
text = gui.top.Text1.get("1.0","end-1c")
words = re.split(" |\t|\n|\.",text)
while("" in words): words.remove("")
count = len(words)
# Add word count to future label text
label = "Word count: " + str(count)
# Figure out the rough estimate for recording length in minutes
lang = gui.top.TCombobox1.get()
if (lang in ["sk", "en"]):
if (lang == "en"): speed = count/120
elif (lang == "sk"): speed = count/110
label += " (~ " + str("%.2f" % speed) + " minutes in " + lang + " lang)"
# Update the GUI label
gui.top.Label1.configure(text=label)
return
# Controller
gui.init()
gui.top.Button1.configure(command=TTS)
gui.top.Text1.bind("<KeyRelease>", StatsCounter)
gui.start()