Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
LINAGORA
L
LGS
Labs
linstt-offline-decoding
Commits
d2744c50
Commit
d2744c50
authored
Jan 12, 2018
by
Rudy BARAGLIA
Browse files
Embeddind of worker
parent
5bab4c72
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
worker.cfg
worker.cfg
+2
-2
worker.py
worker.py
+13
-6
No files found.
worker.cfg
View file @
d2744c50
...
...
@@ -4,6 +4,6 @@ server_port : 8888
server_target : /worker/ws/speech
[worker_params]
temp_file_location : ./wavs/
decoder_command :
./
script
/
decode.sh system/models
temp_file_location :
.
./wavs/
decoder_command :
"cd
script
s;
decode.sh system/models
"
preprocessing : false
\ No newline at end of file
worker.py
View file @
d2744c50
...
...
@@ -12,6 +12,7 @@ import logging
import
json
import
subprocess
import
configparser
import
re
from
ws4py.client.threadedclient
import
WebSocketClient
...
...
@@ -29,7 +30,7 @@ PREPROCESSING = True if worker_settings.get('worker_params', 'preprocessing') ==
class
WorkerWebSocket
(
WebSocketClient
):
def
__init__
(
self
,
uri
):
WebSocketClient
.
__init__
(
self
,
url
=
uri
,
heartbeat_freq
=
10
)
self
.
request_id
=
"<undefined>"
def
opened
(
self
):
pass
def
guard_timeout
(
self
):
...
...
@@ -42,19 +43,23 @@ class WorkerWebSocket(WebSocketClient):
else
:
if
'uuid'
in
json_msg
.
keys
():
#Receive the file path to process
self
.
fileName
=
json_msg
[
'uuid'
]
self
.
client_uuid
=
json_msg
[
'uuid'
]
self
.
fileName
=
self
.
client_uuid
.
replace
(
'-'
,
''
)
self
.
file
=
json_msg
[
'file'
].
decode
(
'base64'
)
with
open
(
TEMP_FILE_PATH
+
self
.
fileName
+
'.wav'
,
'wb'
)
as
f
:
f
.
write
(
self
.
file
)
logging
.
debug
(
"FileName received: %s"
%
json_msg
[
'uuid'
]
)
logging
.
debug
(
"FileName received: %s"
%
self
.
fileName
)
# TODO: preprocessing ? (sox python)
if
PREPROCESSING
:
pass
# TODO: appeler le offline decoder
subprocess
.
call
(
DECODER_COMMAND
+
self
.
fileName
+
'.wav'
,
shell
=
True
)
# Offline decode call
logging
.
debug
(
DECODER_COMMAND
+
' '
+
self
.
fileName
+
'.wav'
)
subprocess
.
call
(
DECODER_COMMAND
+
' '
+
self
.
fileName
+
'.wav'
,
shell
=
True
)
# TODO: nettoyer les fichiers temporaires
# TODO: renvoyer la transcription au master
logging
.
debug
(
os
.
listdir
(
'./trans'
))
with
open
(
'trans/decode_'
+
self
.
fileName
+
'.log'
,
'r'
)
as
resultFile
:
result
=
resultFile
.
read
()
self
.
send_result
(
result
)
...
...
@@ -63,7 +68,9 @@ class WorkerWebSocket(WebSocketClient):
logging
.
debug
(
'POST received'
)
def
send_result
(
self
,
result
=
None
):
msg
=
json
.
dumps
({
u
'uuid'
:
self
.
fileName
,
u
'transcription'
:
result
,
u
'trust_ind'
:
u
"0.1235"
})
msg
=
json
.
dumps
({
u
'uuid'
:
self
.
client_uuid
,
u
'transcription'
:
result
,
u
'trust_ind'
:
u
"0.1235"
})
self
.
client_uuid
=
None
# TODO cleanup temp files.
self
.
send
(
msg
)
def
closed
(
self
,
code
,
reason
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment