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
0fe99509
Commit
0fe99509
authored
Nov 30, 2017
by
Yoann HOUPERT
Browse files
Add test
Clean code
parent
e4d6d634
Pipeline
#6396
passed with stage
in 27 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
131 additions
and
80 deletions
+131
-80
config.json
config.json
+2
-2
lib/controller/speech-enhancement.js
lib/controller/speech-enhancement.js
+23
-22
lib/controller/speech-to-text.js
lib/controller/speech-to-text.js
+7
-28
lib/util/checker.js
lib/util/checker.js
+9
-5
lib/util/checker.test.js
lib/util/checker.test.js
+63
-0
lib/webserver/routes.js
lib/webserver/routes.js
+23
-22
package.json
package.json
+4
-1
No files found.
config.json
View file @
0fe99509
...
...
@@ -2,14 +2,14 @@
"api"
:
3000
,
"orchestrator"
:
{
"gstreamer"
:
{
"host"
:
"linstt
poc
_kaldi_1"
,
"host"
:
"linstt
controller
_kaldi_1"
,
"port"
:
"80"
,
"api"
:
{
"recognize"
:
"client/dynamic/recognize"
}
},
"speechEnhancement"
:
{
"host"
:
"linstt
poc
_speech-enhencement_1"
,
"host"
:
"linstt
controller
_speech-enhencement_1"
,
"port"
:
"5000"
,
"api"
:
{
"upload"
:
"upload"
...
...
lib/speech-enhancement.js
→
lib/
controller/
speech-enhancement.js
View file @
0fe99509
...
...
@@ -17,31 +17,32 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const
request
=
require
(
'
request
'
);
const
enhancement
=
(
wavFile
,
speechEnhancement
,
enhancementlCallback
)
=>
{
const
url
=
'
http://
'
+
speechEnhancement
.
host
+
'
:
'
+
speechEnhancement
.
port
+
'
/
'
+
speechEnhancement
.
api
.
upload
;
module
.
exports
=
config
=>
{
const
request
=
require
(
'
request
'
)
;
const
options
=
{
url
,
formData
:
{
wavFile
:
{
value
:
wavFile
.
data
,
options
:
{
filename
:
'
wavFile
'
,
contentType
:
'
audio/x-wav
'
}
},
msg
:
'
-n
'
},
encoding
:
null
};
return
{
enhancement
:
(
wavFile
,
enhancementlCallback
)
=>
{
const
url
=
'
http://
'
+
config
.
host
+
'
:
'
+
config
.
port
+
'
/
'
+
config
.
api
.
upload
;
request
.
post
(
options
,
enhancementlCallback
);
const
options
=
{
url
,
formData
:
{
wavFile
:
{
value
:
wavFile
.
data
,
options
:
{
filename
:
'
wavFile
'
,
contentType
:
'
audio/x-wav
'
}
},
msg
:
'
-n
'
},
encoding
:
null
};
return
wavFile
;
};
request
.
post
(
options
,
enhancementlCallback
);
module
.
exports
=
{
enhancement
return
wavFile
;
}
};
};
lib/speech-to-text.js
→
lib/
controller/
speech-to-text.js
View file @
0fe99509
...
...
@@ -18,13 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const
request
=
require
(
'
request
'
);
const
transcript
=
(
audio
,
gstreamer
,
sttCallback
)
=>
{
const
url
=
'
http://
'
+
gstreamer
.
host
+
'
:
'
+
gstreamer
.
port
+
'
/
'
+
gstreamer
.
api
.
recognize
;
return
request
.
post
({
url
,
body
:
audio
},
sttCallback
);
};
module
.
exports
=
{
transcript
module
.
exports
=
config
=>
{
const
request
=
require
(
'
request
'
);
return
{
transcript
:
(
audio
,
sttCallback
)
=>
{
const
url
=
'
http://
'
+
config
.
host
+
'
:
'
+
config
.
port
+
'
/
'
+
config
.
api
.
recognize
;
return
request
.
post
({
url
,
body
:
audio
},
sttCallback
);
}
};
};
lib/util.js
→
lib/util
/checker
.js
View file @
0fe99509
...
...
@@ -18,33 +18,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const
fs
=
require
(
'
fs
'
);
const
isFileValid
=
audio
=>
{
if
(
audio
.
mimetype
!==
'
audio/wave
'
)
{
if
(
audio
===
undefined
)
{
return
false
;
}
return
true
;
};
const
cleanFile
=
nameFile
=>
{
fs
.
unlink
(
nameFile
+
'
.wav
'
,
err
=>
{
if
(
err
)
{
throw
err
;
}
});
};
const
writeFile
=
(
nameFile
,
data
)
=>
{
fs
.
writeFile
(
'
enhancementFile.wav
'
,
data
,
err
=>
{
if
(
err
)
{
throw
err
;
}
});
if
(
audio
.
mimetype
===
'
audio/wave
'
||
audio
.
mimetype
===
'
audio/x-wav
'
)
{
return
true
;
}
return
false
;
};
module
.
exports
=
{
isFileValid
,
cleanFile
,
writeFile
isFileValid
};
lib/util/checker.test.js
0 → 100644
View file @
0fe99509
/*
* Copyright (c) 2017 Linagora.
*
* This file is part of linstt-controller
* (see https://ci.linagora.com/linagora/lgs/labs/linstt-controller).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'
use strict
'
;
describe
(
'
checker should if file is valid
'
,
()
=>
{
beforeEach
(()
=>
{
/* eslint-disable import/no-unassigned-import */
global
.
checker
=
require
(
'
./checker.js
'
);
/* eslint-enable */
});
it
(
'
should define checker
'
,
()
=>
{
expect
(
global
.
checker
).
toBeDefined
();
});
it
(
'
should give false when undefined
'
,
()
=>
{
expect
(
global
.
checker
.
isFileValid
()).
toBe
(
false
);
});
it
(
'
should give false when not an audio
'
,
()
=>
{
expect
(
global
.
checker
.
isFileValid
(
'
random stuff
'
)).
toBe
(
false
);
});
it
(
'
should be false when the audio is not a wav
'
,
()
=>
{
const
audio
=
{
mimetype
:
'
audio/webm
'
,
data
:
'
randomByte
'
};
expect
(
global
.
checker
.
isFileValid
(
audio
)).
toBe
(
false
);
});
it
(
'
should be true when the audio is wav
'
,
()
=>
{
const
audioWav
=
{
mimetype
:
'
audio/wave
'
,
data
:
'
randomByte
'
};
const
audioXwav
=
{
mimetype
:
'
audio/x-wav
'
,
data
:
'
randomByte
'
};
expect
(
global
.
checker
.
isFileValid
(
audioWav
)).
toBe
(
true
);
expect
(
global
.
checker
.
isFileValid
(
audioXwav
)).
toBe
(
true
);
});
});
lib/webserver/routes.js
View file @
0fe99509
...
...
@@ -20,41 +20,42 @@
const
routesFactory
=
config
=>
{
/* eslint new-cap: ["error", { "capIsNew": false }] */
config
.
speechEnhancement
.
host
=
'
172.17.0.2
'
;
config
.
gstreamer
.
host
=
'
172.22.0.3
'
;
const
routes
=
require
(
'
express
'
).
Router
();
const
enhancer
=
require
(
'
../speech-enhancement
'
);
const
stt
=
require
(
'
../speech-to-text
'
);
const
util
=
require
(
'
../util
'
);
const
enhancer
=
require
(
'
../
controller/
speech-enhancement
'
)
(
config
.
speechEnhancement
)
;
const
stt
=
require
(
'
../
controller/
speech-to-text
'
)
(
config
.
gstreamer
)
;
const
checker
=
require
(
'
../util
/checker
'
);
routes
.
post
(
'
/api/transcript
'
,
(
req
,
res
)
=>
{
if
(
!
req
.
files
)
{
return
res
.
status
(
400
).
send
(
'
No files were uploaded.
'
);
}
if
(
!
util
.
isFileValid
(
req
.
files
.
wav
))
{
if
(
!
checker
.
isFileValid
(
req
.
files
.
wav
))
{
return
res
.
status
(
400
).
send
(
'
File is not valid.
'
);
}
enhancer
.
enhancement
(
req
.
files
.
wav
,
config
.
speechEnhancement
,
(
err
,
httpResponse
,
body
)
=>
{
enhancer
.
enhancement
(
req
.
files
.
wav
,
(
err
,
httpResponse
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while enhancing audio.
'
+
err
);
}
stt
.
transcript
(
body
,
(
err
,
httpResponse
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while enhancing audio.
'
+
err
);
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio.
'
+
err
);
}
else
if
(
body
.
indexOf
(
'
No workers available
'
)
!==
-
1
)
{
return
res
.
status
(
500
).
send
(
'
No worker available for the moment.
'
);
}
stt
.
transcript
(
body
,
config
.
gstreamer
,
(
err
,
httpResponse
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio.
'
+
err
);
}
else
if
(
body
.
indexOf
(
'
No workers available
'
)
!==
-
1
)
{
return
res
.
status
(
500
).
send
(
'
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
(
200
).
json
({
message
:
'
transcript done
'
,
transcript
:
json
});
}
);
const
json
=
JSON
.
parse
(
body
);
if
(
json
.
status
===
5
)
{
return
res
.
status
(
500
).
send
(
'
Error while transcript the audio.
'
);
}
return
res
.
status
(
200
).
json
({
message
:
'
transcript done
'
,
transcript
:
json
});
}
);
}
);
});
return
routes
;
...
...
package.json
View file @
0fe99509
...
...
@@ -22,7 +22,10 @@
"
sinon
"
:
"
^4.0.2
"
},
"xo"
:
{
"space"
:
true
"space"
:
true
,
"envs"
:
[
"jest"
]
},
"repository"
:
{
"type"
:
"git"
,
...
...
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