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-controller
Commits
336d380c
Commit
336d380c
authored
Jan 16, 2018
by
Yoann HOUPERT
Browse files
better return when error
parent
b08a4eee
Pipeline
#9847
passed with stage
in 1 minute and 11 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
18 deletions
+33
-18
config.json
config.json
+0
-2
lib/webserver/routes.js
lib/webserver/routes.js
+33
-16
No files found.
config.json
View file @
336d380c
...
...
@@ -5,7 +5,6 @@
"isOffline"
:
false
,
"gstreamer"
:
{
"host"
:
"linsttpoc_kaldi_1"
,
"host2"
:
"linsttcontroller_kaldi_1"
,
"port"
:
"80"
,
"api"
:
{
"recognize"
:
"client/dynamic/recognize"
...
...
@@ -20,7 +19,6 @@
},
"speechEnhancement"
:
{
"host"
:
"linsttpoc_speech-enhencement_1"
,
"host2"
:
"linsttcontroller_speech-enhencement_1"
,
"port"
:
"5000"
,
"api"
:
{
"upload"
:
"upload"
...
...
lib/webserver/routes.js
View file @
336d380c
...
...
@@ -18,37 +18,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const
routes
=
require
(
'
express
'
).
Router
();
const
uuidv1
=
require
(
'
uuid/v1
'
);
const
successCode
=
200
;
const
badRequestCode
=
400
;
const
interalServerCode
=
500
;
const
routesFactory
=
config
=>
{
/* eslint new-cap: ["error", { "capIsNew": false }] */
const
routes
=
require
(
'
express
'
).
Router
();
const
uuidv1
=
require
(
'
uuid/v1
'
);
const
enhancer
=
require
(
'
../controller/speech-enhancement
'
)(
config
.
speechEnhancement
);
const
stt
=
require
(
'
../controller/speech-to-text
'
)(
config
.
gstreamer
);
const
offline
=
require
(
'
../controller/offline
'
)(
config
.
offline
);
routes
.
post
(
'
/api/transcript
'
,
(
req
,
res
)
=>
{
if
(
!
req
.
body
)
{
return
res
.
status
(
400
).
send
(
'
No files were uploaded.
'
);
return
res
.
status
(
badRequestCode
).
send
(
'
No files were uploaded.
'
);
}
enhancer
.
enhancement
(
req
.
body
,
(
err
,
httpR
esponse
,
body
)
=>
{
enhancer
.
enhancement
(
req
.
body
,
(
err
,
r
esponse
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while enhancing audio.
'
+
err
);
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Enhancement
'
,
error
:
'
Error during audio enhancing
'
,
info
:
err
.
toString
()});
}
else
if
(
response
.
statusCode
!==
successCode
)
{
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Enhancement
'
,
error
:
'
Error during audio enhancing
'
});
}
if
(
config
.
isOffline
)
{
offline
.
transcript
(
body
,
(
err
,
httpResponse
,
body
)
=>
{
offline
.
transcript
(
body
,
(
err
,
response
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Offline transcription
'
,
error
:
'
Error during audio transcription
'
,
info
:
err
.
toString
()});
}
else
if
(
response
===
undefined
||
body
===
undefined
||
response
.
statusCode
!==
successCode
)
{
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Offline transcription
'
,
error
:
'
Error during audio transcription
'
});
}
const
json
=
JSON
.
parse
(
body
);
if
(
json
.
status
===
5
)
{
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio.
'
);
}
else
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio :
'
+
err
);
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Offline transcription
'
,
error
:
'
Error during audio transcription
'
});
}
// Default Offline
const
transcription
=
json
.
transcript
;
// TODO use this when enhancement whill be integrate
// const transcription = JSON.parse(json.transcript)
const
jsonResponse
=
{
status
:
0
,
hypotheses
:
[{
utterance
:
json
.
transcript
utterance
:
transcript
ion
}],
id
:
uuidv1
()
};
...
...
@@ -56,18 +73,18 @@ const routesFactory = config => {
return
res
.
status
(
200
).
json
({
message
:
'
transcript done
'
,
transcript
:
jsonResponse
});
});
}
else
{
stt
.
transcript
(
body
,
(
err
,
httpR
esponse
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio.
'
+
err
);
stt
.
transcript
(
body
,
(
err
,
r
esponse
,
body
)
=>
{
if
(
err
||
response
===
undefined
||
body
===
undefined
||
response
.
statusCode
!==
successCode
)
{
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Online transcription
'
,
error
:
'
Error during audio transcription
'
,
info
:
err
.
toString
()}
);
}
else
if
(
body
.
indexOf
(
'
No workers available
'
)
!==
-
1
)
{
return
res
.
status
(
500
).
send
(
'
No worker available for the moment.
'
);
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Online transcription
'
,
error
:
'
No worker available for the moment.
'
}
);
}
const
json
=
JSON
.
parse
(
body
);
if
(
json
.
status
===
5
)
{
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio.
'
);
return
res
.
status
(
interalServerCode
).
json
({
module
:
'
Online transcription
'
,
error
:
'
Error during audio transcription
'
}
);
}
return
res
.
status
(
200
).
json
({
message
:
'
t
ranscript done
'
,
transcript
:
json
});
return
res
.
status
(
successCode
).
json
({
message
:
'
T
ranscript done
'
,
transcript
:
json
});
});
}
});
...
...
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