Created
February 17, 2019 20:26
-
-
Save artpel/69dafdf8a96f529eb2fcdfa3b98f4c9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating file name for path and downloading file | |
let formattedDate = moment.unix(Date.now()/1000).format("DDMMYYYY-HHmmss"); | |
let path = "audio-temp" + formattedDate +".flac"; | |
await audioDownloader(path, verbatimData.val().record.urlFlac) | |
// Opening File and creating base64 binary file | |
const audioBase64 = fs.readFileSync(path).toString('base64') | |
// Getting size of File | |
const stats = fs.statSync(path) | |
const fileSizeInBytes = stats.size | |
let firstWs = (filesize) => { | |
let payload = { | |
jwt: token(), | |
version: '1.0', | |
command: 'start-speech-recognition-async', | |
lang: 'fr-FR', | |
filesize, | |
webhook: 'https://bibemus-server.herokuapp.com/webhook/?userId=' + userId + '&verbatimId=' + verbatimId | |
} | |
let url = 'wss://api.vivoka.com:46753/' | |
const ws = new WebSocket(url); | |
ws.on('open', function open() { | |
ws.send(JSON.stringify(payload)); | |
}); | |
ws.on('message', function incoming(data) { | |
let stringData = data.toString(); | |
let jsonStringData = JSON.parse(stringData) | |
console.log(jsonStringData) | |
if (jsonStringData.code == 0) { | |
secondWs(jsonStringData.url, jsonStringData.stt_id) | |
} | |
}); | |
} | |
let secondWs = (url, stt_id) => { | |
let payload = { | |
"stt_id": stt_id, | |
"jwt": token(), | |
"version": "1.0" | |
} | |
const ws = new WebSocket(url); | |
ws.on('open', function open() { | |
console.log('2nd connexion has been opened') | |
ws.send(JSON.stringify(payload)); | |
ws.send(audioBase64) | |
}); | |
ws.on('message', function incoming(data) { | |
console.log(data.toString()); | |
}); | |
} | |
firstWs(fileSizeInBytes) | |
// fs.unlinkSync(path); | |
return ( | |
res.end() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment