I am busy writing a Google cloud function that gets activated by a Google Cloud Storage activity. I need to use sox in a child_process - but not having much success.
This function picks up the audio file/event and then needs to calculate the length of the file and then display that.
When i run the following code(in my index.js):
'use strict';
const exec = require('child_process').exec;
const fs = require('fs');
const path = require('path');
const storage = require('@google-cloud/storage')();
const vision = require('@google-cloud/vision').v1p1beta1;
const client = new vision.ImageAnnotatorClient();
exports.processAudiofile = (event) => {
const object = event.data;
if (object.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return;
} else if (!object.name) {
console.log('This is a deploy event.');
return;
}
const file = storage.bucket(object.bucket).file(object.name);
const filePath = `gs://${object.bucket}/${object.name}`;
console.log(`Analyzing ${file.name}.`);
console.log(`Filepath is ${filePath}.`);
return new Promise((resolve, reject) => {
exec(`sox --i -d ${filePath}`, function(err, stdout){
if (err){
throw err;
}
console.log("Duration:" + stdout);//Prints
});
});
};
with the following package.json:
{
"name": "audiotest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/language": "^1.2.0",
"@google-cloud/speech": "^1.5.0",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.19.0",
"child_process": "^1.0.2",
"fs": "0.0.1-security",
"got": "^8.3.1",
"path": "^0.12.7",
"sox": "^0.1.0"
}
}
i get the following error:
Error: Command failed: sox --i -d gs://rawaudiobucket/shortcall.wav
/bin/sh: 1: sox: not found at ChildProcess.exithandler
(child_process.js:199:12) at emitTwo (events.js:106:13) at
ChildProcess.emit (events.js:191:7) at maybeClose
(internal/child_process.js:920:16) at Socket.<anonymous>
(internal/child_process.js:351:11) at emitOne (events.js:96:13) at
Socket.emit (events.js:188:7) at Pipe._handle.close [as _onclose]
(net.js:509:12)
Any help on this would be greatly appreciated!