forked from matiyau/STTTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTTTS.py
79 lines (64 loc) · 1.94 KB
/
STTTS.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 28 10:27:47 2017
@author: Nishad Mandlik
"""
from chromote import Chromote
import os
from time import sleep
from threading import Thread
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
def BrowSt () :
os.system("chromium-browser -remote-debugging-port=9222")
def WelMes () :
os.system('espeak "Please start your command after the beep"')
print ("Please Wait . . .")
WelcTh = Thread(target=WelMes)
WelcTh.start()
ServPort = 1997
os.system("jack_control start")
os.system("sudo amixer cset numid=3 1")
pwd = os.path.dirname(os.path.abspath(__file__))
os.chdir(pwd)
os.system("sudo fuser -k " + str(ServPort) + "/tcp")
ServTh = Thread(target = HTTPServer(('', ServPort), SimpleHTTPRequestHandler).serve_forever)
ServTh.start()
BrowTh = Thread(target=BrowSt)
BrowTh.start()
launchAttempts = 0
while (launchAttempts<20):
try:
sleep(1)
launchAttempts = launchAttempts + 1
krom = Chromote()
except :
continue
break
if (launchAttempts==20):
WelcTh.join()
ErrMes = "Maximum Attempts Reached. Your Browser Has Either Not Started Or Has Remote Debugging Disabled"
print (ErrMes)
os.system('espeak "' + ErrMes + '"')
TabSTT = krom.tabs[0]
TabSTT.set_url("http://localhost:" + str(ServPort) + "/STTTS.html")
WelcTh.join()
while True:
sleep(1)
PagSour=TabSTT.html
if (PagSour[PagSour.find("<title>")+7:PagSour.find("</title>")]=="Recording"):
break
os.system("aplay " + pwd + "/Beep.wav")
while True:
sleep(1)
PagSour=TabSTT.html
if (PagSour[PagSour.find("<title>")+7:PagSour.find("</title>")]=="Done"):
break
PagSour=TabSTT.html
STT = PagSour[PagSour.find('<span id="confm">')+17 : PagSour.find("</span>")]
krom.close_tab(TabSTT)
print(STT)
os.system('espeak "' + STT + '"')
os.system("sudo fuser -k " + str(ServPort) + "/tcp")
ServTh.join()