Toggle navigation
Toggle navigation
This project
Loading...
Sign in
윤창신
/
searchGuide
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
윤창신
2019-12-03 19:06:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e39f8402b49073a054bcace9220fa9a2c0528af0
e39f8402
1 parent
c2e7e947
fix STT.js
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
4 deletions
api/STT.js
api/STT.js
View file @
e39f840
...
...
@@ -10,8 +10,15 @@ const apiReq = async ( clientData ) => {
mp32Wav
.
saveForWav
(
Buffer
.
from
(
clientData
.
audio
.
replace
(
'data:audio/mp3; codecs=opus;base64,'
,
''
),
'base64'
),
'./audio/audio_input.wav'
,
_
,
16000
,
1
)
//let audiodata = fs.readFileSync('./audio/audio_input.mp3').toString('base64')
console
.
log
(
Buffer
(
clientData
.
audio
,
'base64'
))
getSTT
=
await
apiRequest
.
ETRI
(
"WiseASR/Recognition"
,
{
"language_code"
:
"korean"
,
"audio"
:
audiodata
}
);
let
getSTT
=
{};
try
{
getSTT
=
await
apiRequest
.
ETRI
(
"WiseASR/Recognition"
,
{
"language_code"
:
"korean"
,
"audio"
:
audiodata
}
);
}
catch
(
err
)
{
throw
new
Error
(
err
.
message
);
}
return
{
"text"
:
getSTT
.
return_object
.
recognized
};
}
...
...
@@ -20,9 +27,32 @@ const STT = async ( req, res ) => {
let
clientData
,
voiceTemp
;
clientData
=
req
.
body
.
data
voiceTemp
=
await
apiReq
(
clientData
);
try
{
clientData
=
req
.
body
.
data
if
(
!
clientData
.
audio
.
length
)
{
throw
new
Error
(
"client audio empty"
);
}
else
if
(
!
isBase64
(
clientData
.
audio
)
)
{
throw
new
Error
(
"Type error : audio type should be base64"
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
(
{
"return_code"
:
-
1
,
"error_code"
:
err
.
message
}
);
res
.
status
(
403
);
return
false
;
}
try
{
voiceTemp
=
await
apiReq
(
clientData
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
(
{
"return_code"
:
-
1
,
"error_code"
:
err
.
message
}
);
res
.
status
(
502
);
return
false
;
}
res
.
send
(
{
"return_code"
:
0
,
"return_data"
:
voiceTemp
}
);
res
.
status
(
200
);
};
...
...
Please
register
or
login
to post a comment