윤창신

fix STT.js

......@@ -11,7 +11,14 @@ const apiReq = async ( clientData ) => {
//let audiodata = fs.readFileSync('./audio/audio_input.mp3').toString('base64')
console.log(Buffer(clientData.audio,'base64'))
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,8 +27,31 @@ const STT = async ( req, res ) => {
let clientData,
voiceTemp;
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 );
......