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
d7df6453
Commit
d7df6453
authored
Nov 24, 2017
by
Yoann HOUPERT
Browse files
reconstruct file body for enhancement API
parent
5585cf2d
Pipeline
#6035
passed with stage
in 24 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
20 deletions
+52
-20
lib/speech-enhancement.js
lib/speech-enhancement.js
+20
-9
lib/speech-to-text.js
lib/speech-to-text.js
+0
-1
lib/util.js
lib/util.js
+21
-1
lib/webserver/routes.js
lib/webserver/routes.js
+11
-9
No files found.
lib/speech-enhancement.js
View file @
d7df6453
...
...
@@ -17,19 +17,30 @@
* 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
fs
=
require
(
'
fs
'
);
const
request
=
require
(
'
request
'
);
const
enhancement
=
(
wavFile
,
speechEnhancement
,
enhancementlCallback
)
=>
{
const
formData
=
{
wavFile
:
wavFile
.
data
,
msg
:
'
-n
'
};
const
enhancement
=
(
wavFile
,
speechEnhancement
,
nameFile
,
enhancementlCallback
)
=>
{
const
url
=
'
http://
'
+
speechEnhancement
.
host
+
'
:
'
+
speechEnhancement
.
port
+
'
/
'
+
speechEnhancement
.
api
.
upload
;
if
(
!
speechEnhancement
.
debug
)
{
return
request
.
post
({
url
,
form
:
formData
},
enhancementlCallback
);
}
fs
.
writeFile
(
nameFile
+
'
.wav
'
,
wavFile
.
data
,
err
=>
{
if
(
err
)
{
throw
err
;
}
const
options
=
{
url
,
headers
:
{
'
content-type
'
:
'
multipart/form-data; boundary=---011000010111000001101001
'
},
formData
:
{
wavFile
:
fs
.
createReadStream
(
nameFile
+
'
.wav
'
),
msg
:
'
-n
'
}
};
request
.
post
(
options
,
enhancementlCallback
);
});
return
wavFile
;
};
...
...
lib/speech-to-text.js
View file @
d7df6453
...
...
@@ -22,7 +22,6 @@ const request = require('request');
const
transcript
=
(
audio
,
gstreamer
,
sttCallback
)
=>
{
const
url
=
'
http://
'
+
gstreamer
.
host
+
'
:
'
+
gstreamer
.
port
+
'
/
'
+
gstreamer
.
api
.
recognize
;
// TODO until no docker-compose use debug mode
return
request
.
post
({
url
,
body
:
audio
},
sttCallback
);
};
...
...
lib/
controller
.js
→
lib/
util
.js
View file @
d7df6453
...
...
@@ -18,6 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const
fs
=
require
(
'
fs
'
);
const
isFileValid
=
audio
=>
{
if
(
audio
.
mimetype
!==
'
audio/wave
'
)
{
return
false
;
...
...
@@ -25,6 +27,24 @@ const isFileValid = audio => {
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
;
}
});
};
module
.
exports
=
{
isFileValid
isFileValid
,
cleanFile
,
writeFile
};
lib/webserver/routes.js
View file @
d7df6453
...
...
@@ -23,36 +23,38 @@ const routesFactory = config => {
const
routes
=
require
(
'
express
'
).
Router
();
const
enhancer
=
require
(
'
../speech-enhancement
'
);
const
stt
=
require
(
'
../speech-to-text
'
);
const
contro
l
=
require
(
'
../
controller
'
);
const
uti
l
=
require
(
'
../
util
'
);
routes
.
post
(
'
/api/transcript
'
,
(
req
,
res
)
=>
{
if
(
!
req
.
files
)
{
return
res
.
status
(
400
).
send
(
'
No files were uploaded.
'
);
}
if
(
!
contro
l
.
isFileValid
(
req
.
files
.
wav
))
{
if
(
!
uti
l
.
isFileValid
(
req
.
files
.
wav
))
{
return
res
.
status
(
400
).
send
(
'
File is not valid.
'
);
}
enhancer
.
enhancement
(
req
.
files
.
wav
,
config
.
speechEnhancement
,
const
nameFile
=
Math
.
random
().
toString
(
36
).
substring
(
7
);
enhancer
.
enhancement
(
req
.
files
.
wav
,
config
.
speechEnhancement
,
nameFile
,
(
err
,
httpResponse
,
body
)
=>
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
'
Error while enhancing audio.
'
+
err
);
}
let
buff
=
new
Buffer
(
body
);
util
.
cleanFile
(
nameFile
);
util
.
writeFile
(
'
enchancementFile
'
,
body
);
// TODO Manage 'body' raw for kaldis api
stt
.
transcript
(
req
.
files
.
wav
.
data
,
config
.
gstreamer
,
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
){
}
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
)
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
.
hypotheses
[
0
].
utterance
});
}
);
...
...
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