윤창신

write STT.js

1 +const apiRequest = require('./apiRequest');
2 +const isBase64 = require('is-base64');
3 +//const Lame = require("node-lame").Lame;
4 +const fs = require("fs");
5 +//const Mp32Wav = require('mp3-to-wav')
6 +
7 +const apiReq = async ( clientData ) => {
8 + fs.writeFileSync('./audio/audio_input.mp3', Buffer.from(clientData.audio.replace('data:audio/mp3; codecs=opus;base64,', ''), 'base64'));
9 + const mp32Wav = new Mp32Wav('./audio/audio_input.mp3')
10 + mp32Wav.saveForWav(Buffer.from(clientData.audio.replace('data:audio/mp3; codecs=opus;base64,', ''), 'base64'),'./audio/audio_input.wav',_,16000,1)
11 + //let audiodata = fs.readFileSync('./audio/audio_input.mp3').toString('base64')
12 + console.log(Buffer(clientData.audio,'base64'))
13 +
14 + getSTT = await apiRequest.ETRI( "WiseASR/Recognition", { "language_code" : "korean", "audio" : audiodata } );
15 +
16 + return { "text" : getSTT.return_object.recognized };
17 +}
18 +
19 +const STT = async ( req, res ) => {
20 + let clientData,
21 + voiceTemp;
22 +
23 + clientData = req.body.data
24 + voiceTemp = await apiReq( clientData );
25 +
26 + res.send( { "return_code" : 0, "return_data" : voiceTemp } );
27 + res.status( 200 );
28 +};
29 +
30 +module.exports=STT;
...\ No newline at end of file ...\ No newline at end of file