-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjulius.py
executable file
·34 lines (27 loc) · 895 Bytes
/
julius.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
import queue
import logging
import sys
import pyjulius3
logger = logging.getLogger(__name__)
class Julius:
def __init__(self):
# Initialize and try to connect
self.jul_client_ = pyjulius3.Client('localhost', 10500)
try:
self.jul_client_.connect()
except pyjulius3.ConnectionError:
print('Start julius as module first!')
sys.exit(1)
# Start client which starts word detection
self.jul_client_.start()
print("Julius opened!")
def __del__(self):
if self.jul_client_.state == pyjulius3.CONNECTED:
print('Close connection to Julius!')
self.jul_client_.disconnect() # disconnect from julius
def getJuliusDetection(self):
try:
ret = self.jul_client_.results.get(False)
except queue.Empty:
return ''
return ret