윤창신

fix STT.js

...@@ -11,7 +11,14 @@ const apiReq = async ( clientData ) => { ...@@ -11,7 +11,14 @@ const apiReq = async ( clientData ) => {
11 //let audiodata = fs.readFileSync('./audio/audio_input.mp3').toString('base64') 11 //let audiodata = fs.readFileSync('./audio/audio_input.mp3').toString('base64')
12 console.log(Buffer(clientData.audio,'base64')) 12 console.log(Buffer(clientData.audio,'base64'))
13 13
14 +
15 + let getSTT = {};
16 + try {
14 getSTT = await apiRequest.ETRI( "WiseASR/Recognition", { "language_code" : "korean", "audio" : audiodata } ); 17 getSTT = await apiRequest.ETRI( "WiseASR/Recognition", { "language_code" : "korean", "audio" : audiodata } );
18 + }
19 + catch ( err ) {
20 + throw new Error ( err.message );
21 + }
15 22
16 return { "text" : getSTT.return_object.recognized }; 23 return { "text" : getSTT.return_object.recognized };
17 } 24 }
...@@ -20,8 +27,31 @@ const STT = async ( req, res ) => { ...@@ -20,8 +27,31 @@ const STT = async ( req, res ) => {
20 let clientData, 27 let clientData,
21 voiceTemp; 28 voiceTemp;
22 29
30 + try {
23 clientData = req.body.data 31 clientData = req.body.data
32 + if( !clientData.audio.length ) {
33 + throw new Error( "client audio empty" );
34 + }
35 + else if( !isBase64( clientData.audio ) ) {
36 + throw new Error( "Type error : audio type should be base64" );
37 + }
38 + }
39 + catch( err ) {
40 + console.log( err );
41 + res.json( { "return_code" : -1, "error_code" : err.message } );
42 + res.status( 403 );
43 + return false;
44 + }
45 +
46 + try {
24 voiceTemp = await apiReq( clientData ); 47 voiceTemp = await apiReq( clientData );
48 + }
49 + catch( err ) {
50 + console.log( err );
51 + res.json( { "return_code" : -1, "error_code" : err.message } );
52 + res.status( 502 );
53 + return false;
54 + }
25 55
26 res.send( { "return_code" : 0, "return_data" : voiceTemp } ); 56 res.send( { "return_code" : 0, "return_data" : voiceTemp } );
27 res.status( 200 ); 57 res.status( 200 );
......