-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextTime.py
More file actions
43 lines (31 loc) · 918 Bytes
/
TextTime.py
File metadata and controls
43 lines (31 loc) · 918 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
from AppleNewsUtils import *
from Utils import *
from sound import Player
def calc_readtime(text, wpm=160):
words = split_words(text)
word_counts = len(words)
return word_counts / wpm
def split_words(text):
for ws in ('\n', '\t'):
text = text.replace(ws, ' ')
for q in ('"', "'", ','):
text = text.replace(q, '')
return text.split(' ')
def print_readtime(read_time):
min = read_time // 1
sec = (read_time % 1) * 60
rtstr = f' * Approx. {min: .0f} min {sec: .0f} sec'
print(rtstr)
return rtstr
def print_ttstime(fpath):
duration = Player(fpath).duration
min = duration // 60
sec = duration % 60
rtstr = f' * Actual. {min: .0f} min {sec: .0f} sec'
print(rtstr)
return rtstr
if __name__ == '__main__':
print(' please wait..')
text = get_safe_text()
rt = calc_readtime(text)
print_readtime(rt)