-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat2voice.py
executable file
·52 lines (39 loc) · 1.46 KB
/
chat2voice.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
import subprocess
import hashlib
import os
import sys
import time
def GetCurrentHash():
with open(txtFile) as file_to_check:
# read contents of the file
data = file_to_check.read()
# pipe contents of the file through
md5_returned = hashlib.md5(data.encode('utf-8')).hexdigest()
return md5_returned
def SpeakToText(message):
print(message)
os.system("sh ~/programs_setup/speak_text/chat2voice_speak.sh " + str(message))
def SplitString(text):
splitted = str(text).split(": ")
return splitted[1]
if __name__ == "__main__":
#SpeakToText("Dies ist ein".encode('utf8'))
print("Text To Speech SL Chat Log")
txtFile = r'/home/debian/.secondlife/xyz_resident/chat.txt'
beforeHash = ''
# Open,close, read file and calculate MD5 on its contents
with open(txtFile) as file_to_check:
# read contents of the file
data = file_to_check.read()
# pipe contents of the file through
md5_returned = hashlib.md5(data.encode('utf-8')).hexdigest()
beforeHash = md5_returned
while True:
if GetCurrentHash() != beforeHash:
beforeHash = GetCurrentHash()
with open(txtFile, 'r') as f:
lines = f.readlines()
lastLine = lines[len(lines)-1]
print(SplitString(lastLine))
SpeakToText(SplitString(lastLine).encode('utf8').splitlines()[0])
time.sleep(1.5)