Created
March 6, 2019 02:31
-
-
Save himanshuteotia/ad5a623ea144c3589f66d70c4650f1bb 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
let express = require("express"); | |
let request = require("request"); | |
const ffmpeg = require("fluent-ffmpeg"); | |
const fs = require("fs"); | |
let track = | |
"https://cdn.fbsbx.com/v/t59.3654-21/52113399_803146416702766_1003332990597595136_n.mp4/audioclip-1551778334000-1950.mp4?_nc_cat=105&_nc_ht=cdn.fbsbx.com&oh=07e065c73899d3dd825828f4ce019138&oe=5C80FE67"; //your path to source file | |
async function createFile(track) { | |
new Promise((resolve, reject) => { | |
ffmpeg(track) | |
.toFormat("wav") | |
.on("error", err => { | |
console.log("An error occurred: " + err.message); | |
reject(); | |
}) | |
.on("progress", progress => { | |
// console.log(JSON.stringify(progress)); | |
console.log("Processing: " + progress.targetSize + " KB converted"); | |
}) | |
.on("end", () => { | |
console.log("Processing finished !"); | |
}) | |
.save("./hello.wav") | |
.on("end", () => { | |
console.log("On provcessing final end Processing finished !"); | |
resolve(); | |
}); //path where you want to save your file | |
}); | |
} | |
async function convertAndFind() { | |
await createFile(track); | |
request( | |
{ | |
url: "https://api.wit.ai/speech?v=20160526", | |
method: "POST", | |
headers: { | |
"cache-control": "no-cache", | |
"content-disposition": "attachment; filename=" + "hello", | |
authorization: "Bearer UOM5JKJ77YK7IMUINQPRIG7MRVRTUFNE", | |
"content-type": "audio/wav" | |
}, | |
encoding: null, | |
body: fs.createReadStream("./hello.wav") | |
}, | |
(error, response, body) => { | |
if (error) { | |
console.log({ name: error }); | |
} else { | |
console.log(JSON.parse(response.body.toString())); | |
} | |
} | |
); | |
} | |
convertAndFind(); | |
let app = express(); | |
app.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment