윤창신

write STT.js

const apiRequest = require('./apiRequest');
const isBase64 = require('is-base64');
//const Lame = require("node-lame").Lame;
const fs = require("fs");
//const Mp32Wav = require('mp3-to-wav')
const apiReq = async ( clientData ) => {
fs.writeFileSync('./audio/audio_input.mp3', Buffer.from(clientData.audio.replace('data:audio/mp3; codecs=opus;base64,', ''), 'base64'));
const mp32Wav = new Mp32Wav('./audio/audio_input.mp3')
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 } );
return { "text" : getSTT.return_object.recognized };
}
const STT = async ( req, res ) => {
let clientData,
voiceTemp;
clientData = req.body.data
voiceTemp = await apiReq( clientData );
res.send( { "return_code" : 0, "return_data" : voiceTemp } );
res.status( 200 );
};
module.exports=STT;
\ No newline at end of file